Skip to content
Prev Previous commit
Next Next commit
Use an exhaustive match in target_host_combination.
This avoids bugs where components are added to one part of the manifest but not another.
  • Loading branch information
jyn514 committed Oct 27, 2022
commit 6cbf07959692c662126d0971f767ba14fd175ce5
83 changes: 48 additions & 35 deletions src/tools/build-manifest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,42 +401,55 @@ impl Builder {
let mut components = Vec::new();
let mut extensions = Vec::new();

let host_component = |pkg| Component::from_str(pkg, host);

// rustc/rust-std/cargo/docs are all required,
// and so is rust-mingw if it's available for the target.
components.extend(vec![
host_component("rustc"),
host_component("rust-std"),
host_component("cargo"),
host_component("rust-docs"),
]);
if host.contains("pc-windows-gnu") {
components.push(host_component("rust-mingw"));
}
let host_component = |pkg: &_| Component::from_str(pkg, host);

// Tools are always present in the manifest,
// but might be marked as unavailable if they weren't built.
extensions.extend(vec![
host_component("clippy-preview"),
host_component("miri-preview"),
host_component("rls-preview"),
host_component("rust-analyzer-preview"),
host_component("rustfmt-preview"),
host_component("llvm-tools-preview"),
host_component("rust-analysis"),
host_component("rust-docs-json-preview"),
]);

extensions.extend(
TARGETS
.iter()
.filter(|&&target| target != host)
.map(|target| Component::from_str("rust-std", target)),
);
extensions.extend(HOSTS.iter().map(|target| Component::from_str("rustc-dev", target)));
extensions.extend(HOSTS.iter().map(|target| Component::from_str("rustc-docs", target)));
extensions.push(Component::from_str("rust-src", "*"));
for pkg in PkgType::all() {
match pkg {
// rustc/rust-std/cargo/docs are all required
PkgType::Rustc | PkgType::Cargo | PkgType::HtmlDocs => {
components.push(host_component(&pkg.manifest_component_name()));
}
PkgType::RustStd => {
components.push(host_component(&pkg.manifest_component_name()));
extensions.extend(
TARGETS.iter().filter(|&&target| target != host).map(|target| {
Component::from_str(&pkg.manifest_component_name(), target)
}),
);
}
// so is rust-mingw if it's available for the target
PkgType::RustMingw => {
if host.contains("pc-windows-gnu") {
components.push(host_component("rust-mingw"));
}
}
// Tools are always present in the manifest,
// but might be marked as unavailable if they weren't built.
PkgType::Clippy
| PkgType::Miri
| PkgType::Rls
| PkgType::RustAnalyzer
| PkgType::Rustfmt
| PkgType::LlvmTools
| PkgType::RustAnalysis
| PkgType::JsonDocs => {
extensions.push(host_component(&pkg.manifest_component_name()));
}
PkgType::RustcDev | PkgType::RustcDocs => {
extensions.extend(
HOSTS.iter().map(|target| {
Component::from_str(&pkg.manifest_component_name(), target)
}),
);
}
PkgType::RustSrc => {
extensions.push(Component::from_str(&pkg.manifest_component_name(), "*"));
}
PkgType::Rust | PkgType::Other(_) => {}
// FIXME: is this correct? maybe we should add it so rustup knows about it ...
PkgType::ReproducibleArtifacts => {}
}
}

// If the components/extensions don't actually exist for this
// particular host/target combination then nix it entirely from our
Expand Down
3 changes: 1 addition & 2 deletions src/tools/build-manifest/src/versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ macro_rules! pkg_type {
}
}

/// Component name in the manifest. In particular, this includes the `-preview` suffix where appropriate.
pub(crate) fn all() -> &'static [PkgType] {
&[ $(PkgType::$variant),+ ]
}
Expand Down Expand Up @@ -69,7 +68,7 @@ pkg_type! {
}

impl PkgType {
// / Component name in the manifest. In particular, this includes the `-preview` suffix where appropriate.
/// Component name in the manifest. In particular, this includes the `-preview` suffix where appropriate.
pub(crate) fn manifest_component_name(&self) -> String {
if self.is_preview() {
format!("{}-preview", self.tarball_component_name())
Expand Down