1 //! Build a dist manifest, hash and sign everything.
2 //! This gets called by `promote-release`
3 //! (https://github.com/rust-lang/rust-central-station/tree/master/promote-release)
4 //! via `x.py dist hash-and-sign`; the cmdline arguments are set up
5 //! by rustbuild (in `src/bootstrap/dist.rs`).
11 use crate::checksum::Checksums;
12 use crate::manifest::{Component, Manifest, Package, Rename, Target};
13 use crate::versions::{PkgType, Versions};
14 use std::collections::{BTreeMap, HashMap, HashSet};
16 use std::fs::{self, File};
17 use std::path::{Path, PathBuf};
19 static HOSTS: &[&str] = &[
20 "aarch64-apple-darwin",
21 "aarch64-pc-windows-msvc",
22 "aarch64-unknown-linux-gnu",
23 "aarch64-unknown-linux-musl",
24 "arm-unknown-linux-gnueabi",
25 "arm-unknown-linux-gnueabihf",
26 "armv7-unknown-linux-gnueabihf",
28 "i686-pc-windows-gnu",
29 "i686-pc-windows-msvc",
30 "i686-unknown-linux-gnu",
31 "mips-unknown-linux-gnu",
32 "mips64-unknown-linux-gnuabi64",
33 "mips64el-unknown-linux-gnuabi64",
34 "mipsel-unknown-linux-gnu",
35 "mipsisa32r6-unknown-linux-gnu",
36 "mipsisa32r6el-unknown-linux-gnu",
37 "mipsisa64r6-unknown-linux-gnuabi64",
38 "mipsisa64r6el-unknown-linux-gnuabi64",
39 "powerpc-unknown-linux-gnu",
40 "powerpc64-unknown-linux-gnu",
41 "powerpc64le-unknown-linux-gnu",
42 "riscv64gc-unknown-linux-gnu",
43 "s390x-unknown-linux-gnu",
44 "x86_64-apple-darwin",
45 "x86_64-pc-windows-gnu",
46 "x86_64-pc-windows-msvc",
47 "x86_64-unknown-freebsd",
48 "x86_64-unknown-illumos",
49 "x86_64-unknown-linux-gnu",
50 "x86_64-unknown-linux-musl",
51 "x86_64-unknown-netbsd",
54 static TARGETS: &[&str] = &[
55 "aarch64-apple-darwin",
58 "aarch64-linux-android",
59 "aarch64-pc-windows-msvc",
60 "aarch64-unknown-hermit",
61 "aarch64-unknown-linux-gnu",
62 "aarch64-unknown-linux-musl",
63 "aarch64-unknown-none",
64 "aarch64-unknown-none-softfloat",
65 "aarch64-unknown-redox",
66 "arm-linux-androideabi",
67 "arm-unknown-linux-gnueabi",
68 "arm-unknown-linux-gnueabihf",
69 "arm-unknown-linux-musleabi",
70 "arm-unknown-linux-musleabihf",
71 "armv5te-unknown-linux-gnueabi",
72 "armv5te-unknown-linux-musleabi",
74 "armv7-linux-androideabi",
75 "thumbv7neon-linux-androideabi",
76 "armv7-unknown-linux-gnueabi",
77 "armv7-unknown-linux-gnueabihf",
79 "thumbv7neon-unknown-linux-gnueabihf",
80 "armv7-unknown-linux-musleabi",
81 "armv7-unknown-linux-musleabihf",
83 "armebv7r-none-eabihf",
87 "asmjs-unknown-emscripten",
89 "i586-pc-windows-msvc",
90 "i586-unknown-linux-gnu",
91 "i586-unknown-linux-musl",
94 "i686-pc-windows-gnu",
95 "i686-pc-windows-msvc",
96 "i686-unknown-freebsd",
97 "i686-unknown-linux-gnu",
98 "i686-unknown-linux-musl",
99 "mips-unknown-linux-gnu",
100 "mips-unknown-linux-musl",
101 "mips64-unknown-linux-gnuabi64",
102 "mips64-unknown-linux-muslabi64",
103 "mips64el-unknown-linux-gnuabi64",
104 "mips64el-unknown-linux-muslabi64",
105 "mipsisa32r6-unknown-linux-gnu",
106 "mipsisa32r6el-unknown-linux-gnu",
107 "mipsisa64r6-unknown-linux-gnuabi64",
108 "mipsisa64r6el-unknown-linux-gnuabi64",
109 "mipsel-unknown-linux-gnu",
110 "mipsel-unknown-linux-musl",
111 "nvptx64-nvidia-cuda",
112 "powerpc-unknown-linux-gnu",
113 "powerpc64-unknown-linux-gnu",
114 "powerpc64le-unknown-linux-gnu",
115 "riscv32i-unknown-none-elf",
116 "riscv32imc-unknown-none-elf",
117 "riscv32imac-unknown-none-elf",
118 "riscv32gc-unknown-linux-gnu",
119 "riscv64imac-unknown-none-elf",
120 "riscv64gc-unknown-none-elf",
121 "riscv64gc-unknown-linux-gnu",
122 "s390x-unknown-linux-gnu",
123 "sparc64-unknown-linux-gnu",
124 "sparcv9-sun-solaris",
125 "thumbv6m-none-eabi",
126 "thumbv7em-none-eabi",
127 "thumbv7em-none-eabihf",
128 "thumbv7m-none-eabi",
129 "thumbv8m.base-none-eabi",
130 "thumbv8m.main-none-eabi",
131 "thumbv8m.main-none-eabihf",
132 "wasm32-unknown-emscripten",
133 "wasm32-unknown-unknown",
135 "x86_64-apple-darwin",
137 "x86_64-fortanix-unknown-sgx",
139 "x86_64-linux-android",
140 "x86_64-pc-windows-gnu",
141 "x86_64-pc-windows-msvc",
142 "x86_64-rumprun-netbsd",
143 "x86_64-sun-solaris",
145 "x86_64-unknown-freebsd",
146 "x86_64-unknown-illumos",
147 "x86_64-unknown-linux-gnu",
148 "x86_64-unknown-linux-gnux32",
149 "x86_64-unknown-linux-musl",
150 "x86_64-unknown-netbsd",
151 "x86_64-unknown-redox",
152 "x86_64-unknown-hermit",
155 static DOCS_TARGETS: &[&str] = &[
156 "aarch64-unknown-linux-gnu",
158 "i686-pc-windows-gnu",
159 "i686-pc-windows-msvc",
160 "i686-unknown-linux-gnu",
161 "x86_64-apple-darwin",
162 "x86_64-pc-windows-gnu",
163 "x86_64-pc-windows-msvc",
164 "x86_64-unknown-linux-gnu",
165 "x86_64-unknown-linux-musl",
168 static MSI_INSTALLERS: &[&str] = &[
169 "aarch64-pc-windows-msvc",
170 "i686-pc-windows-gnu",
171 "i686-pc-windows-msvc",
172 "x86_64-pc-windows-gnu",
173 "x86_64-pc-windows-msvc",
176 static PKG_INSTALLERS: &[&str] = &["x86_64-apple-darwin", "aarch64-apple-darwin"];
178 static MINGW: &[&str] = &["i686-pc-windows-gnu", "x86_64-pc-windows-gnu"];
180 static NIGHTLY_ONLY_COMPONENTS: &[&str] = &["miri-preview", "rust-analyzer-preview"];
186 Err(e) => panic!("{} failed with {}", stringify!($e), e),
193 checksums: Checksums,
194 shipped_files: HashSet<String>,
203 let num_threads = if let Some(num) = env::var_os("BUILD_MANIFEST_NUM_THREADS") {
204 num.to_str().unwrap().parse().expect("invalid number for BUILD_MANIFEST_NUM_THREADS")
208 rayon::ThreadPoolBuilder::new()
209 .num_threads(num_threads)
211 .expect("failed to initialize Rayon");
213 let mut args = env::args().skip(1);
214 let input = PathBuf::from(args.next().unwrap());
215 let output = PathBuf::from(args.next().unwrap());
216 let date = args.next().unwrap();
217 let s3_address = args.next().unwrap();
218 let channel = args.next().unwrap();
221 versions: Versions::new(&channel, &input).unwrap(),
222 checksums: t!(Checksums::new()),
223 shipped_files: HashSet::new(),
234 fn build(&mut self) {
235 self.check_toolstate();
236 let manifest = self.build_manifest();
238 let channel = self.versions.channel().to_string();
239 self.write_channel_files(&channel, &manifest);
240 if channel == "stable" {
241 // channel-rust-1.XX.YY.toml
242 let rust_version = self.versions.rustc_version().to_string();
243 self.write_channel_files(&rust_version, &manifest);
245 // channel-rust-1.XX.toml
246 let major_minor = rust_version.split('.').take(2).collect::<Vec<_>>().join(".");
247 self.write_channel_files(&major_minor, &manifest);
250 if let Some(path) = std::env::var_os("BUILD_MANIFEST_SHIPPED_FILES_PATH") {
251 self.write_shipped_files(&Path::new(&path));
254 t!(self.checksums.store_cache());
257 /// If a tool does not pass its tests on *any* of Linux and Windows, don't ship
258 /// it on *all* targets, because tools like Miri can "cross-run" programs for
259 /// different targets, for example, run a program for `x86_64-pc-windows-msvc`
260 /// on `x86_64-unknown-linux-gnu`.
261 /// Right now, we do this only for Miri.
262 fn check_toolstate(&mut self) {
263 for file in &["toolstates-linux.json", "toolstates-windows.json"] {
264 let toolstates: Option<HashMap<String, String>> = File::open(self.input.join(file))
266 .and_then(|f| serde_json::from_reader(&f).ok());
267 let toolstates = toolstates.unwrap_or_else(|| {
268 println!("WARNING: `{}` missing/malformed; assuming all tools failed", file);
269 HashMap::default() // Use empty map if anything went wrong.
271 // Mark some tools as missing based on toolstate.
272 if toolstates.get("miri").map(|s| &*s as &str) != Some("test-pass") {
273 println!("Miri tests are not passing, removing component");
274 self.versions.disable_version(&PkgType::Miri);
280 fn build_manifest(&mut self) -> Manifest {
281 let mut manifest = Manifest {
282 manifest_version: "2".to_string(),
283 date: self.date.to_string(),
284 pkg: BTreeMap::new(),
285 artifacts: BTreeMap::new(),
286 renames: BTreeMap::new(),
287 profiles: BTreeMap::new(),
289 self.add_packages_to(&mut manifest);
290 self.add_artifacts_to(&mut manifest);
291 self.add_profiles_to(&mut manifest);
292 self.add_renames_to(&mut manifest);
293 manifest.pkg.insert("rust".to_string(), self.rust_package(&manifest));
295 self.checksums.fill_missing_checksums(&mut manifest);
300 fn add_packages_to(&mut self, manifest: &mut Manifest) {
301 let mut package = |name, targets| self.package(name, &mut manifest.pkg, targets);
302 package("rustc", HOSTS);
303 package("rustc-dev", HOSTS);
304 package("reproducible-artifacts", HOSTS);
305 package("rustc-docs", HOSTS);
306 package("cargo", HOSTS);
307 package("rust-mingw", MINGW);
308 package("rust-std", TARGETS);
309 package("rust-docs", DOCS_TARGETS);
310 package("rust-src", &["*"]);
311 package("rls-preview", HOSTS);
312 package("rust-analyzer-preview", HOSTS);
313 package("clippy-preview", HOSTS);
314 package("miri-preview", HOSTS);
315 package("rustfmt-preview", HOSTS);
316 package("rust-analysis", TARGETS);
317 package("llvm-tools-preview", TARGETS);
320 fn add_artifacts_to(&mut self, manifest: &mut Manifest) {
321 manifest.add_artifact("source-code", |artifact| {
322 let tarball = self.versions.tarball_name(&PkgType::Rustc, "src").unwrap();
323 artifact.add_tarball(self, "*", &tarball);
326 manifest.add_artifact("installer-msi", |artifact| {
327 for target in MSI_INSTALLERS {
328 let msi = self.versions.archive_name(&PkgType::Rust, target, "msi").unwrap();
329 artifact.add_file(self, target, &msi);
333 manifest.add_artifact("installer-pkg", |artifact| {
334 for target in PKG_INSTALLERS {
335 let pkg = self.versions.archive_name(&PkgType::Rust, target, "pkg").unwrap();
336 artifact.add_file(self, target, &pkg);
341 fn add_profiles_to(&mut self, manifest: &mut Manifest) {
342 let mut profile = |name, pkgs| self.profile(name, &mut manifest.profiles, pkgs);
343 profile("minimal", &["rustc", "cargo", "rust-std", "rust-mingw"]);
367 "rust-analyzer-preview",
369 "llvm-tools-preview",
375 // The compiler libraries are not stable for end users, and they're also huge, so we only
376 // `rustc-dev` for nightly users, and only in the "complete" profile. It's still possible
377 // for users to install the additional component manually, if needed.
378 if self.versions.channel() == "nightly" {
379 self.extend_profile("complete", &mut manifest.profiles, &["rustc-dev"]);
380 self.extend_profile("complete", &mut manifest.profiles, &["rustc-docs"]);
384 fn add_renames_to(&self, manifest: &mut Manifest) {
385 let mut rename = |from: &str, to: &str| {
386 manifest.renames.insert(from.to_owned(), Rename { to: to.to_owned() })
388 rename("rls", "rls-preview");
389 rename("rustfmt", "rustfmt-preview");
390 rename("clippy", "clippy-preview");
391 rename("miri", "miri-preview");
394 fn rust_package(&mut self, manifest: &Manifest) -> Package {
395 let version_info = self.versions.version(&PkgType::Rust).expect("missing Rust tarball");
396 let mut pkg = Package {
397 version: version_info.version.expect("missing Rust version"),
398 git_commit_hash: version_info.git_commit,
399 target: BTreeMap::new(),
402 if let Some(target) = self.target_host_combination(host, &manifest) {
403 pkg.target.insert(host.to_string(), target);
405 pkg.target.insert(host.to_string(), Target::unavailable());
412 fn target_host_combination(&mut self, host: &str, manifest: &Manifest) -> Option<Target> {
413 let filename = self.versions.tarball_name(&PkgType::Rust, host).unwrap();
415 let mut target = Target::from_compressed_tar(self, &filename);
416 if !target.available {
420 let mut components = Vec::new();
421 let mut extensions = Vec::new();
423 let host_component = |pkg| Component::from_str(pkg, host);
425 // rustc/rust-std/cargo/docs are all required,
426 // and so is rust-mingw if it's available for the target.
427 components.extend(vec![
428 host_component("rustc"),
429 host_component("rust-std"),
430 host_component("cargo"),
431 host_component("rust-docs"),
433 if host.contains("pc-windows-gnu") {
434 components.push(host_component("rust-mingw"));
437 // Tools are always present in the manifest,
438 // but might be marked as unavailable if they weren't built.
439 extensions.extend(vec![
440 host_component("clippy-preview"),
441 host_component("miri-preview"),
442 host_component("rls-preview"),
443 host_component("rust-analyzer-preview"),
444 host_component("rustfmt-preview"),
445 host_component("llvm-tools-preview"),
446 host_component("rust-analysis"),
452 .filter(|&&target| target != host)
453 .map(|target| Component::from_str("rust-std", target)),
455 extensions.extend(HOSTS.iter().map(|target| Component::from_str("rustc-dev", target)));
456 extensions.extend(HOSTS.iter().map(|target| Component::from_str("rustc-docs", target)));
457 extensions.push(Component::from_str("rust-src", "*"));
459 // If the components/extensions don't actually exist for this
460 // particular host/target combination then nix it entirely from our
462 let has_component = |c: &Component| {
466 let pkg = match manifest.pkg.get(&c.pkg) {
468 None => return false,
470 pkg.target.get(&c.target).is_some()
472 extensions.retain(&has_component);
473 components.retain(&has_component);
475 target.components = Some(components);
476 target.extensions = Some(extensions);
483 dst: &mut BTreeMap<String, Vec<String>>,
486 dst.insert(profile_name.to_owned(), pkgs.iter().map(|s| (*s).to_owned()).collect());
492 dst: &mut BTreeMap<String, Vec<String>>,
495 dst.get_mut(profile_name)
496 .expect("existing profile")
497 .extend(pkgs.iter().map(|s| (*s).to_owned()));
500 fn package(&mut self, pkgname: &str, dst: &mut BTreeMap<String, Package>, targets: &[&str]) {
501 let version_info = self
503 .version(&PkgType::from_component(pkgname))
504 .expect("failed to load package version");
505 let mut is_present = version_info.present;
507 // Never ship nightly-only components for other trains.
508 if self.versions.channel() != "nightly" && NIGHTLY_ONLY_COMPONENTS.contains(&pkgname) {
509 is_present = false; // Pretend the component is entirely missing.
512 let targets = targets
515 let target = if is_present {
518 .tarball_name(&PkgType::from_component(pkgname), name)
521 Target::from_compressed_tar(self, &filename)
523 // If the component is not present for this build add it anyway but mark it as
524 // unavailable -- this way rustup won't allow upgrades without --force
525 Target::unavailable()
527 (name.to_string(), target)
534 version: version_info.version.unwrap_or_default(),
535 git_commit_hash: version_info.git_commit,
541 fn url(&self, path: &Path) -> String {
542 let file_name = path.file_name().unwrap().to_str().unwrap();
543 format!("{}/{}/{}", self.s3_address, self.date, file_name)
546 fn write_channel_files(&mut self, channel_name: &str, manifest: &Manifest) {
547 self.write(&toml::to_string(&manifest).unwrap(), channel_name, ".toml");
548 self.write(&manifest.date, channel_name, "-date.txt");
550 manifest.pkg["rust"].git_commit_hash.as_ref().unwrap(),
552 "-git-commit-hash.txt",
556 fn write(&mut self, contents: &str, channel_name: &str, suffix: &str) {
557 let name = format!("channel-rust-{}{}", channel_name, suffix);
558 self.shipped_files.insert(name.clone());
560 let dst = self.output.join(name);
561 t!(fs::write(&dst, contents));
564 fn write_shipped_files(&self, path: &Path) {
565 let mut files = self.shipped_files.iter().map(|s| s.as_str()).collect::<Vec<_>>();
567 let content = format!("{}\n", files.join("\n"));
569 t!(std::fs::write(path, content.as_bytes()));