diff --git a/src/commands/package.rs b/src/commands/package.rs index 624beb1..40c43fd 100644 --- a/src/commands/package.rs +++ b/src/commands/package.rs @@ -58,6 +58,7 @@ pub struct FeatureOptions { #[allow(clippy::too_many_arguments)] pub fn run( platforms: Option>, + build_target: Option<&str>, package_name: Option, xcframework_name: String, disable_warnings: bool, @@ -77,6 +78,7 @@ pub fn run( return run_for_crate( crates[0], platforms.clone(), + build_target, package_name, xcframework_name, disable_warnings, @@ -97,6 +99,7 @@ pub fn run( run_for_crate( current_crate, platforms.clone(), + build_target, None, xcframework_name.clone(), disable_warnings, @@ -116,6 +119,7 @@ pub fn run( fn run_for_crate( current_crate: &Package, platforms: Option>, + build_target: Option<&str>, package_name: Option, xcframework_name: String, disable_warnings: bool, @@ -154,12 +158,40 @@ fn run_for_crate( Err("At least 1 platform needs to be selected!")?; } - let targets: Vec<_> = platforms + let mut targets: Vec<_> = platforms .into_iter() .flat_map(|p| p.into_apple_platforms()) .map(|p| p.target()) .collect(); + if let Some(build_target) = build_target { + targets.retain_mut(|platform_target| match platform_target { + Target::Single { architecture, .. } => *architecture == build_target, + Target::Universal { + architectures, + display_name, + platform, + .. + } => { + let Some(architecture) = architectures.iter().find(|t| **t == build_target) else { + return false; + }; + *platform_target = Target::Single { + architecture, + display_name, + platform: *platform, + }; + true + } + }); + if targets.is_empty() { + return Err(Error::from(format!( + "No matching build target for {}", + build_target + ))); + } + } + if !skip_toolchains_check { let missing_toolchains = check_installed_toolchains(&targets); let nightly_toolchains = check_nightly_installed(&targets); diff --git a/src/main.rs b/src/main.rs index 105dbff..b56d11d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -74,6 +74,10 @@ enum Action { #[arg(short, long, trailing_var_arg = true, num_args = 1..=4, ignore_case = true)] platforms: Option>, + #[arg(long)] + /// Build package for the specified target triplet only. + target: Option, + #[arg(short = 'n', long = "name")] package_name: Option, @@ -122,6 +126,7 @@ fn main() -> ExitCode { Action::Package { platforms, + target, package_name, xcframework_name, suppress_warnings, @@ -133,6 +138,7 @@ fn main() -> ExitCode { no_default_features, } => package::run( platforms, + target.as_deref(), package_name, xcframework_name, suppress_warnings, diff --git a/src/targets.rs b/src/targets.rs index be11097..3f29cd9 100644 --- a/src/targets.rs +++ b/src/targets.rs @@ -51,7 +51,11 @@ impl Target { .into_iter() .map(|arch| { // FIXME: Remove nightly for Tier 3 targets here once build-std is stabilized - let mut cmd = if self.platform().is_tier_3() { command("cargo +nightly build -Z build-std") } else { command("cargo build") }; + let mut cmd = if self.platform().is_tier_3() { + command("cargo +nightly build -Z build-std") + } else { + command("cargo build") + }; cmd.arg("--target").arg(arch); match mode {