diff options
Diffstat (limited to 'third_party/rust/uniffi')
-rw-r--r-- | third_party/rust/uniffi/.cargo-checksum.json | 1 | ||||
-rw-r--r-- | third_party/rust/uniffi/Cargo.toml | 68 | ||||
-rw-r--r-- | third_party/rust/uniffi/release.toml | 14 | ||||
-rw-r--r-- | third_party/rust/uniffi/src/cli.rs | 106 | ||||
-rw-r--r-- | third_party/rust/uniffi/src/lib.rs | 37 | ||||
-rw-r--r-- | third_party/rust/uniffi/tests/ui/proc_macro_arc.rs | 25 | ||||
-rw-r--r-- | third_party/rust/uniffi/tests/ui/proc_macro_arc.stderr | 31 | ||||
-rw-r--r-- | third_party/rust/uniffi/tests/ui/version_mismatch.rs | 4 | ||||
-rw-r--r-- | third_party/rust/uniffi/tests/ui/version_mismatch.stderr | 7 |
9 files changed, 293 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..5b1e3bd47e --- /dev/null +++ b/third_party/rust/uniffi/.cargo-checksum.json @@ -0,0 +1 @@ +{"files":{"Cargo.toml":"aa6288a6de59c4f25216578c7b27a51fbe98fb41c22c88f561dd171dfd905bd6","release.toml":"183ddd766a32826c448f33db7420abf2332b327f563e5de771c9e1733ef93e7a","src/cli.rs":"d8c8ebf37db05b31c33190de80923fde91c96c520a09c62ff6754b68a26dcf08","src/lib.rs":"08c447841ed496727112ccc4f6469bf00c50109575281c3b64f5dced65bbc119","tests/ui/proc_macro_arc.rs":"d766dffee3fe6a93522d40f44a7f15592db141fd674034fa5f016e06f510e87b","tests/ui/proc_macro_arc.stderr":"32096490256b658d42b8187547d07473439329e62676aa9b1ec6dbeef401ad7a","tests/ui/version_mismatch.rs":"16ea359e5853517ee0d0704c015ae8c825533109fbefd715130d0f4a51f15898","tests/ui/version_mismatch.stderr":"21dcb836253312ba8e3a0502cce6ff279818aaaadcea9628a41b196e0c8c94b6"},"package":"f71cc01459bc34cfe43fabf32b39f1228709bc6db1b3a664a92940af3d062376"}
\ 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..ddaa6c536c --- /dev/null +++ b/third_party/rust/uniffi/Cargo.toml @@ -0,0 +1,68 @@ +# 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.23.0" +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 = "3.1" +features = [ + "cargo", + "std", + "derive", +] +optional = true + +[dependencies.uniffi_bindgen] +version = "=0.23.0" +optional = true + +[dependencies.uniffi_build] +version = "=0.23.0" +optional = true + +[dependencies.uniffi_core] +version = "=0.23.0" + +[dependencies.uniffi_macros] +version = "=0.23.0" + +[dev-dependencies.trybuild] +version = "1" + +[features] +bindgen-tests = ["dep:uniffi_bindgen"] +build = ["dep:uniffi_build"] +cli = [ + "dep:uniffi_bindgen", + "dep:clap", + "dep:camino", +] +default = [] diff --git a/third_party/rust/uniffi/release.toml b/third_party/rust/uniffi/release.toml new file mode 100644 index 0000000000..3decae3abf --- /dev/null +++ b/third_party/rust/uniffi/release.toml @@ -0,0 +1,14 @@ +# 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="\\[\\[NextUnreleasedUniFFIVersion\\]\\]", replace="[[UnreleasedUniFFIVersion]]", 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..705ea9f453 --- /dev/null +++ b/third_party/rust/uniffi/src/cli.rs @@ -0,0 +1,106 @@ +/* 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}; + +// 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, possible_values = &["kotlin", "python", "swift", "ruby"])] + language: Vec<String>, + + /// 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>, + + /// Path to the UDL file. + udl_file: 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>, + + /// 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>, + + /// Do not try to format the generated bindings. + #[clap(long, short)] + no_format: bool, + + /// Path to the UDL file. + udl_file: Utf8PathBuf, + }, + + /// Print the JSON representation of the interface from a dynamic library + PrintJson { + /// 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, + udl_file, + } => uniffi_bindgen::generate_bindings( + udl_file, + config.as_deref(), + language.iter().map(String::as_str).collect(), + out_dir.as_deref(), + lib_file.as_deref(), + !no_format, + ), + Commands::Scaffolding { + out_dir, + config, + no_format, + udl_file, + } => uniffi_bindgen::generate_component_scaffolding( + udl_file, + config.as_deref(), + out_dir.as_deref(), + !no_format, + ), + Commands::PrintJson { path } => uniffi_bindgen::print_json(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..bb308c55f2 --- /dev/null +++ b/third_party/rust/uniffi/src/lib.rs @@ -0,0 +1,37 @@ +/* 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::{export, include_scaffolding, Enum, Error, Object, Record}; +#[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 = "cli")] +pub use uniffi_bindgen::{generate_bindings, generate_component_scaffolding, print_json}; +#[cfg(feature = "build")] +pub use uniffi_build::generate_scaffolding; +#[cfg(feature = "bindgen-tests")] +pub use uniffi_macros::build_foreign_language_testcases; + +#[cfg(test)] +mod test { + #[test] + fn trybuild_ui_tests() { + let t = trybuild::TestCases::new(); + t.compile_fail("tests/ui/*.rs"); + } +} + +#[cfg(feature = "cli")] +pub fn uniffi_bindgen_main() { + cli::run_main().unwrap(); +} 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..bdffc020e0 --- /dev/null +++ b/third_party/rust/uniffi/tests/ui/proc_macro_arc.rs @@ -0,0 +1,25 @@ +use std::sync::Arc; + +fn main() {} + +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 {} + } +} + +mod uniffi_types { + pub use super::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..9e89f7bccf --- /dev/null +++ b/third_party/rust/uniffi/tests/ui/proc_macro_arc.stderr @@ -0,0 +1,31 @@ +error[E0271]: type mismatch resolving `<Arc<child::Foo> as child::_::_::{closure#0}::TypeEq>::This == Arc<Foo>` + --> tests/ui/proc_macro_arc.rs:18:22 + | +18 | fn take_foo(foo: Arc<Foo>) { + | ^^^^^^^^ type mismatch resolving `<Arc<child::Foo> as child::_::_::{closure#0}::TypeEq>::This == Arc<Foo>` + | +note: expected this to be `Arc<Foo>` + --> tests/ui/proc_macro_arc.rs:18:22 + | +18 | fn take_foo(foo: Arc<Foo>) { + | ^^^ + = note: enum `child::Foo` and struct `Foo` have similar names, but are actually distinct types +note: enum `child::Foo` is defined in module `crate::child` of the current crate + --> tests/ui/proc_macro_arc.rs:15:5 + | +15 | enum Foo {} + | ^^^^^^^^ +note: struct `Foo` is defined in module `crate` of the current crate + --> tests/ui/proc_macro_arc.rs:5:1 + | +5 | pub struct Foo; + | ^^^^^^^^^^^^^^ +note: required by a bound in `child::_::_::{closure#0}::assert_type_eq_all` + --> tests/ui/proc_macro_arc.rs:18:22 + | +18 | fn take_foo(foo: Arc<Foo>) { + | ^^^ + | | + | required by a bound in this + | required by this bound in `child::_::_::{closure#0}::assert_type_eq_all` + = note: this error originates in the macro `::uniffi::deps::static_assertions::assert_type_eq_all` (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) |