summaryrefslogtreecommitdiffstats
path: root/third_party/rust/uniffi
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /third_party/rust/uniffi
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/uniffi')
-rw-r--r--third_party/rust/uniffi/.cargo-checksum.json1
-rw-r--r--third_party/rust/uniffi/Cargo.toml71
-rw-r--r--third_party/rust/uniffi/release.toml16
-rw-r--r--third_party/rust/uniffi/src/cli.rs136
-rw-r--r--third_party/rust/uniffi/src/lib.rs40
-rw-r--r--third_party/rust/uniffi/tests/ui/proc_macro_arc.rs24
-rw-r--r--third_party/rust/uniffi/tests/ui/proc_macro_arc.stderr22
-rw-r--r--third_party/rust/uniffi/tests/ui/version_mismatch.rs4
-rw-r--r--third_party/rust/uniffi/tests/ui/version_mismatch.stderr7
9 files changed, 321 insertions, 0 deletions
diff --git a/third_party/rust/uniffi/.cargo-checksum.json b/third_party/rust/uniffi/.cargo-checksum.json
new file mode 100644
index 0000000000..74d539b505
--- /dev/null
+++ b/third_party/rust/uniffi/.cargo-checksum.json
@@ -0,0 +1 @@
+{"files":{"Cargo.toml":"5a5cf41b9eb4aac8e312fc9584c0d47585a5a20b13bc7cfb14c9b8813ea596e6","release.toml":"1aa1b131d4cc93b5eba8758a4401c70bc0d7fe5861e2ec147e9259fe7c0da472","src/cli.rs":"0b4791c263d6cf54e4e63dff9a8ead59838d5e7b45fbf5b7f77ab16f602bdb0d","src/lib.rs":"6bc2c11f466fbcd128827a57b5f93a77f716262200f4e5ad2ed8dd75845320fc","tests/ui/proc_macro_arc.rs":"fedc429603753e8ef953642a7295323ccb3f76fd3ae1ab181ad90c5eb88212bb","tests/ui/proc_macro_arc.stderr":"a24af227b907328c9cac6317ec9f43dbc45d7f7c77c603e5d72db7fa050e8b01","tests/ui/version_mismatch.rs":"16ea359e5853517ee0d0704c015ae8c825533109fbefd715130d0f4a51f15898","tests/ui/version_mismatch.stderr":"21dcb836253312ba8e3a0502cce6ff279818aaaadcea9628a41b196e0c8c94b6"},"package":"21345172d31092fd48c47fd56c53d4ae9e41c4b1f559fb8c38c1ab1685fd919f"} \ No newline at end of file
diff --git a/third_party/rust/uniffi/Cargo.toml b/third_party/rust/uniffi/Cargo.toml
new file mode 100644
index 0000000000..475c8ab9be
--- /dev/null
+++ b/third_party/rust/uniffi/Cargo.toml
@@ -0,0 +1,71 @@
+# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
+#
+# When uploading crates to the registry Cargo will automatically
+# "normalize" Cargo.toml files for maximal compatibility
+# with all versions of Cargo and also rewrite `path` dependencies
+# to registry (e.g., crates.io) dependencies.
+#
+# If you are reading this file be aware that the original Cargo.toml
+# will likely look very different (and much more reasonable).
+# See Cargo.toml.orig for the original contents.
+
+[package]
+edition = "2021"
+name = "uniffi"
+version = "0.25.3"
+authors = ["Firefox Sync Team <sync-team@mozilla.com>"]
+description = "a multi-language bindings generator for rust"
+homepage = "https://mozilla.github.io/uniffi-rs"
+documentation = "https://mozilla.github.io/uniffi-rs"
+keywords = [
+ "ffi",
+ "bindgen",
+]
+license = "MPL-2.0"
+repository = "https://github.com/mozilla/uniffi-rs"
+
+[dependencies.anyhow]
+version = "1"
+
+[dependencies.camino]
+version = "1.0.8"
+optional = true
+
+[dependencies.clap]
+version = "4"
+features = [
+ "cargo",
+ "std",
+ "derive",
+]
+optional = true
+
+[dependencies.uniffi_bindgen]
+version = "=0.25.3"
+optional = true
+
+[dependencies.uniffi_build]
+version = "=0.25.3"
+optional = true
+
+[dependencies.uniffi_core]
+version = "=0.25.3"
+
+[dependencies.uniffi_macros]
+version = "=0.25.3"
+
+[dev-dependencies.trybuild]
+version = "1"
+
+[features]
+bindgen = ["dep:uniffi_bindgen"]
+bindgen-tests = ["dep:uniffi_bindgen"]
+build = ["dep:uniffi_build"]
+cli = [
+ "bindgen",
+ "uniffi_bindgen?/clap",
+ "dep:clap",
+ "dep:camino",
+]
+default = []
+tokio = ["uniffi_core/tokio"]
diff --git a/third_party/rust/uniffi/release.toml b/third_party/rust/uniffi/release.toml
new file mode 100644
index 0000000000..36154d8322
--- /dev/null
+++ b/third_party/rust/uniffi/release.toml
@@ -0,0 +1,16 @@
+# Note that this `release.toml` exists to capture things that must only be
+# done once for `cargo release-uniffi`.
+#
+# [../uniffi_core/release.toml](../uniffi_core/release.toml) captures things that must only be done for `cargo release-backend-crates`
+#
+# All other config exists in [../release.toml](../release.toml).
+
+tag = true
+
+# This is how we manage the sections in CHANGELOG.md
+pre-release-replacements = [
+ {file="../CHANGELOG.md", search="\\[\\[UnreleasedUniFFIVersion\\]\\]", replace="v{{version}}", exactly=2},
+ {file="../CHANGELOG.md", search="\\.\\.\\.HEAD\\)", replace="...{{tag_name}})", exactly=1},
+ {file="../CHANGELOG.md", search="\\[\\[NextUnreleasedUniFFIVersion\\]\\]", replace="[[UnreleasedUniFFIVersion]]", exactly=2},
+ {file="../CHANGELOG.md", search="\\.\\.\\.NEXT_HEAD\\)", replace="...HEAD)", exactly=1},
+]
diff --git a/third_party/rust/uniffi/src/cli.rs b/third_party/rust/uniffi/src/cli.rs
new file mode 100644
index 0000000000..b2d3adc2ae
--- /dev/null
+++ b/third_party/rust/uniffi/src/cli.rs
@@ -0,0 +1,136 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+use camino::Utf8PathBuf;
+use clap::{Parser, Subcommand};
+use uniffi_bindgen::bindings::TargetLanguage;
+
+// Structs to help our cmdline parsing. Note that docstrings below form part
+// of the "help" output.
+
+/// Scaffolding and bindings generator for Rust
+#[derive(Parser)]
+#[clap(name = "uniffi-bindgen")]
+#[clap(version = clap::crate_version!())]
+#[clap(propagate_version = true)]
+struct Cli {
+ #[clap(subcommand)]
+ command: Commands,
+}
+
+#[derive(Subcommand)]
+enum Commands {
+ /// Generate foreign language bindings
+ Generate {
+ /// Foreign language(s) for which to build bindings.
+ #[clap(long, short, value_enum)]
+ language: Vec<TargetLanguage>,
+
+ /// Directory in which to write generated files. Default is same folder as .udl file.
+ #[clap(long, short)]
+ out_dir: Option<Utf8PathBuf>,
+
+ /// Do not try to format the generated bindings.
+ #[clap(long, short)]
+ no_format: bool,
+
+ /// Path to the optional uniffi config file. If not provided, uniffi-bindgen will try to guess it from the UDL's file location.
+ #[clap(long, short)]
+ config: Option<Utf8PathBuf>,
+
+ /// Extract proc-macro metadata from a native lib (cdylib or staticlib) for this crate.
+ #[clap(long)]
+ lib_file: Option<Utf8PathBuf>,
+
+ /// Pass in a cdylib path rather than a UDL file
+ #[clap(long = "library")]
+ library_mode: bool,
+
+ /// When `--library` is passed, only generate bindings for one crate.
+ /// When `--library` is not passed, use this as the crate name instead of attempting to
+ /// locate and parse Cargo.toml.
+ #[clap(long = "crate")]
+ crate_name: Option<String>,
+
+ /// Path to the UDL file, or cdylib if `library-mode` is specified
+ source: Utf8PathBuf,
+ },
+
+ /// Generate Rust scaffolding code
+ Scaffolding {
+ /// Directory in which to write generated files. Default is same folder as .udl file.
+ #[clap(long, short)]
+ out_dir: Option<Utf8PathBuf>,
+
+ /// Do not try to format the generated bindings.
+ #[clap(long, short)]
+ no_format: bool,
+
+ /// Path to the UDL file.
+ udl_file: Utf8PathBuf,
+ },
+
+ /// Print a debug representation of the interface from a dynamic library
+ PrintRepr {
+ /// Path to the library file (.so, .dll, .dylib, or .a)
+ path: Utf8PathBuf,
+ },
+}
+
+pub fn run_main() -> anyhow::Result<()> {
+ let cli = Cli::parse();
+ match cli.command {
+ Commands::Generate {
+ language,
+ out_dir,
+ no_format,
+ config,
+ lib_file,
+ source,
+ crate_name,
+ library_mode,
+ } => {
+ if library_mode {
+ if lib_file.is_some() {
+ panic!("--lib-file is not compatible with --library.")
+ }
+ if config.is_some() {
+ panic!("--config is not compatible with --library. The config file(s) will be found automatically.")
+ }
+ let out_dir = out_dir.expect("--out-dir is required when using --library");
+ if language.is_empty() {
+ panic!("please specify at least one language with --language")
+ }
+ uniffi_bindgen::library_mode::generate_bindings(
+ &source, crate_name, &language, &out_dir, !no_format,
+ )?;
+ } else {
+ uniffi_bindgen::generate_bindings(
+ &source,
+ config.as_deref(),
+ language,
+ out_dir.as_deref(),
+ lib_file.as_deref(),
+ crate_name.as_deref(),
+ !no_format,
+ )?;
+ }
+ }
+ Commands::Scaffolding {
+ out_dir,
+ no_format,
+ udl_file,
+ } => {
+ uniffi_bindgen::generate_component_scaffolding(
+ &udl_file,
+ out_dir.as_deref(),
+ !no_format,
+ )?;
+ }
+ Commands::PrintRepr { path } => {
+ uniffi_bindgen::print_repr(&path)?;
+ }
+ };
+ Ok(())
+}
diff --git a/third_party/rust/uniffi/src/lib.rs b/third_party/rust/uniffi/src/lib.rs
new file mode 100644
index 0000000000..0625bd9c66
--- /dev/null
+++ b/third_party/rust/uniffi/src/lib.rs
@@ -0,0 +1,40 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/// Reexport items from other uniffi creates
+pub use uniffi_core::*;
+pub use uniffi_macros::*;
+#[cfg(feature = "cli")]
+mod cli;
+#[cfg(feature = "bindgen-tests")]
+pub use uniffi_bindgen::bindings::kotlin::run_test as kotlin_run_test;
+#[cfg(feature = "bindgen-tests")]
+pub use uniffi_bindgen::bindings::python::run_test as python_run_test;
+#[cfg(feature = "bindgen-tests")]
+pub use uniffi_bindgen::bindings::ruby::run_test as ruby_run_test;
+#[cfg(feature = "bindgen-tests")]
+pub use uniffi_bindgen::bindings::swift::run_test as swift_run_test;
+#[cfg(feature = "bindgen")]
+pub use uniffi_bindgen::{
+ bindings::TargetLanguage, generate_bindings, generate_component_scaffolding,
+ generate_component_scaffolding_for_crate, print_repr,
+};
+#[cfg(feature = "build")]
+pub use uniffi_build::{generate_scaffolding, generate_scaffolding_for_crate};
+#[cfg(feature = "bindgen-tests")]
+pub use uniffi_macros::build_foreign_language_testcases;
+
+#[cfg(feature = "cli")]
+pub fn uniffi_bindgen_main() {
+ cli::run_main().unwrap();
+}
+
+#[cfg(test)]
+mod test {
+ #[test]
+ fn trybuild_ui_tests() {
+ let t = trybuild::TestCases::new();
+ t.compile_fail("tests/ui/*.rs");
+ }
+}
diff --git a/third_party/rust/uniffi/tests/ui/proc_macro_arc.rs b/third_party/rust/uniffi/tests/ui/proc_macro_arc.rs
new file mode 100644
index 0000000000..9db3376594
--- /dev/null
+++ b/third_party/rust/uniffi/tests/ui/proc_macro_arc.rs
@@ -0,0 +1,24 @@
+use std::sync::Arc;
+
+fn main() {}
+
+// Normally this is defined by the scaffolding code, manually define it for the UI test
+pub struct UniFfiTag;
+
+pub struct Foo;
+
+#[uniffi::export]
+fn make_foo() -> Arc<Foo> {
+ Arc::new(Foo)
+}
+
+mod child {
+ use std::sync::Arc;
+
+ enum Foo {}
+
+ #[uniffi::export]
+ fn take_foo(foo: Arc<Foo>) {
+ match &*foo {}
+ }
+}
diff --git a/third_party/rust/uniffi/tests/ui/proc_macro_arc.stderr b/third_party/rust/uniffi/tests/ui/proc_macro_arc.stderr
new file mode 100644
index 0000000000..0654a29e25
--- /dev/null
+++ b/third_party/rust/uniffi/tests/ui/proc_macro_arc.stderr
@@ -0,0 +1,22 @@
+error[E0277]: the trait bound `Foo: FfiConverterArc<UniFfiTag>` is not satisfied
+ --> tests/ui/proc_macro_arc.rs:10:1
+ |
+10 | #[uniffi::export]
+ | ^^^^^^^^^^^^^^^^^ the trait `FfiConverterArc<UniFfiTag>` is not implemented for `Foo`
+ |
+ = help: the trait `LowerReturn<UT>` is implemented for `Arc<T>`
+ = note: required for `Arc<Foo>` to implement `FfiConverter<UniFfiTag>`
+ = note: required for `Arc<Foo>` to implement `Lower<UniFfiTag>`
+ = note: required for `Arc<Foo>` to implement `LowerReturn<UniFfiTag>`
+ = note: this error originates in the attribute macro `uniffi::export` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: the trait bound `child::Foo: FfiConverterArc<UniFfiTag>` is not satisfied
+ --> tests/ui/proc_macro_arc.rs:20:5
+ |
+20 | #[uniffi::export]
+ | ^^^^^^^^^^^^^^^^^ the trait `FfiConverterArc<UniFfiTag>` is not implemented for `child::Foo`
+ |
+ = help: the trait `Lift<UT>` is implemented for `Arc<T>`
+ = note: required for `Arc<child::Foo>` to implement `FfiConverter<UniFfiTag>`
+ = note: required for `Arc<child::Foo>` to implement `Lift<UniFfiTag>`
+ = note: this error originates in the attribute macro `uniffi::export` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/third_party/rust/uniffi/tests/ui/version_mismatch.rs b/third_party/rust/uniffi/tests/ui/version_mismatch.rs
new file mode 100644
index 0000000000..6a7edb891d
--- /dev/null
+++ b/third_party/rust/uniffi/tests/ui/version_mismatch.rs
@@ -0,0 +1,4 @@
+// This should fail with a version mismatch.
+uniffi::assert_compatible_version!("0.0.1"); // An error message would go here.
+
+fn main() {}
diff --git a/third_party/rust/uniffi/tests/ui/version_mismatch.stderr b/third_party/rust/uniffi/tests/ui/version_mismatch.stderr
new file mode 100644
index 0000000000..bc30714099
--- /dev/null
+++ b/third_party/rust/uniffi/tests/ui/version_mismatch.stderr
@@ -0,0 +1,7 @@
+error[E0080]: evaluation of constant value failed
+ --> tests/ui/version_mismatch.rs:2:1
+ |
+2 | uniffi::assert_compatible_version!("0.0.1"); // An error message would go here.
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to compute `0_usize - 1_usize`, which would overflow
+ |
+ = note: this error originates in the macro `uniffi::deps::static_assertions::const_assert` which comes from the expansion of the macro `uniffi::assert_compatible_version` (in Nightly builds, run with -Z macro-backtrace for more info)