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, don't ship it.
258 /// Right now, we do this only for Miri.
259 fn check_toolstate(&mut self) {
260 let toolstates
: Option
<HashMap
<String
, String
>> =
261 File
::open(self.input
.join("toolstates-linux.json"))
263 .and_then(|f
| serde_json
::from_reader(&f
).ok());
264 let toolstates
= toolstates
.unwrap_or_else(|| {
266 "WARNING: `toolstates-linux.json` missing/malformed; \
267 assuming all tools failed"
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
);
278 fn build_manifest(&mut self) -> Manifest
{
279 let mut manifest
= Manifest
{
280 manifest_version
: "2".to_string(),
281 date
: self.date
.to_string(),
282 pkg
: BTreeMap
::new(),
283 artifacts
: BTreeMap
::new(),
284 renames
: BTreeMap
::new(),
285 profiles
: BTreeMap
::new(),
287 self.add_packages_to(&mut manifest
);
288 self.add_artifacts_to(&mut manifest
);
289 self.add_profiles_to(&mut manifest
);
290 self.add_renames_to(&mut manifest
);
291 manifest
.pkg
.insert("rust".to_string(), self.rust_package(&manifest
));
293 self.checksums
.fill_missing_checksums(&mut manifest
);
298 fn add_packages_to(&mut self, manifest
: &mut Manifest
) {
299 let mut package
= |name
, targets
| self.package(name
, &mut manifest
.pkg
, targets
);
300 package("rustc", HOSTS
);
301 package("rustc-dev", HOSTS
);
302 package("reproducible-artifacts", HOSTS
);
303 package("rustc-docs", HOSTS
);
304 package("cargo", HOSTS
);
305 package("rust-mingw", MINGW
);
306 package("rust-std", TARGETS
);
307 package("rust-docs", DOCS_TARGETS
);
308 package("rust-src", &["*"]);
309 package("rls-preview", HOSTS
);
310 package("rust-analyzer-preview", HOSTS
);
311 package("clippy-preview", HOSTS
);
312 package("miri-preview", HOSTS
);
313 package("rustfmt-preview", HOSTS
);
314 package("rust-analysis", TARGETS
);
315 package("llvm-tools-preview", TARGETS
);
318 fn add_artifacts_to(&mut self, manifest
: &mut Manifest
) {
319 manifest
.add_artifact("source-code", |artifact
| {
320 let tarball
= self.versions
.tarball_name(&PkgType
::Rustc
, "src").unwrap();
321 artifact
.add_tarball(self, "*", &tarball
);
324 manifest
.add_artifact("installer-msi", |artifact
| {
325 for target
in MSI_INSTALLERS
{
326 let msi
= self.versions
.archive_name(&PkgType
::Rust
, target
, "msi").unwrap();
327 artifact
.add_file(self, target
, &msi
);
331 manifest
.add_artifact("installer-pkg", |artifact
| {
332 for target
in PKG_INSTALLERS
{
333 let pkg
= self.versions
.archive_name(&PkgType
::Rust
, target
, "pkg").unwrap();
334 artifact
.add_file(self, target
, &pkg
);
339 fn add_profiles_to(&mut self, manifest
: &mut Manifest
) {
340 let mut profile
= |name
, pkgs
| self.profile(name
, &mut manifest
.profiles
, pkgs
);
341 profile("minimal", &["rustc", "cargo", "rust-std", "rust-mingw"]);
365 "rust-analyzer-preview",
367 "llvm-tools-preview",
373 // The compiler libraries are not stable for end users, and they're also huge, so we only
374 // `rustc-dev` for nightly users, and only in the "complete" profile. It's still possible
375 // for users to install the additional component manually, if needed.
376 if self.versions
.channel() == "nightly" {
377 self.extend_profile("complete", &mut manifest
.profiles
, &["rustc-dev"]);
378 self.extend_profile("complete", &mut manifest
.profiles
, &["rustc-docs"]);
382 fn add_renames_to(&self, manifest
: &mut Manifest
) {
383 let mut rename
= |from
: &str, to
: &str| {
384 manifest
.renames
.insert(from
.to_owned(), Rename { to: to.to_owned() }
)
386 rename("rls", "rls-preview");
387 rename("rustfmt", "rustfmt-preview");
388 rename("clippy", "clippy-preview");
389 rename("miri", "miri-preview");
392 fn rust_package(&mut self, manifest
: &Manifest
) -> Package
{
393 let version_info
= self.versions
.version(&PkgType
::Rust
).expect("missing Rust tarball");
394 let mut pkg
= Package
{
395 version
: version_info
.version
.expect("missing Rust version"),
396 git_commit_hash
: version_info
.git_commit
,
397 target
: BTreeMap
::new(),
400 if let Some(target
) = self.target_host_combination(host
, &manifest
) {
401 pkg
.target
.insert(host
.to_string(), target
);
403 pkg
.target
.insert(host
.to_string(), Target
::unavailable());
410 fn target_host_combination(&mut self, host
: &str, manifest
: &Manifest
) -> Option
<Target
> {
411 let filename
= self.versions
.tarball_name(&PkgType
::Rust
, host
).unwrap();
413 let mut target
= Target
::from_compressed_tar(self, &filename
);
414 if !target
.available
{
418 let mut components
= Vec
::new();
419 let mut extensions
= Vec
::new();
421 let host_component
= |pkg
| Component
::from_str(pkg
, host
);
423 // rustc/rust-std/cargo/docs are all required,
424 // and so is rust-mingw if it's available for the target.
425 components
.extend(vec
![
426 host_component("rustc"),
427 host_component("rust-std"),
428 host_component("cargo"),
429 host_component("rust-docs"),
431 if host
.contains("pc-windows-gnu") {
432 components
.push(host_component("rust-mingw"));
435 // Tools are always present in the manifest,
436 // but might be marked as unavailable if they weren't built.
437 extensions
.extend(vec
![
438 host_component("clippy-preview"),
439 host_component("miri-preview"),
440 host_component("rls-preview"),
441 host_component("rust-analyzer-preview"),
442 host_component("rustfmt-preview"),
443 host_component("llvm-tools-preview"),
444 host_component("rust-analysis"),
450 .filter(|&&target
| target
!= host
)
451 .map(|target
| Component
::from_str("rust-std", target
)),
453 extensions
.extend(HOSTS
.iter().map(|target
| Component
::from_str("rustc-dev", target
)));
454 extensions
.extend(HOSTS
.iter().map(|target
| Component
::from_str("rustc-docs", target
)));
455 extensions
.push(Component
::from_str("rust-src", "*"));
457 // If the components/extensions don't actually exist for this
458 // particular host/target combination then nix it entirely from our
460 let has_component
= |c
: &Component
| {
464 let pkg
= match manifest
.pkg
.get(&c
.pkg
) {
466 None
=> return false,
468 pkg
.target
.get(&c
.target
).is_some()
470 extensions
.retain(&has_component
);
471 components
.retain(&has_component
);
473 target
.components
= Some(components
);
474 target
.extensions
= Some(extensions
);
481 dst
: &mut BTreeMap
<String
, Vec
<String
>>,
484 dst
.insert(profile_name
.to_owned(), pkgs
.iter().map(|s
| (*s
).to_owned()).collect());
490 dst
: &mut BTreeMap
<String
, Vec
<String
>>,
493 dst
.get_mut(profile_name
)
494 .expect("existing profile")
495 .extend(pkgs
.iter().map(|s
| (*s
).to_owned()));
498 fn package(&mut self, pkgname
: &str, dst
: &mut BTreeMap
<String
, Package
>, targets
: &[&str]) {
499 let version_info
= self
501 .version(&PkgType
::from_component(pkgname
))
502 .expect("failed to load package version");
503 let mut is_present
= version_info
.present
;
505 // Never ship nightly-only components for other trains.
506 if self.versions
.channel() != "nightly" && NIGHTLY_ONLY_COMPONENTS
.contains(&pkgname
) {
507 is_present
= false; // Pretend the component is entirely missing.
510 let targets
= targets
513 let target
= if is_present
{
516 .tarball_name(&PkgType
::from_component(pkgname
), name
)
519 Target
::from_compressed_tar(self, &filename
)
521 // If the component is not present for this build add it anyway but mark it as
522 // unavailable -- this way rustup won't allow upgrades without --force
523 Target
::unavailable()
525 (name
.to_string(), target
)
532 version
: version_info
.version
.unwrap_or_default(),
533 git_commit_hash
: version_info
.git_commit
,
539 fn url(&self, path
: &Path
) -> String
{
540 let file_name
= path
.file_name().unwrap().to_str().unwrap();
541 format
!("{}/{}/{}", self.s3_address
, self.date
, file_name
)
544 fn write_channel_files(&mut self, channel_name
: &str, manifest
: &Manifest
) {
545 self.write(&toml
::to_string(&manifest
).unwrap(), channel_name
, ".toml");
546 self.write(&manifest
.date
, channel_name
, "-date.txt");
548 manifest
.pkg
["rust"].git_commit_hash
.as_ref().unwrap(),
550 "-git-commit-hash.txt",
554 fn write(&mut self, contents
: &str, channel_name
: &str, suffix
: &str) {
555 let name
= format
!("channel-rust-{}{}", channel_name
, suffix
);
556 self.shipped_files
.insert(name
.clone());
558 let dst
= self.output
.join(name
);
559 t
!(fs
::write(&dst
, contents
));
562 fn write_shipped_files(&self, path
: &Path
) {
563 let mut files
= self.shipped_files
.iter().map(|s
| s
.as_str()).collect
::<Vec
<_
>>();
565 let content
= format
!("{}\n", files
.join("\n"));
567 t
!(std
::fs
::write(path
, content
.as_bytes()));