summaryrefslogtreecommitdiffstats
path: root/third_party/rust/uniffi/src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/uniffi/src
parentInitial commit. (diff)
downloadfirefox-esr-upstream.tar.xz
firefox-esr-upstream.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/uniffi/src')
-rw-r--r--third_party/rust/uniffi/src/cli.rs106
-rw-r--r--third_party/rust/uniffi/src/lib.rs37
2 files changed, 143 insertions, 0 deletions
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();
+}