From b2d7ca8a876281fc81790f2c5a67ffe200987690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Misty=20De=20M=C3=A9o?= Date: Tue, 26 Sep 2023 15:30:55 -0700 Subject: [PATCH] Add targets field --- cargo-dist/src/backend/ci/github.rs | 10 +++++++++- cargo-dist/src/config.rs | 29 ++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/cargo-dist/src/backend/ci/github.rs b/cargo-dist/src/backend/ci/github.rs index 7715a658a..73de27b22 100644 --- a/cargo-dist/src/backend/ci/github.rs +++ b/cargo-dist/src/backend/ci/github.rs @@ -287,7 +287,13 @@ fn package_install_for_targets( return None; } - let packages: Vec = packages.homebrew.clone().into_keys().collect(); + let packages: Vec = packages + .homebrew + .clone() + .into_iter() + .filter(|(_, package)| package.0.wanted_for_target(target)) + .map(|(name, _)| name) + .collect(); return Some(brew_bundle_command(&packages)); } "i686-unknown-linux-gnu" | "x86_64-unknown-linux-gnu" | "aarch64-unknown-linux-gnu" => { @@ -299,6 +305,7 @@ fn package_install_for_targets( .apt .clone() .into_iter() + .filter(|(_, package)| package.0.wanted_for_target(target)) .map(|(name, spec)| { if let Some(version) = spec.0.version { format!("{name}={version}") @@ -319,6 +326,7 @@ fn package_install_for_targets( .chocolatey .clone() .into_iter() + .filter(|(_, package)| package.0.wanted_for_target(target)) .map(|(name, package)| { if let Some(version) = package.0.version { format!("choco install {name} --version={version}") diff --git a/cargo-dist/src/config.rs b/cargo-dist/src/config.rs index 7087ffce7..4813e74e3 100644 --- a/cargo-dist/src/config.rs +++ b/cargo-dist/src/config.rs @@ -827,6 +827,19 @@ pub struct SystemDependencyComplex { pub version: Option, /// Phases at which the dependency is required pub phase: Vec, + /// One or more targets this package should be installed on; defaults to all targets if not specified + pub targets: Vec, +} + +impl SystemDependencyComplex { + /// Checks if this dependency should be installed on the specified target. + pub fn wanted_for_target(&self, target: &String) -> bool { + if self.targets.is_empty() { + true + } else { + self.targets.contains(target) + } + } } /// Definition for a single package @@ -843,6 +856,9 @@ pub enum SystemDependencyKind { /// Phases at which the dependency is required #[serde(default = "DependencyKind::default_phases")] phase: Vec, + /// One or more targets this package should be installed on; defaults to all targets if not specified + #[serde(default = "Vec::new")] + targets: Vec, }, } @@ -886,11 +902,18 @@ impl<'de> Deserialize<'de> for SystemDependency { SystemDependencyComplex { version: v, phase: DependencyKind::default_phases(), + targets: vec![], } } - SystemDependencyKind::Tagged { version, phase } => { - SystemDependencyComplex { version, phase } - } + SystemDependencyKind::Tagged { + version, + phase, + targets, + } => SystemDependencyComplex { + version, + phase, + targets, + }, }; Ok(SystemDependency(res))