Skip to content

Commit

Permalink
Add targets field
Browse files Browse the repository at this point in the history
  • Loading branch information
mistydemeo committed Sep 26, 2023
1 parent acf78a9 commit b2d7ca8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
10 changes: 9 additions & 1 deletion cargo-dist/src/backend/ci/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,13 @@ fn package_install_for_targets(
return None;
}

let packages: Vec<String> = packages.homebrew.clone().into_keys().collect();
let packages: Vec<String> = 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" => {
Expand All @@ -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}")
Expand All @@ -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}")
Expand Down
29 changes: 26 additions & 3 deletions cargo-dist/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,19 @@ pub struct SystemDependencyComplex {
pub version: Option<String>,
/// Phases at which the dependency is required
pub phase: Vec<DependencyKind>,
/// One or more targets this package should be installed on; defaults to all targets if not specified
pub targets: Vec<String>,
}

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
Expand All @@ -843,6 +856,9 @@ pub enum SystemDependencyKind {
/// Phases at which the dependency is required
#[serde(default = "DependencyKind::default_phases")]
phase: Vec<DependencyKind>,
/// One or more targets this package should be installed on; defaults to all targets if not specified
#[serde(default = "Vec::new")]
targets: Vec<String>,
},
}

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

0 comments on commit b2d7ca8

Please sign in to comment.