Bug 1950665 - Upgrade to UniFFI 0.29,

Differential Revision: https://phabricator.services.mozilla.com/D239796
This commit is contained in:
Ben Dean-Kawamura
2025-03-26 17:12:06 +00:00
parent fae9e9d8b6
commit f07cda2602
13 changed files with 76 additions and 51 deletions

View File

@@ -61,8 +61,8 @@ rust-version = "1.82.0"
[workspace.dependencies]
# Shared across multiple UniFFI consumers.
uniffi = "0.28.2"
uniffi_bindgen = "0.28.2"
uniffi = "0.29.0"
uniffi_bindgen = "0.29.0"
# Shared across multiple application-services consumers.
rusqlite = "0.31.0"
# Shared across multiple glean consumers.
@@ -176,6 +176,9 @@ goblin = { path = "build/rust/goblin" }
# Implement getrandom 0.2 in terms of 0.3
getrandom = { path = "build/rust/getrandom" }
# Patch rustc-hash 1.1.0 to 2.1.1
rustc-hash = { path = "build/rust/rustc-hash" }
# Patch memoffset from 0.8.0 to 0.9.0 since it's compatible and it avoids duplication
memoffset = { path = "build/rust/memoffset" }
@@ -241,14 +244,14 @@ malloc_size_of_derive = { path = "xpcom/rust/malloc_size_of_derive" }
objc = { git = "https://github.com/glandium/rust-objc", rev = "4de89f5aa9851ceca4d40e7ac1e2759410c04324" }
# application-services overrides to make updating them all simpler.
interrupt-support = { git = "https://github.com/mozilla/application-services", rev = "d773da92641d92930b7308300e9fc2746a05ce6a" }
relevancy = { git = "https://github.com/mozilla/application-services", rev = "d773da92641d92930b7308300e9fc2746a05ce6a" }
search = { git = "https://github.com/mozilla/application-services", rev = "d773da92641d92930b7308300e9fc2746a05ce6a" }
sql-support = { git = "https://github.com/mozilla/application-services", rev = "d773da92641d92930b7308300e9fc2746a05ce6a" }
suggest = { git = "https://github.com/mozilla/application-services", rev = "d773da92641d92930b7308300e9fc2746a05ce6a" }
sync15 = { git = "https://github.com/mozilla/application-services", rev = "d773da92641d92930b7308300e9fc2746a05ce6a" }
tabs = { git = "https://github.com/mozilla/application-services", rev = "d773da92641d92930b7308300e9fc2746a05ce6a" }
viaduct = { git = "https://github.com/mozilla/application-services", rev = "d773da92641d92930b7308300e9fc2746a05ce6a" }
webext-storage = { git = "https://github.com/mozilla/application-services", rev = "d773da92641d92930b7308300e9fc2746a05ce6a" }
interrupt-support = { git = "https://github.com/mozilla/application-services", rev = "50c3f77fa264974678ec59e752fe7dc39c29900b" }
relevancy = { git = "https://github.com/mozilla/application-services", rev = "50c3f77fa264974678ec59e752fe7dc39c29900b" }
search = { git = "https://github.com/mozilla/application-services", rev = "50c3f77fa264974678ec59e752fe7dc39c29900b" }
sql-support = { git = "https://github.com/mozilla/application-services", rev = "50c3f77fa264974678ec59e752fe7dc39c29900b" }
suggest = { git = "https://github.com/mozilla/application-services", rev = "50c3f77fa264974678ec59e752fe7dc39c29900b" }
sync15 = { git = "https://github.com/mozilla/application-services", rev = "50c3f77fa264974678ec59e752fe7dc39c29900b" }
tabs = { git = "https://github.com/mozilla/application-services", rev = "50c3f77fa264974678ec59e752fe7dc39c29900b" }
viaduct = { git = "https://github.com/mozilla/application-services", rev = "50c3f77fa264974678ec59e752fe7dc39c29900b" }
webext-storage = { git = "https://github.com/mozilla/application-services", rev = "50c3f77fa264974678ec59e752fe7dc39c29900b" }
allocator-api2 = { path = "third_party/rust/allocator-api2" }

