diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/uniffi/src/cli.rs | |
parent | Initial commit. (diff) | |
download | firefox-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 '')
-rw-r--r-- | third_party/rust/uniffi/src/cli.rs | 106 |
1 files changed, 106 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(()) +} |