diff --git a/crates/ubrn_cli/src/android.rs b/crates/ubrn_cli/src/android.rs index b42df382..d25b0755 100644 --- a/crates/ubrn_cli/src/android.rs +++ b/crates/ubrn_cli/src/android.rs @@ -232,13 +232,13 @@ impl AndroidArgs { .arg(target.to_string()) .arg("--platform") .arg(format!("{}", api_level)); - if !self.common_args.release { + if self.common_args.profile() != "release" { cmd.arg("--no-strip"); } - cmd.arg("--").arg("build"); - if self.common_args.release { - cmd.arg("--release"); - } + cmd.arg("--") + .arg("build") + .arg("--profile") + .arg(self.common_args.profile()); cmd.args(cargo_extras.clone()); run_cmd(cmd.current_dir(rust_dir))?; Ok(target.clone()) diff --git a/crates/ubrn_cli/src/building.rs b/crates/ubrn_cli/src/building.rs index 738c3463..a66b9c80 100644 --- a/crates/ubrn_cli/src/building.rs +++ b/crates/ubrn_cli/src/building.rs @@ -87,6 +87,12 @@ pub(crate) struct CommonBuildArgs { #[clap(long, short, default_value = "false")] pub(crate) release: bool, + /// Use a specific build profile + /// + /// This overrides the -r / --release flag if both are specified. + #[clap(long, short)] + pub(crate) profile: Option, + /// If the Rust library has been built for at least one target, then /// don't re-run cargo build. /// @@ -101,8 +107,8 @@ pub(crate) struct CommonBuildArgs { } impl CommonBuildArgs { - pub(crate) fn profile<'a>(&self) -> &'a str { - CrateMetadata::profile(self.release) + pub(crate) fn profile(&self) -> &str { + CrateMetadata::profile(self.profile.as_deref(), self.release) } } diff --git a/crates/ubrn_cli/src/ios.rs b/crates/ubrn_cli/src/ios.rs index eaa33e2f..b90f5ccd 100644 --- a/crates/ubrn_cli/src/ios.rs +++ b/crates/ubrn_cli/src/ios.rs @@ -212,10 +212,9 @@ impl IOsArgs { .arg("--manifest-path") .arg(manifest_path) .arg("--target") - .arg(&target.triple); - if self.common_args.release { - cmd.arg("--release"); - } + .arg(&target.triple) + .arg("--profile") + .arg(self.common_args.profile()); cmd.args(cargo_extras.clone()); run_cmd(cmd.current_dir(rust_dir))?; Ok(()) diff --git a/crates/ubrn_common/src/rust_crate.rs b/crates/ubrn_common/src/rust_crate.rs index e34ec7a7..ef13326b 100644 --- a/crates/ubrn_common/src/rust_crate.rs +++ b/crates/ubrn_common/src/rust_crate.rs @@ -21,12 +21,12 @@ pub struct CrateMetadata { } impl CrateMetadata { - pub fn profile<'a>(release: bool) -> &'a str { - if release { + pub fn profile(profile: Option<&str>, release: bool) -> &str { + profile.unwrap_or(if release { "release" } else { "debug" - } + }) } pub fn library_path(&self, target: Option<&str>, profile: &str) -> Utf8PathBuf { diff --git a/docs/src/reference/commandline.md b/docs/src/reference/commandline.md index 98b4b7a7..08f9042b 100644 --- a/docs/src/reference/commandline.md +++ b/docs/src/reference/commandline.md @@ -62,6 +62,7 @@ This takes care of the work of compiling the Rust, ready for generating bindings - `--and-generate` this runs the `generate all` command immediately after building. - `--targets` a comma separated list of targets, specific to each platform. This overrides the values in the config file. - `--release` builds a release version of the library. +- `--profile` uses a specific build profile, overriding --release if necessary ## `build android` @@ -77,13 +78,18 @@ Options: -t, --targets ... Comma separated list of targets, that override the values in the `config.yaml` file. - Android: aarch64-linux-android, armv7-linux-androideabi, x86_64-linux-android i686-linux-android, + Android: aarch64-linux-android,armv7-linux-androideabi,x86_64-linux-android,i686-linux-android, - Synonyms for: arm64-v8a, armeabi-v7a, x86_64, x86 + Synonyms for: arm64-v8a,armeabi-v7a,x86_64,x86 -r, --release Build a release build + -p, --profile + Use a specific build profile + + This overrides the -r / --release flag if both are specified. + --no-cargo If the Rust library has been built for at least one target, then don't re-run cargo build. @@ -132,9 +138,8 @@ You can find the version you need in your react-native `android/build.gradle` fi ## `build ios` Build the crate for use on an iOS device or simulator. -``` -Build the crate for use on an iOS device or simulator +``` Usage: uniffi-bindgen-react-native build ios [OPTIONS] --config Options: @@ -155,11 +160,16 @@ Options: -t, --targets ... Comma separated list of targets, that override the values in the `config.yaml` file. - iOS: aarch64-apple-ios, aarch64-apple-ios-sim, x86_64-apple-ios + iOS: aarch64-apple-ios,aarch64-apple-ios-sim,x86_64-apple-ios -r, --release Build a release build + -p, --profile + Use a specific build profile + + This overrides the -r / --release flag if both are specified. + --no-cargo If the Rust library has been built for at least one target, then don't re-run cargo build. diff --git a/xtask/src/run/rust_crate.rs b/xtask/src/run/rust_crate.rs index c75510b3..5209a4b1 100644 --- a/xtask/src/run/rust_crate.rs +++ b/xtask/src/run/rust_crate.rs @@ -21,6 +21,12 @@ pub(crate) struct CrateArg { #[clap(long, requires = "crate_dir", default_value = "false")] pub(crate) release: bool, + /// Use a specific build profile + /// + /// This overrides the release flag if both are specified. + #[clap(long, requires = "crate_dir")] + pub(crate) profile: Option, + /// Do not invoke cargo build. /// /// This is useful when invoking from within a test. @@ -31,29 +37,27 @@ pub(crate) struct CrateArg { impl CrateArg { pub(crate) fn cargo_build(&self, clean: bool) -> Result { let metadata = CrateMetadata::try_from(self.crate_dir.clone().expect("crate has no path"))?; - let profile = CrateMetadata::profile(self.release); - let lib_path = metadata.library_path(None, profile); + let lib_path = metadata.library_path(None, self.profile()); if lib_path.exists() && clean { metadata.cargo_clean()?; } if !lib_path.exists() || !self.no_cargo { - cargo_build(&metadata, self.release)?; + cargo_build(&metadata, self.profile())?; } Ok(metadata) } pub(crate) fn profile(&self) -> &str { - CrateMetadata::profile(self.release) + CrateMetadata::profile(self.profile.as_deref(), self.release) } } -fn cargo_build(metadata: &CrateMetadata, release: bool) -> Result<()> { +fn cargo_build(metadata: &CrateMetadata, profile: &str) -> Result<()> { let mut cmd = Command::new("cargo"); cmd.current_dir(metadata.crate_dir()); - cmd.arg("build"); - if release { - cmd.arg("--release"); - } + cmd.arg("build") + .arg("--profile") + .arg(profile); run_cmd_quietly(&mut cmd)?; Ok(()) }