From eb821d1073033c44165ac956470bb2c12cf07929 Mon Sep 17 00:00:00 2001 From: James Hugman Date: Wed, 4 Dec 2024 15:16:34 +0000 Subject: [PATCH] Add wasm feature --- crates/ubrn_bindgen/Cargo.toml | 3 +++ crates/ubrn_bindgen/src/cli.rs | 20 ++++++++++++++++---- crates/ubrn_cli/Cargo.toml | 4 ++++ crates/ubrn_cli/src/generate.rs | 1 + xtask/Cargo.toml | 2 +- 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/crates/ubrn_bindgen/Cargo.toml b/crates/ubrn_bindgen/Cargo.toml index 29eb1720..52666e0f 100644 --- a/crates/ubrn_bindgen/Cargo.toml +++ b/crates/ubrn_bindgen/Cargo.toml @@ -4,6 +4,9 @@ version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[features] +default = [] +wasm = [] [dependencies] anyhow = { workspace = true } diff --git a/crates/ubrn_bindgen/src/cli.rs b/crates/ubrn_bindgen/src/cli.rs index 801c10b2..ae1ed52b 100644 --- a/crates/ubrn_bindgen/src/cli.rs +++ b/crates/ubrn_bindgen/src/cli.rs @@ -22,14 +22,16 @@ pub struct BindingsArgs { pub(crate) source: SourceArgs, #[command(flatten)] pub(crate) output: OutputArgs, + #[cfg(feature = "wasm")] #[command(flatten)] - pub(crate) switches: SwitchArgs, + switches: SwitchArgs, } impl BindingsArgs { - pub fn new(switches: SwitchArgs, source: SourceArgs, output: OutputArgs) -> Self { + pub fn new(_switches: SwitchArgs, source: SourceArgs, output: OutputArgs) -> Self { Self { - switches, + #[cfg(feature = "wasm")] + switches: _switches, source, output, } @@ -42,6 +44,16 @@ impl BindingsArgs { pub fn cpp_dir(&self) -> &Utf8Path { &self.output.cpp_dir } + + #[cfg(not(feature = "wasm"))] + pub fn switches(&self) -> SwitchArgs { + Default::default() + } + + #[cfg(feature = "wasm")] + pub fn switches(&self) -> SwitchArgs { + self.switches.clone() + } } #[derive(Args, Clone, Debug)] @@ -125,7 +137,7 @@ impl BindingsArgs { let generator = ReactNativeBindingGenerator::new( ts_dir.clone(), abi_dir.clone(), - self.switches.clone(), + self.switches(), ); let dummy_dir = Utf8PathBuf::from_str(".")?; diff --git a/crates/ubrn_cli/Cargo.toml b/crates/ubrn_cli/Cargo.toml index eda384ae..65a01967 100644 --- a/crates/ubrn_cli/Cargo.toml +++ b/crates/ubrn_cli/Cargo.toml @@ -8,6 +8,10 @@ name = "uniffi-bindgen-react-native" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[features] +default = [] +wasm = [] + [dependencies] anyhow = { workspace = true } askama = { workspace = true } diff --git a/crates/ubrn_cli/src/generate.rs b/crates/ubrn_cli/src/generate.rs index 68c53740..b56f8849 100644 --- a/crates/ubrn_cli/src/generate.rs +++ b/crates/ubrn_cli/src/generate.rs @@ -62,6 +62,7 @@ pub(crate) struct GenerateAllArgs { #[clap(long)] config: Utf8PathBuf, + #[cfg(feature = "wasm")] #[command(flatten)] switches: SwitchArgs, diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index c766d399..218add58 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -13,5 +13,5 @@ anyhow = { workspace = true } camino = { workspace = true } clap = { workspace = true } pathdiff = { workspace = true } -ubrn_bindgen = { path = "../crates/ubrn_bindgen" } +ubrn_bindgen = { path = "../crates/ubrn_bindgen", features = ["wasm"] } ubrn_common = { path = "../crates/ubrn_common" }