Skip to content

Commit 6cbf079

Browse files
committed
Use an exhaustive match in target_host_combination.
This avoids bugs where components are added to one part of the manifest but not another.
1 parent a3dd94e commit 6cbf079

File tree

2 files changed

+49
-37
lines changed

2 files changed

+49
-37
lines changed

src/tools/build-manifest/src/main.rs

Lines changed: 48 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -401,42 +401,55 @@ impl Builder {
401401
let mut components = Vec::new();
402402
let mut extensions = Vec::new();
403403

404-
let host_component = |pkg| Component::from_str(pkg, host);
405-
406-
// rustc/rust-std/cargo/docs are all required,
407-
// and so is rust-mingw if it's available for the target.
408-
components.extend(vec![
409-
host_component("rustc"),
410-
host_component("rust-std"),
411-
host_component("cargo"),
412-
host_component("rust-docs"),
413-
]);
414-
if host.contains("pc-windows-gnu") {
415-
components.push(host_component("rust-mingw"));
416-
}
404+
let host_component = |pkg: &_| Component::from_str(pkg, host);
417405

418-
// Tools are always present in the manifest,
419-
// but might be marked as unavailable if they weren't built.
420-
extensions.extend(vec![
421-
host_component("clippy-preview"),
422-
host_component("miri-preview"),
423-
host_component("rls-preview"),
424-
host_component("rust-analyzer-preview"),
425-
host_component("rustfmt-preview"),
426-
host_component("llvm-tools-preview"),
427-
host_component("rust-analysis"),
428-
host_component("rust-docs-json-preview"),
429-
]);
430-
431-
extensions.extend(
432-
TARGETS
433-
.iter()
434-
.filter(|&&target| target != host)
435-
.map(|target| Component::from_str("rust-std", target)),
436-
);
437-
extensions.extend(HOSTS.iter().map(|target| Component::from_str("rustc-dev", target)));
438-
extensions.extend(HOSTS.iter().map(|target| Component::from_str("rustc-docs", target)));
439-
extensions.push(Component::from_str("rust-src", "*"));
406+
for pkg in PkgType::all() {
407+
match pkg {
408+
// rustc/rust-std/cargo/docs are all required
409+
PkgType::Rustc | PkgType::Cargo | PkgType::HtmlDocs => {
410+
components.push(host_component(&pkg.manifest_component_name()));
411+
}
412+
PkgType::RustStd => {
413+
components.push(host_component(&pkg.manifest_component_name()));
414+
extensions.extend(
415+
TARGETS.iter().filter(|&&target| target != host).map(|target| {
416+
Component::from_str(&pkg.manifest_component_name(), target)
417+
}),
418+
);
419+
}
420+
// so is rust-mingw if it's available for the target
421+
PkgType::RustMingw => {
422+
if host.contains("pc-windows-gnu") {
423+
components.push(host_component("rust-mingw"));
424+
}
425+
}
426+
// Tools are always present in the manifest,
427+
// but might be marked as unavailable if they weren't built.
428+
PkgType::Clippy
429+
| PkgType::Miri
430+
| PkgType::Rls
431+
| PkgType::RustAnalyzer
432+
| PkgType::Rustfmt
433+
| PkgType::LlvmTools
434+
| PkgType::RustAnalysis
435+
| PkgType::JsonDocs => {
436+
extensions.push(host_component(&pkg.manifest_component_name()));
437+
}
438+
PkgType::RustcDev | PkgType::RustcDocs => {
439+
extensions.extend(
440+
HOSTS.iter().map(|target| {
441+
Component::from_str(&pkg.manifest_component_name(), target)
442+
}),
443+
);
444+
}
445+
PkgType::RustSrc => {
446+
extensions.push(Component::from_str(&pkg.manifest_component_name(), "*"));
447+
}
448+
PkgType::Rust | PkgType::Other(_) => {}
449+
// FIXME: is this correct? maybe we should add it so rustup knows about it ...
450+
PkgType::ReproducibleArtifacts => {}
451+
}
452+
}
440453

441454
// If the components/extensions don't actually exist for this
442455
// particular host/target combination then nix it entirely from our

src/tools/build-manifest/src/versions.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ macro_rules! pkg_type {
3939
}
4040
}
4141

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

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

0 commit comments

Comments
 (0)