View File

@@ -0,0 +1,17 @@
[package]
name = "rustc-hash"
version = "1.999.999"
edition = "2018"
license = "Apache-2.0 OR MIT"
[lib]
path = "lib.rs"
[dependencies.rustc-hash]
version = "2.1.1"
default-features = false
[features]
default = ["rustc-hash/default"]
std = ["rustc-hash/std"]
rand = ["rustc-hash/rand"]

View File

@@ -0,0 +1,11 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
pub use rustc_hash::*;

View File

@@ -10,7 +10,7 @@ path = "src/main.rs"
[dependencies]
anyhow = "1"
askama = { version = "0.12", default-features = false, features = ["config"] }
rinja = { version = "0.3.4", default-features = false, features = ["config"] }
clap = { version = "4", default-features = false, features = ["std", "derive", "cargo"] }
cargo_metadata = "0.15"
extend = "1.1"

View File

@@ -8,33 +8,17 @@ use url::Url;
pub struct Handle(pub i64);
// We must implement the UniffiCustomTypeConverter trait for each custom type on the scaffolding side
impl UniffiCustomTypeConverter for Handle {
// The `Builtin` type will be used to marshall values across the FFI
type Builtin = i64;
// Convert Builtin to our custom type
fn into_custom(val: Self::Builtin) -> uniffi::Result<Self> {
Ok(Handle(val))
}
// Convert our custom type to Builtin
fn from_custom(obj: Self) -> Self::Builtin {
obj.0
}
}
uniffi::custom_type!(Handle, i64, {
try_lift: |val| Ok(Handle(val)),
lower: |obj| obj.0,
});
// Use `url::Url` as a custom type, with `String` as the Builtin
impl UniffiCustomTypeConverter for Url {
type Builtin = String;
fn into_custom(val: Self::Builtin) -> uniffi::Result<Self> {
Ok(Url::parse(&val)?)
}
fn from_custom(obj: Self) -> Self::Builtin {
obj.to_string()
}
}
uniffi::custom_type!(Url, String, {
remote,
try_lift: |val| Ok(Url::parse(&val)?),
lower: |obj| obj.to_string(),
});
// And a little struct and function that ties them together.
pub struct CustomTypesDemo {

View File

@@ -5,8 +5,8 @@
use std::fs;
use anyhow::Context;
use askama::Template;
use camino::Utf8Path;
use rinja::Template;
use uniffi_bindgen::ComponentInterface;
use crate::{render::js::*, Component, Result};

View File

@@ -3,9 +3,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use anyhow::{Context, Result};
use askama::Template;
use camino::{Utf8Path, Utf8PathBuf};
use clap::Parser;
use rinja::Template;
use serde::{Deserialize, Serialize};
use std::collections::HashSet;
use std::fs::File;

View File

@@ -16,8 +16,8 @@ License, v. 2.0. If a copy of the MPL was not distributed with this
use std::collections::HashSet;
use askama::Template;
use heck::{ToSnakeCase, ToUpperCamelCase};
use rinja::Template;
use uniffi_bindgen::interface::{
AsType, Callable, CallbackInterface, ComponentInterface, FfiDefinition, FfiFunction, FfiType,
};
@@ -416,8 +416,10 @@ fn scaffolding_converter(ci: &ComponentInterface, ffi_type: &FfiType) -> String
match ffi_type {
FfiType::RustArcPtr(name) => {
// Check if this is an external type
for (extern_name, crate_name, _, _) in ci.iter_external_types() {
if extern_name == name {
for ty in ci.iter_external_types() {
let external_ty_name = ty.name().expect("External type without name");
let crate_name = ty.module_path().expect("External type without module path");
if external_ty_name == name {
return format!(
"ScaffoldingObjectConverter<&{}>",
pointer_type(crate_name_to_namespace(&crate_name), name),
@@ -461,7 +463,9 @@ fn cpp_type(ffi_type: &FfiType) -> String {
FfiType::RustCallStatus => "RustCallStatus".to_owned(),
FfiType::Callback(name) | FfiType::Struct(name) => name.to_owned(),
FfiType::VoidPointer => "void*".to_owned(),
FfiType::Reference(inner) => format!("{}*", cpp_type(inner.as_ref())),
FfiType::MutReference(inner) | FfiType::Reference(inner) => {
format!("{}*", cpp_type(inner.as_ref()))
}
}
}

View File

@@ -4,9 +4,9 @@ License, v. 2.0. If a copy of the MPL was not distributed with this
use super::shared::*;
use crate::{CallbackIds, Config, FunctionIds, ObjectIds};
use askama::Template;
use extend::ext;
use heck::{ToLowerCamelCase, ToShoutySnakeCase, ToUpperCamelCase};
use rinja::Template;
use uniffi_bindgen::interface::{
Argument, AsType, Callable, CallbackInterface, ComponentInterface, Constructor, Enum, Field,
Function, Literal, Method, Object, Radix, Record, Type, Variant,
@@ -261,7 +261,6 @@ pub impl Type {
| Type::Enum { name, .. }
| Type::Record { name, .. }
| Type::CallbackInterface { name, .. }
| Type::External { name, .. }
| Type::Custom { name, .. } => name.to_upper_camel_case(),
Type::Optional { inner_type } => format!("?{}", inner_type.type_name()),
Type::Sequence { inner_type } => format!("Array.<{}>", inner_type.type_name()),
@@ -302,7 +301,7 @@ pub impl Type {
key_type.canonical_name().to_upper_camel_case(),
value_type.canonical_name().to_upper_camel_case()
),
Type::External { name, .. } | Type::Custom { name, .. } => format!("Type{name}"),
Type::Custom { name, .. } => format!("Type{name}"),
}
}

View File

@@ -22,7 +22,7 @@ export class {{ record.js_name() }} {
equals(other) {
return (
{%- for field in record.fields() %}
{{ field.as_type().equals("this.{}"|format(field.js_name()), "other.{}"|format(field.js_name())) }}{% if !loop.last %} &&{% endif %}
{{ field.as_type().equals(&("this.{}"|format(field.js_name())), &("other.{}"|format(field.js_name()))) }}{% if !loop.last %} &&{% endif %}
{%- endfor %}
)
}

View File

@@ -3,7 +3,8 @@
{% endif %}
{%- for type_ in ci.iter_types() %}
{%- for type_ in ci.iter_local_types() %}
{%- let ffi_converter = type_.ffi_converter() %}
{%- match type_ %}
@@ -75,9 +76,6 @@
{%- when Type::Custom { name, builtin, module_path } %}
{%- include "CustomType.sys.mjs" %}
{%- when Type::External { name, module_path, kind, namespace, tagged } %}
{%- include "ExternalType.sys.mjs" %}
{%- when Type::CallbackInterface { name, module_path } %}
{%- include "CallbackInterface.sys.mjs" %}
@@ -88,6 +86,14 @@
{% endfor %}
{%- for type_ in ci.iter_external_types() %}
{%- let ffi_converter = type_.ffi_converter() %}
{%- let name = type_.name().expect("External type without name") %}
{%- let module_path = type_.module_path().expect("External type without module path") %}
{%- include "ExternalType.sys.mjs" %}
{%- endfor %}
{%- if !ci.callback_interface_definitions().is_empty() %}
// Define callback interface handlers, this must come after the type loop since they reference the FfiConverters defined above.

View File

@@ -13,6 +13,7 @@ test-manifest-toml:
- 'testing/mozbase/manifestparser/tests/'
- 'testing/raptor/raptor/tests/'
- 'third_party/rust/'
- 'toolkit/components/uniffi-bindgen-gecko-js/rinja.toml'
- '**/.*ruff.toml'
- '**/Cargo.toml'
- '**/Cross.toml'