diff --git a/Cargo.toml b/Cargo.toml index 44dba1782c15..e9bb960e12f7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" } diff --git a/build/rust/rustc-hash/Cargo.toml b/build/rust/rustc-hash/Cargo.toml new file mode 100644 index 000000000000..977387a469fd --- /dev/null +++ b/build/rust/rustc-hash/Cargo.toml @@ -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"] diff --git a/build/rust/rustc-hash/lib.rs b/build/rust/rustc-hash/lib.rs new file mode 100644 index 000000000000..dd0d3cd92fd7 --- /dev/null +++ b/build/rust/rustc-hash/lib.rs @@ -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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +pub use rustc_hash::*; diff --git a/toolkit/components/uniffi-bindgen-gecko-js/Cargo.toml b/toolkit/components/uniffi-bindgen-gecko-js/Cargo.toml index 29e2e5ad6ac6..f617bcace37b 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/Cargo.toml +++ b/toolkit/components/uniffi-bindgen-gecko-js/Cargo.toml @@ -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" diff --git a/toolkit/components/uniffi-bindgen-gecko-js/fixtures/custom-types/src/lib.rs b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/custom-types/src/lib.rs index 61aea7a11ab3..b146bdd51c00 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/fixtures/custom-types/src/lib.rs +++ b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/custom-types/src/lib.rs @@ -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 { - 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 { - 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 { diff --git a/toolkit/components/uniffi-bindgen-gecko-js/askama.toml b/toolkit/components/uniffi-bindgen-gecko-js/rinja.toml similarity index 100% rename from toolkit/components/uniffi-bindgen-gecko-js/askama.toml rename to toolkit/components/uniffi-bindgen-gecko-js/rinja.toml diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/docs.rs b/toolkit/components/uniffi-bindgen-gecko-js/src/docs.rs index a2cc8721aa17..153409a461a0 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/docs.rs +++ b/toolkit/components/uniffi-bindgen-gecko-js/src/docs.rs @@ -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}; diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/lib.rs b/toolkit/components/uniffi-bindgen-gecko-js/src/lib.rs index a9f07ce53c8b..cef7646e9de9 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/lib.rs +++ b/toolkit/components/uniffi-bindgen-gecko-js/src/lib.rs @@ -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; diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/render/cpp.rs b/toolkit/components/uniffi-bindgen-gecko-js/src/render/cpp.rs index af78d2381fe6..2bc575ccfb0f 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/render/cpp.rs +++ b/toolkit/components/uniffi-bindgen-gecko-js/src/render/cpp.rs @@ -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())) + } } } diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/render/js.rs b/toolkit/components/uniffi-bindgen-gecko-js/src/render/js.rs index faf5a897f44c..73aaf8dd3e8d 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/render/js.rs +++ b/toolkit/components/uniffi-bindgen-gecko-js/src/render/js.rs @@ -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}"), } } diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Record.sys.mjs b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Record.sys.mjs index 40e46cc85b8b..df0c3044dcfb 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Record.sys.mjs +++ b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Record.sys.mjs @@ -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 %} ) } diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Types.sys.mjs b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Types.sys.mjs index 0a447296f7f8..1ab390e76974 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Types.sys.mjs +++ b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Types.sys.mjs @@ -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. diff --git a/tools/lint/test-manifest-toml.yml b/tools/lint/test-manifest-toml.yml index 9f3eb882ca43..fde20732a757 100644 --- a/tools/lint/test-manifest-toml.yml +++ b/tools/lint/test-manifest-toml.yml @@ -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'