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`).
12 use std::collections::BTreeMap;
15 use std::io::{self, Read, Write};
16 use std::path::{PathBuf, Path};
17 use std::process::{Command, Stdio};
19 static HOSTS: &[&str] = &[
20 "aarch64-unknown-linux-gnu",
21 "arm-unknown-linux-gnueabi",
22 "arm-unknown-linux-gnueabihf",
23 "armv7-unknown-linux-gnueabihf",
25 "i686-pc-windows-gnu",
26 "i686-pc-windows-msvc",
27 "i686-unknown-linux-gnu",
28 "mips-unknown-linux-gnu",
29 "mips64-unknown-linux-gnuabi64",
30 "mips64el-unknown-linux-gnuabi64",
31 "mipsel-unknown-linux-gnu",
32 "mipsisa32r6-unknown-linux-gnu",
33 "mipsisa32r6el-unknown-linux-gnu",
34 "mipsisa64r6-unknown-linux-gnuabi64",
35 "mipsisa64r6el-unknown-linux-gnuabi64",
36 "powerpc-unknown-linux-gnu",
37 "powerpc64-unknown-linux-gnu",
38 "powerpc64le-unknown-linux-gnu",
39 "s390x-unknown-linux-gnu",
40 "x86_64-apple-darwin",
41 "x86_64-pc-windows-gnu",
42 "x86_64-pc-windows-msvc",
43 "x86_64-unknown-freebsd",
44 "x86_64-unknown-linux-gnu",
45 "x86_64-unknown-linux-musl",
46 "x86_64-unknown-netbsd",
49 static TARGETS: &[&str] = &[
52 "aarch64-linux-android",
53 "aarch64-pc-windows-msvc",
54 "aarch64-unknown-cloudabi",
55 "aarch64-unknown-linux-gnu",
56 "aarch64-unknown-linux-musl",
57 "aarch64-unknown-redox",
58 "arm-linux-androideabi",
59 "arm-unknown-linux-gnueabi",
60 "arm-unknown-linux-gnueabihf",
61 "arm-unknown-linux-musleabi",
62 "arm-unknown-linux-musleabihf",
63 "armv5te-unknown-linux-gnueabi",
64 "armv5te-unknown-linux-musleabi",
66 "armv7-linux-androideabi",
67 "thumbv7neon-linux-androideabi",
68 "armv7-unknown-linux-gnueabi",
69 "armv7-unknown-linux-gnueabihf",
70 "thumbv7neon-unknown-linux-gnueabihf",
71 "armv7-unknown-linux-musleabi",
72 "armv7-unknown-linux-musleabihf",
74 "armebv7r-none-eabihf",
78 "asmjs-unknown-emscripten",
80 "i586-pc-windows-msvc",
81 "i586-unknown-linux-gnu",
82 "i586-unknown-linux-musl",
85 "i686-pc-windows-gnu",
86 "i686-pc-windows-msvc",
87 "i686-unknown-freebsd",
88 "i686-unknown-linux-gnu",
89 "i686-unknown-linux-musl",
90 "mips-unknown-linux-gnu",
91 "mips-unknown-linux-musl",
92 "mips64-unknown-linux-gnuabi64",
93 "mips64el-unknown-linux-gnuabi64",
94 "mipsisa32r6-unknown-linux-gnu",
95 "mipsisa32r6el-unknown-linux-gnu",
96 "mipsisa64r6-unknown-linux-gnuabi64",
97 "mipsisa64r6el-unknown-linux-gnuabi64",
98 "mipsel-unknown-linux-gnu",
99 "mipsel-unknown-linux-musl",
100 "nvptx64-nvidia-cuda",
101 "powerpc-unknown-linux-gnu",
102 "powerpc64-unknown-linux-gnu",
103 "powerpc64le-unknown-linux-gnu",
104 "riscv32i-unknown-none-elf",
105 "riscv32imc-unknown-none-elf",
106 "riscv32imac-unknown-none-elf",
107 "riscv64imac-unknown-none-elf",
108 "riscv64gc-unknown-none-elf",
109 "s390x-unknown-linux-gnu",
110 "sparc64-unknown-linux-gnu",
111 "sparcv9-sun-solaris",
112 "thumbv6m-none-eabi",
113 "thumbv7em-none-eabi",
114 "thumbv7em-none-eabihf",
115 "thumbv7m-none-eabi",
116 "thumbv8m.base-none-eabi",
117 "thumbv8m.main-none-eabi",
118 "thumbv8m.main-none-eabihf",
119 "wasm32-unknown-emscripten",
120 "wasm32-unknown-unknown",
122 "x86_64-apple-darwin",
124 "x86_64-fortanix-unknown-sgx",
126 "x86_64-linux-android",
127 "x86_64-pc-windows-gnu",
128 "x86_64-pc-windows-msvc",
129 "x86_64-rumprun-netbsd",
130 "x86_64-sun-solaris",
132 "x86_64-unknown-cloudabi",
133 "x86_64-unknown-freebsd",
134 "x86_64-unknown-linux-gnu",
135 "x86_64-unknown-linux-gnux32",
136 "x86_64-unknown-linux-musl",
137 "x86_64-unknown-netbsd",
138 "x86_64-unknown-redox",
141 static DOCS_TARGETS: &[&str] = &[
143 "i686-pc-windows-gnu",
144 "i686-pc-windows-msvc",
145 "i686-unknown-linux-gnu",
146 "x86_64-apple-darwin",
147 "x86_64-pc-windows-gnu",
148 "x86_64-pc-windows-msvc",
149 "x86_64-unknown-linux-gnu",
152 static MINGW: &[&str] = &[
153 "i686-pc-windows-gnu",
154 "x86_64-pc-windows-gnu",
158 #[serde(rename_all = "kebab-case")]
160 manifest_version: String,
162 pkg: BTreeMap<String, Package>,
163 renames: BTreeMap<String, Rename>,
164 profiles: BTreeMap<String, Vec<String>>,
170 git_commit_hash: Option<String>,
171 target: BTreeMap<String, Target>,
179 #[derive(Serialize, Default)]
183 hash: Option<String>,
184 xz_url: Option<String>,
185 xz_hash: Option<String>,
186 components: Option<Vec<Component>>,
187 extensions: Option<Vec<Component>>,
191 fn unavailable() -> Self { Self::default() }
201 fn from_str(pkg: &str, target: &str) -> Self {
202 Self { pkg: pkg.to_string(), target: target.to_string() }
207 ($e:expr) => (match $e {
209 Err(e) => panic!("{} failed with {}", stringify!($e), e),
214 rust_release: String,
215 cargo_release: String,
217 clippy_release: String,
218 rustfmt_release: String,
219 llvm_tools_release: String,
220 lldb_release: String,
221 miri_release: String,
225 gpg_passphrase: String,
226 digests: BTreeMap<String, String>,
230 rust_version: Option<String>,
231 cargo_version: Option<String>,
232 rls_version: Option<String>,
233 clippy_version: Option<String>,
234 rustfmt_version: Option<String>,
235 llvm_tools_version: Option<String>,
236 lldb_version: Option<String>,
237 miri_version: Option<String>,
239 rust_git_commit_hash: Option<String>,
240 cargo_git_commit_hash: Option<String>,
241 rls_git_commit_hash: Option<String>,
242 clippy_git_commit_hash: Option<String>,
243 rustfmt_git_commit_hash: Option<String>,
244 llvm_tools_git_commit_hash: Option<String>,
245 lldb_git_commit_hash: Option<String>,
246 miri_git_commit_hash: Option<String>,
252 // Avoid signing packages while manually testing
253 // Do NOT set this envvar in CI
254 let should_sign = env::var("BUILD_MANIFEST_DISABLE_SIGNING").is_err();
256 // Safety check to ensure signing is always enabled on CI
257 // The CI environment variable is set by both Travis and AppVeyor
258 if !should_sign && env::var("CI").is_ok() {
259 println!("The 'BUILD_MANIFEST_DISABLE_SIGNING' env var can't be enabled on CI.");
260 println!("If you're not running this on CI, unset the 'CI' env var.");
264 let mut args = env::args().skip(1);
265 let input = PathBuf::from(args.next().unwrap());
266 let output = PathBuf::from(args.next().unwrap());
267 let date = args.next().unwrap();
268 let rust_release = args.next().unwrap();
269 let s3_address = args.next().unwrap();
270 let cargo_release = args.next().unwrap();
271 let rls_release = args.next().unwrap();
272 let clippy_release = args.next().unwrap();
273 let miri_release = args.next().unwrap();
274 let rustfmt_release = args.next().unwrap();
275 let llvm_tools_release = args.next().unwrap();
276 let lldb_release = args.next().unwrap();
278 // Do not ask for a passphrase while manually testing
279 let mut passphrase = String::new();
281 // `x.py` passes the passphrase via stdin.
282 t!(io::stdin().read_to_string(&mut passphrase));
297 gpg_passphrase: passphrase,
298 digests: BTreeMap::new(),
305 clippy_version: None,
306 rustfmt_version: None,
307 llvm_tools_version: None,
311 rust_git_commit_hash: None,
312 cargo_git_commit_hash: None,
313 rls_git_commit_hash: None,
314 clippy_git_commit_hash: None,
315 rustfmt_git_commit_hash: None,
316 llvm_tools_git_commit_hash: None,
317 lldb_git_commit_hash: None,
318 miri_git_commit_hash: None,
324 enum PkgType { RustSrc, Cargo, Rls, Clippy, Rustfmt, LlvmTools, Lldb, Miri, Other }
327 fn from_component(component: &str) -> Self {
330 "rust-src" => RustSrc,
332 "rls" | "rls-preview" => Rls,
333 "clippy" | "clippy-preview" => Clippy,
334 "rustfmt" | "rustfmt-preview" => Rustfmt,
335 "llvm-tools" | "llvm-tools-preview" => LlvmTools,
336 "lldb" | "lldb-preview" => Lldb,
337 "miri" | "miri-preview" => Miri,
344 fn build(&mut self) {
345 self.rust_version = self.version("rust", "x86_64-unknown-linux-gnu");
346 self.cargo_version = self.version("cargo", "x86_64-unknown-linux-gnu");
347 self.rls_version = self.version("rls", "x86_64-unknown-linux-gnu");
348 self.clippy_version = self.version("clippy", "x86_64-unknown-linux-gnu");
349 self.rustfmt_version = self.version("rustfmt", "x86_64-unknown-linux-gnu");
350 self.llvm_tools_version = self.version("llvm-tools", "x86_64-unknown-linux-gnu");
351 // lldb is only built for macOS.
352 self.lldb_version = self.version("lldb", "x86_64-apple-darwin");
353 self.miri_version = self.version("miri", "x86_64-unknown-linux-gnu");
355 self.rust_git_commit_hash = self.git_commit_hash("rust", "x86_64-unknown-linux-gnu");
356 self.cargo_git_commit_hash = self.git_commit_hash("cargo", "x86_64-unknown-linux-gnu");
357 self.rls_git_commit_hash = self.git_commit_hash("rls", "x86_64-unknown-linux-gnu");
358 self.clippy_git_commit_hash = self.git_commit_hash("clippy", "x86_64-unknown-linux-gnu");
359 self.rustfmt_git_commit_hash = self.git_commit_hash("rustfmt", "x86_64-unknown-linux-gnu");
360 self.llvm_tools_git_commit_hash = self.git_commit_hash("llvm-tools",
361 "x86_64-unknown-linux-gnu");
362 self.lldb_git_commit_hash = self.git_commit_hash("lldb", "x86_64-unknown-linux-gnu");
363 self.miri_git_commit_hash = self.git_commit_hash("miri", "x86_64-unknown-linux-gnu");
365 self.digest_and_sign();
366 let manifest = self.build_manifest();
367 self.write_channel_files(&self.rust_release, &manifest);
369 if self.rust_release != "beta" && self.rust_release != "nightly" {
370 self.write_channel_files("stable", &manifest);
374 /// Hash all files, compute their signatures, and collect the hashes in `self.digests`.
375 fn digest_and_sign(&mut self) {
376 for file in t!(self.input.read_dir()).map(|e| t!(e).path()) {
377 let filename = file.file_name().unwrap().to_str().unwrap();
378 let digest = self.hash(&file);
380 assert!(self.digests.insert(filename.to_string(), digest).is_none());
384 fn build_manifest(&mut self) -> Manifest {
385 let mut manifest = Manifest {
386 manifest_version: "2".to_string(),
387 date: self.date.to_string(),
388 pkg: BTreeMap::new(),
389 renames: BTreeMap::new(),
390 profiles: BTreeMap::new(),
392 self.add_packages_to(&mut manifest);
393 self.add_profiles_to(&mut manifest);
394 self.add_renames_to(&mut manifest);
395 manifest.pkg.insert("rust".to_string(), self.rust_package(&manifest));
399 fn add_packages_to(&mut self, manifest: &mut Manifest) {
400 let mut package = |name, targets| self.package(name, &mut manifest.pkg, targets);
401 package("rustc", HOSTS);
402 package("rustc-dev", HOSTS);
403 package("cargo", HOSTS);
404 package("rust-mingw", MINGW);
405 package("rust-std", TARGETS);
406 package("rust-docs", DOCS_TARGETS);
407 package("rust-src", &["*"]);
408 package("rls-preview", HOSTS);
409 package("clippy-preview", HOSTS);
410 package("miri-preview", HOSTS);
411 package("rustfmt-preview", HOSTS);
412 package("rust-analysis", TARGETS);
413 package("llvm-tools-preview", TARGETS);
414 package("lldb-preview", TARGETS);
417 fn add_profiles_to(&mut self, manifest: &mut Manifest) {
418 let mut profile = |name, pkgs| self.profile(name, &mut manifest.profiles, pkgs);
419 profile("minimal", &["rustc", "cargo", "rust-std", "rust-mingw"]);
420 profile("default", &[
421 "rustc", "cargo", "rust-std", "rust-mingw",
422 "rust-docs", "rustfmt-preview", "clippy-preview"
424 profile("complete", &[
425 "rustc", "cargo", "rust-std", "rust-mingw",
426 "rust-docs", "rustfmt-preview", "clippy-preview",
427 "rls-preview", "rust-src", "llvm-tools-preview",
428 "lldb-preview", "rust-analysis", "miri-preview"
432 fn add_renames_to(&self, manifest: &mut Manifest) {
433 let mut rename = |from: &str, to: &str| manifest.renames.insert(
435 Rename { to: to.to_owned() }
437 rename("rls", "rls-preview");
438 rename("rustfmt", "rustfmt-preview");
439 rename("clippy", "clippy-preview");
440 rename("miri", "miri-preview");
443 fn rust_package(&mut self, manifest: &Manifest) -> Package {
444 let mut pkg = Package {
445 version: self.cached_version("rust")
447 .expect("Couldn't find Rust version")
449 git_commit_hash: self.cached_git_commit_hash("rust").clone(),
450 target: BTreeMap::new(),
453 if let Some(target) = self.target_host_combination(host, &manifest) {
454 pkg.target.insert(host.to_string(), target);
456 pkg.target.insert(host.to_string(), Target::unavailable());
463 fn target_host_combination(&mut self, host: &str, manifest: &Manifest) -> Option<Target> {
464 let filename = self.filename("rust", host);
465 let digest = self.digests.remove(&filename)?;
466 let xz_filename = filename.replace(".tar.gz", ".tar.xz");
467 let xz_digest = self.digests.remove(&xz_filename);
468 let mut components = Vec::new();
469 let mut extensions = Vec::new();
471 let host_component = |pkg| Component::from_str(pkg, host);
473 // rustc/rust-std/cargo/docs are all required,
474 // and so is rust-mingw if it's available for the target.
475 components.extend(vec![
476 host_component("rustc"),
477 host_component("rust-std"),
478 host_component("cargo"),
479 host_component("rust-docs"),
481 if host.contains("pc-windows-gnu") {
482 components.push(host_component("rust-mingw"));
485 // The compiler libraries are not stable for end users, but `rustc-dev` was only recently
486 // split out of `rust-std`. We'll include it by default as a transition for nightly users,
487 // but ship it as an optional component on the beta and stable channels.
488 if self.rust_release == "nightly" {
489 components.push(host_component("rustc-dev"));
491 extensions.push(host_component("rustc-dev"));
494 // Tools are always present in the manifest,
495 // but might be marked as unavailable if they weren't built.
496 extensions.extend(vec![
497 host_component("clippy-preview"),
498 host_component("miri-preview"),
499 host_component("rls-preview"),
500 host_component("rustfmt-preview"),
501 host_component("llvm-tools-preview"),
502 host_component("lldb-preview"),
503 host_component("rust-analysis"),
508 .filter(|&&target| target != host)
509 .map(|target| Component::from_str("rust-std", target))
513 .filter(|&&target| target != host)
514 .map(|target| Component::from_str("rustc-dev", target))
516 extensions.push(Component::from_str("rust-src", "*"));
518 // If the components/extensions don't actually exist for this
519 // particular host/target combination then nix it entirely from our
521 let has_component = |c: &Component| {
525 let pkg = match manifest.pkg.get(&c.pkg) {
527 None => return false,
529 pkg.target.get(&c.target).is_some()
531 extensions.retain(&has_component);
532 components.retain(&has_component);
536 url: Some(self.url(&filename)),
538 xz_url: xz_digest.as_ref().map(|_| self.url(&xz_filename)),
540 components: Some(components),
541 extensions: Some(extensions),
545 fn profile(&mut self,
547 dst: &mut BTreeMap<String, Vec<String>>,
549 dst.insert(profile_name.to_owned(), pkgs.iter().map(|s| (*s).to_owned()).collect());
552 fn package(&mut self,
554 dst: &mut BTreeMap<String, Package>,
556 let (version, mut is_present) = self.cached_version(pkgname)
559 .map(|version| (version, true))
560 .unwrap_or_default(); // `is_present` defaults to `false` here.
562 // Miri is nightly-only; never ship it for other trains.
563 if pkgname == "miri-preview" && self.rust_release != "nightly" {
564 is_present = false; // Pretend the component is entirely missing.
567 let targets = targets.iter().map(|name| {
569 // The component generally exists, but it might still be missing for this target.
570 let filename = self.filename(pkgname, name);
571 let digest = match self.digests.remove(&filename) {
572 Some(digest) => digest,
573 // This component does not exist for this target -- skip it.
574 None => return (name.to_string(), Target::unavailable()),
576 let xz_filename = filename.replace(".tar.gz", ".tar.xz");
577 let xz_digest = self.digests.remove(&xz_filename);
579 (name.to_string(), Target {
581 url: Some(self.url(&filename)),
583 xz_url: xz_digest.as_ref().map(|_| self.url(&xz_filename)),
589 // If the component is not present for this build add it anyway but mark it as
590 // unavailable -- this way rustup won't allow upgrades without --force
591 (name.to_string(), Target::unavailable())
595 dst.insert(pkgname.to_string(), Package {
597 git_commit_hash: self.cached_git_commit_hash(pkgname).clone(),
602 fn url(&self, filename: &str) -> String {
609 fn filename(&self, component: &str, target: &str) -> String {
611 match PkgType::from_component(component) {
612 RustSrc => format!("rust-src-{}.tar.gz", self.rust_release),
613 Cargo => format!("cargo-{}-{}.tar.gz", self.cargo_release, target),
614 Rls => format!("rls-{}-{}.tar.gz", self.rls_release, target),
615 Clippy => format!("clippy-{}-{}.tar.gz", self.clippy_release, target),
616 Rustfmt => format!("rustfmt-{}-{}.tar.gz", self.rustfmt_release, target),
617 LlvmTools => format!("llvm-tools-{}-{}.tar.gz", self.llvm_tools_release, target),
618 Lldb => format!("lldb-{}-{}.tar.gz", self.lldb_release, target),
619 Miri => format!("miri-{}-{}.tar.gz", self.miri_release, target),
620 Other => format!("{}-{}-{}.tar.gz", component, self.rust_release, target),
624 fn cached_version(&self, component: &str) -> &Option<String> {
626 match PkgType::from_component(component) {
627 Cargo => &self.cargo_version,
628 Rls => &self.rls_version,
629 Clippy => &self.clippy_version,
630 Rustfmt => &self.rustfmt_version,
631 LlvmTools => &self.llvm_tools_version,
632 Lldb => &self.lldb_version,
633 Miri => &self.miri_version,
634 _ => &self.rust_version,
638 fn cached_git_commit_hash(&self, component: &str) -> &Option<String> {
640 match PkgType::from_component(component) {
641 Cargo => &self.cargo_git_commit_hash,
642 Rls => &self.rls_git_commit_hash,
643 Clippy => &self.clippy_git_commit_hash,
644 Rustfmt => &self.rustfmt_git_commit_hash,
645 LlvmTools => &self.llvm_tools_git_commit_hash,
646 Lldb => &self.lldb_git_commit_hash,
647 Miri => &self.miri_git_commit_hash,
648 _ => &self.rust_git_commit_hash,
652 fn version(&self, component: &str, target: &str) -> Option<String> {
653 self.untar(component, target, |filename| format!("{}/version", filename))
656 fn git_commit_hash(&self, component: &str, target: &str) -> Option<String> {
657 self.untar(component, target, |filename| format!("{}/git-commit-hash", filename))
660 fn untar<F>(&self, component: &str, target: &str, dir: F) -> Option<String>
662 F: FnOnce(String) -> String
664 let mut cmd = Command::new("tar");
665 let filename = self.filename(component, target);
667 .arg(self.input.join(&filename))
668 .arg(dir(filename.replace(".tar.gz", "")))
670 let output = t!(cmd.output());
671 if output.status.success() {
672 Some(String::from_utf8_lossy(&output.stdout).trim().to_string())
678 fn hash(&self, path: &Path) -> String {
679 let sha = t!(Command::new("shasum")
680 .arg("-a").arg("256")
681 .arg(path.file_name().unwrap())
682 .current_dir(path.parent().unwrap())
684 assert!(sha.status.success());
686 let filename = path.file_name().unwrap().to_str().unwrap();
687 let sha256 = self.output.join(format!("{}.sha256", filename));
688 t!(fs::write(&sha256, &sha.stdout));
690 let stdout = String::from_utf8_lossy(&sha.stdout);
691 stdout.split_whitespace().next().unwrap().to_string()
694 fn sign(&self, path: &Path) {
695 if !self.should_sign {
699 let filename = path.file_name().unwrap().to_str().unwrap();
700 let asc = self.output.join(format!("{}.asc", filename));
701 println!("signing: {:?}", path);
702 let mut cmd = Command::new("gpg");
703 cmd.arg("--pinentry-mode=loopback")
707 .arg("--passphrase-fd").arg("0")
708 .arg("--personal-digest-preferences").arg("SHA512")
710 .arg("--output").arg(&asc)
711 .arg("--detach-sign").arg(path)
712 .stdin(Stdio::piped());
713 let mut child = t!(cmd.spawn());
714 t!(child.stdin.take().unwrap().write_all(self.gpg_passphrase.as_bytes()));
715 assert!(t!(child.wait()).success());
718 fn write_channel_files(&self, channel_name: &str, manifest: &Manifest) {
719 self.write(&toml::to_string(&manifest).unwrap(), channel_name, ".toml");
720 self.write(&manifest.date, channel_name, "-date.txt");
721 self.write(manifest.pkg["rust"].git_commit_hash.as_ref().unwrap(),
722 channel_name, "-git-commit-hash.txt");
725 fn write(&self, contents: &str, channel_name: &str, suffix: &str) {
726 let dst = self.output.join(format!("channel-rust-{}{}", channel_name, suffix));
727 t!(fs::write(&dst, contents));