Skip to content

Commit

Permalink
Merge pull request #63 from pronebird/build-target
Browse files Browse the repository at this point in the history
Add target setting that enables building single architecture only
  • Loading branch information
antoniusnaumann authored Aug 11, 2024
2 parents afd9033 + d65951c commit b7ea4fe
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
34 changes: 33 additions & 1 deletion src/commands/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub struct FeatureOptions {
#[allow(clippy::too_many_arguments)]
pub fn run(
platforms: Option<Vec<Platform>>,
build_target: Option<&str>,
package_name: Option<String>,
xcframework_name: String,
disable_warnings: bool,
Expand All @@ -77,6 +78,7 @@ pub fn run(
return run_for_crate(
crates[0],
platforms.clone(),
build_target,
package_name,
xcframework_name,
disable_warnings,
Expand All @@ -97,6 +99,7 @@ pub fn run(
run_for_crate(
current_crate,
platforms.clone(),
build_target,
None,
xcframework_name.clone(),
disable_warnings,
Expand All @@ -116,6 +119,7 @@ pub fn run(
fn run_for_crate(
current_crate: &Package,
platforms: Option<Vec<Platform>>,
build_target: Option<&str>,
package_name: Option<String>,
xcframework_name: String,
disable_warnings: bool,
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ enum Action {
#[arg(short, long, trailing_var_arg = true, num_args = 1..=4, ignore_case = true)]
platforms: Option<Vec<package::Platform>>,

#[arg(long)]
/// Build package for the specified target triplet only.
target: Option<String>,

#[arg(short = 'n', long = "name")]
package_name: Option<String>,

Expand Down Expand Up @@ -122,6 +126,7 @@ fn main() -> ExitCode {

Action::Package {
platforms,
target,
package_name,
xcframework_name,
suppress_warnings,
Expand All @@ -133,6 +138,7 @@ fn main() -> ExitCode {
no_default_features,
} => package::run(
platforms,
target.as_deref(),
package_name,
xcframework_name,
suppress_warnings,
Expand Down
6 changes: 5 additions & 1 deletion src/targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit b7ea4fe

Please sign in to comment.