Skip to content

Commit 3c0fb7f

Browse files
committed
Add manifest docs fallback.
1 parent a34c079 commit 3c0fb7f

File tree

2 files changed

+62
-41
lines changed

2 files changed

+62
-41
lines changed

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

+60-35
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,19 @@ static TARGETS: &[&str] = &[
155155
"x86_64-unknown-hermit",
156156
];
157157

158-
static DOCS_TARGETS: &[&str] = &[
159-
"aarch64-unknown-linux-gnu",
160-
"i686-apple-darwin",
161-
"i686-pc-windows-gnu",
162-
"i686-pc-windows-msvc",
163-
"i686-unknown-linux-gnu",
164-
"x86_64-apple-darwin",
165-
"x86_64-pc-windows-gnu",
166-
"x86_64-pc-windows-msvc",
167-
"x86_64-unknown-linux-gnu",
168-
"x86_64-unknown-linux-musl",
158+
/// This allows the manifest to contain rust-docs for hosts that don't build
159+
/// docs.
160+
///
161+
/// Tuples of `(host_partial, host_instead)`. If the host does not have the
162+
/// rust-docs component available, then if the host name contains
163+
/// `host_partial`, it will use the docs from `host_instead` instead.
164+
///
165+
/// The order here matters, more specific entries should be first.
166+
static DOCS_FALLBACK: &[(&str, &str)] = &[
167+
("-apple-", "x86_64-apple-darwin"),
168+
("aarch64", "aarch64-unknown-linux-gnu"),
169+
("arm-", "aarch64-unknown-linux-gnu"),
170+
("", "x86_64-unknown-linux-gnu"),
169171
];
170172

171173
static MSI_INSTALLERS: &[&str] = &[
@@ -301,23 +303,27 @@ impl Builder {
301303
}
302304

303305
fn add_packages_to(&mut self, manifest: &mut Manifest) {
304-
let mut package = |name, targets| self.package(name, &mut manifest.pkg, targets);
305-
package("rustc", HOSTS);
306-
package("rustc-dev", HOSTS);
307-
package("reproducible-artifacts", HOSTS);
308-
package("rustc-docs", HOSTS);
309-
package("cargo", HOSTS);
310-
package("rust-mingw", MINGW);
311-
package("rust-std", TARGETS);
312-
package("rust-docs", DOCS_TARGETS);
313-
package("rust-src", &["*"]);
314-
package("rls-preview", HOSTS);
315-
package("rust-analyzer-preview", HOSTS);
316-
package("clippy-preview", HOSTS);
317-
package("miri-preview", HOSTS);
318-
package("rustfmt-preview", HOSTS);
319-
package("rust-analysis", TARGETS);
320-
package("llvm-tools-preview", TARGETS);
306+
macro_rules! package {
307+
($name:expr, $targets:expr) => {
308+
self.package($name, &mut manifest.pkg, $targets, &[])
309+
};
310+
}
311+
package!("rustc", HOSTS);
312+
package!("rustc-dev", HOSTS);
313+
package!("reproducible-artifacts", HOSTS);
314+
package!("rustc-docs", HOSTS);
315+
package!("cargo", HOSTS);
316+
package!("rust-mingw", MINGW);
317+
package!("rust-std", TARGETS);
318+
self.package("rust-docs", &mut manifest.pkg, HOSTS, DOCS_FALLBACK);
319+
package!("rust-src", &["*"]);
320+
package!("rls-preview", HOSTS);
321+
package!("rust-analyzer-preview", HOSTS);
322+
package!("clippy-preview", HOSTS);
323+
package!("miri-preview", HOSTS);
324+
package!("rustfmt-preview", HOSTS);
325+
package!("rust-analysis", TARGETS);
326+
package!("llvm-tools-preview", TARGETS);
321327
}
322328

323329
fn add_artifacts_to(&mut self, manifest: &mut Manifest) {
@@ -500,7 +506,13 @@ impl Builder {
500506
.extend(pkgs.iter().map(|s| (*s).to_owned()));
501507
}
502508

503-
fn package(&mut self, pkgname: &str, dst: &mut BTreeMap<String, Package>, targets: &[&str]) {
509+
fn package(
510+
&mut self,
511+
pkgname: &str,
512+
dst: &mut BTreeMap<String, Package>,
513+
targets: &[&str],
514+
fallback: &[(&str, &str)],
515+
) {
504516
let version_info = self
505517
.versions
506518
.version(&PkgType::from_component(pkgname))
@@ -512,16 +524,29 @@ impl Builder {
512524
is_present = false; // Pretend the component is entirely missing.
513525
}
514526

527+
macro_rules! tarball_name {
528+
($target_name:expr) => {
529+
self.versions.tarball_name(&PkgType::from_component(pkgname), $target_name).unwrap()
530+
};
531+
}
532+
let mut target_from_compressed_tar = |target_name| {
533+
let target = Target::from_compressed_tar(self, &tarball_name!(target_name));
534+
if target.available {
535+
return target;
536+
}
537+
for (substr, fallback_target) in fallback {
538+
if target_name.contains(substr) {
539+
return Target::from_compressed_tar(self, &tarball_name!(fallback_target));
540+
}
541+
}
542+
Target::unavailable()
543+
};
544+
515545
let targets = targets
516546
.iter()
517547
.map(|name| {
518548
let target = if is_present {
519-
let filename = self
520-
.versions
521-
.tarball_name(&PkgType::from_component(pkgname), name)
522-
.unwrap();
523-
524-
Target::from_compressed_tar(self, &filename)
549+
target_from_compressed_tar(name)
525550
} else {
526551
// If the component is not present for this build add it anyway but mark it as
527552
// unavailable -- this way rustup won't allow upgrades without --force

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

+2-6
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl Versions {
169169
}
170170

171171
pub(crate) fn archive_name(
172-
&mut self,
172+
&self,
173173
package: &PkgType,
174174
target: &str,
175175
extension: &str,
@@ -189,11 +189,7 @@ impl Versions {
189189
}
190190
}
191191

192-
pub(crate) fn tarball_name(
193-
&mut self,
194-
package: &PkgType,
195-
target: &str,
196-
) -> Result<String, Error> {
192+
pub(crate) fn tarball_name(&self, package: &PkgType, target: &str) -> Result<String, Error> {
197193
self.archive_name(package, target, "tar.gz")
198194
}
199195

0 commit comments

Comments
 (0)