Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --profile build argument #192

Merged
merged 8 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/ubrn_cli/src/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,12 @@ impl AndroidArgs {
.arg(target.to_string())
.arg("--platform")
.arg(format!("{}", api_level));
if !self.common_args.release {
if self.common_args.profile() != "release" {
Johennes marked this conversation as resolved.
Show resolved Hide resolved
cmd.arg("--no-strip");
}
cmd.arg("--").arg("build");
if self.common_args.release {
cmd.arg("--release");
if self.common_args.profile() != "debug" {
cmd.arg("--profile").arg(self.common_args.profile());
Johennes marked this conversation as resolved.
Show resolved Hide resolved
}
cmd.args(cargo_extras.clone());
run_cmd(cmd.current_dir(rust_dir))?;
Expand Down
10 changes: 8 additions & 2 deletions crates/ubrn_cli/src/building.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,

/// If the Rust library has been built for at least one target, then
/// don't re-run cargo build.
///
Expand All @@ -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)
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/ubrn_cli/src/ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ impl IOsArgs {
.arg(manifest_path)
.arg("--target")
.arg(&target.triple);
if self.common_args.release {
cmd.arg("--release");
if self.common_args.profile() != "debug" {
cmd.arg("--profile").arg(self.common_args.profile());
Johennes marked this conversation as resolved.
Show resolved Hide resolved
}
cmd.args(cargo_extras.clone());
run_cmd(cmd.current_dir(rust_dir))?;
Expand Down
8 changes: 2 additions & 6 deletions crates/ubrn_common/src/rust_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@ pub struct CrateMetadata {
}

impl CrateMetadata {
pub fn profile<'a>(release: bool) -> &'a str {
if release {
"release"
} else {
"debug"
}
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 {
Expand Down
20 changes: 15 additions & 5 deletions docs/src/reference/commandline.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand All @@ -77,13 +78,18 @@ Options:
-t, --targets <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 <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.

Expand Down Expand Up @@ -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 <CONFIG>

Options:
Expand All @@ -155,11 +160,16 @@ Options:
-t, --targets <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 <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.

Expand Down
19 changes: 12 additions & 7 deletions xtask/src/run/rust_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Johennes marked this conversation as resolved.
Show resolved Hide resolved
pub(crate) profile: Option<String>,

/// Do not invoke cargo build.
///
/// This is useful when invoking from within a test.
Expand All @@ -31,28 +37,27 @@ pub(crate) struct CrateArg {
impl CrateArg {
pub(crate) fn cargo_build(&self, clean: bool) -> Result<CrateMetadata> {
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");
if profile != "debug" {
cmd.arg("--profile").arg(profile);
}
run_cmd_quietly(&mut cmd)?;
Ok(())
Expand Down
Loading