3 extern crate serde_derive;
5 use std::collections::BTreeMap;
8 use std::io::{self, Read, Write};
9 use std::path::{PathBuf, Path};
10 use std::process::{Command, Stdio};
12 static HOSTS: &'static [&'static str] = &[
13 "aarch64-unknown-linux-gnu",
14 "arm-unknown-linux-gnueabi",
15 "arm-unknown-linux-gnueabihf",
16 "armv7-unknown-linux-gnueabihf",
18 "i686-pc-windows-gnu",
19 "i686-pc-windows-msvc",
20 "i686-unknown-linux-gnu",
21 "mips-unknown-linux-gnu",
22 "mips64-unknown-linux-gnuabi64",
23 "mips64el-unknown-linux-gnuabi64",
24 "mipsel-unknown-linux-gnu",
25 "powerpc-unknown-linux-gnu",
26 "powerpc64-unknown-linux-gnu",
27 "powerpc64le-unknown-linux-gnu",
28 "s390x-unknown-linux-gnu",
29 "x86_64-apple-darwin",
30 "x86_64-pc-windows-gnu",
31 "x86_64-pc-windows-msvc",
32 "x86_64-unknown-freebsd",
33 "x86_64-unknown-linux-gnu",
34 "x86_64-unknown-netbsd",
37 static TARGETS: &'static [&'static str] = &[
40 "aarch64-linux-android",
41 "aarch64-pc-windows-msvc",
42 "aarch64-unknown-cloudabi",
43 "aarch64-unknown-linux-gnu",
44 "aarch64-unknown-linux-musl",
45 "arm-linux-androideabi",
46 "arm-unknown-linux-gnueabi",
47 "arm-unknown-linux-gnueabihf",
48 "arm-unknown-linux-musleabi",
49 "arm-unknown-linux-musleabihf",
50 "armv5te-unknown-linux-gnueabi",
51 "armv5te-unknown-linux-musleabi",
53 "armv7-linux-androideabi",
54 "thumbv7neon-linux-androideabi",
55 "armv7-unknown-linux-gnueabihf",
56 "thumbv7neon-unknown-linux-gnueabihf",
57 "armv7-unknown-linux-musleabihf",
59 "armebv7r-none-eabihf",
63 "asmjs-unknown-emscripten",
65 "i586-pc-windows-msvc",
66 "i586-unknown-linux-gnu",
67 "i586-unknown-linux-musl",
70 "i686-pc-windows-gnu",
71 "i686-pc-windows-msvc",
72 "i686-unknown-freebsd",
73 "i686-unknown-linux-gnu",
74 "i686-unknown-linux-musl",
75 "mips-unknown-linux-gnu",
76 "mips-unknown-linux-musl",
77 "mips64-unknown-linux-gnuabi64",
78 "mips64el-unknown-linux-gnuabi64",
79 "mipsel-unknown-linux-gnu",
80 "mipsel-unknown-linux-musl",
81 "powerpc-unknown-linux-gnu",
82 "powerpc64-unknown-linux-gnu",
83 "powerpc64le-unknown-linux-gnu",
84 "riscv32imc-unknown-none-elf",
85 "riscv32imac-unknown-none-elf",
86 "s390x-unknown-linux-gnu",
87 "sparc64-unknown-linux-gnu",
88 "sparcv9-sun-solaris",
90 "thumbv7em-none-eabi",
91 "thumbv7em-none-eabihf",
93 "wasm32-unknown-emscripten",
94 "wasm32-unknown-unknown",
95 "x86_64-apple-darwin",
98 "x86_64-linux-android",
99 "x86_64-pc-windows-gnu",
100 "x86_64-pc-windows-msvc",
101 "x86_64-rumprun-netbsd",
102 "x86_64-sun-solaris",
103 "x86_64-unknown-cloudabi",
104 "x86_64-unknown-freebsd",
105 "x86_64-unknown-linux-gnu",
106 "x86_64-unknown-linux-gnux32",
107 "x86_64-unknown-linux-musl",
108 "x86_64-unknown-netbsd",
109 "x86_64-unknown-redox",
112 static DOCS_TARGETS: &'static [&'static str] = &[
114 "i686-pc-windows-gnu",
115 "i686-pc-windows-msvc",
116 "i686-unknown-linux-gnu",
117 "x86_64-apple-darwin",
118 "x86_64-pc-windows-gnu",
119 "x86_64-pc-windows-msvc",
120 "x86_64-unknown-linux-gnu",
123 static MINGW: &'static [&'static str] = &[
124 "i686-pc-windows-gnu",
125 "x86_64-pc-windows-gnu",
129 #[serde(rename_all = "kebab-case")]
131 manifest_version: String,
133 pkg: BTreeMap<String, Package>,
134 renames: BTreeMap<String, Rename>,
135 profiles: BTreeMap<String, Vec<String>>,
141 git_commit_hash: Option<String>,
142 target: BTreeMap<String, Target>,
154 hash: Option<String>,
155 xz_url: Option<String>,
156 xz_hash: Option<String>,
157 components: Option<Vec<Component>>,
158 extensions: Option<Vec<Component>>,
162 fn unavailable() -> Target {
182 ($e:expr) => (match $e {
184 Err(e) => panic!("{} failed with {}", stringify!($e), e),
189 rust_release: String,
190 cargo_release: String,
192 clippy_release: String,
193 rustfmt_release: String,
194 llvm_tools_release: String,
195 lldb_release: String,
196 miri_release: String,
200 gpg_passphrase: String,
201 digests: BTreeMap<String, String>,
205 rust_version: Option<String>,
206 cargo_version: Option<String>,
207 rls_version: Option<String>,
208 clippy_version: Option<String>,
209 rustfmt_version: Option<String>,
210 llvm_tools_version: Option<String>,
211 lldb_version: Option<String>,
212 miri_version: Option<String>,
214 rust_git_commit_hash: Option<String>,
215 cargo_git_commit_hash: Option<String>,
216 rls_git_commit_hash: Option<String>,
217 clippy_git_commit_hash: Option<String>,
218 rustfmt_git_commit_hash: Option<String>,
219 llvm_tools_git_commit_hash: Option<String>,
220 lldb_git_commit_hash: Option<String>,
221 miri_git_commit_hash: Option<String>,
227 // Avoid signing packages while manually testing
228 // Do NOT set this envvar in CI
229 let should_sign = env::var("BUILD_MANIFEST_DISABLE_SIGNING").is_err();
231 // Safety check to ensure signing is always enabled on CI
232 // The CI environment variable is set by both Travis and AppVeyor
233 if !should_sign && env::var("CI").is_ok() {
234 println!("The 'BUILD_MANIFEST_DISABLE_SIGNING' env var can't be enabled on CI.");
235 println!("If you're not running this on CI, unset the 'CI' env var.");
239 let mut args = env::args().skip(1);
240 let input = PathBuf::from(args.next().unwrap());
241 let output = PathBuf::from(args.next().unwrap());
242 let date = args.next().unwrap();
243 let rust_release = args.next().unwrap();
244 let s3_address = args.next().unwrap();
245 let cargo_release = args.next().unwrap();
246 let rls_release = args.next().unwrap();
247 let clippy_release = args.next().unwrap();
248 let miri_release = args.next().unwrap();
249 let rustfmt_release = args.next().unwrap();
250 let llvm_tools_release = args.next().unwrap();
251 let lldb_release = args.next().unwrap();
253 // Do not ask for a passphrase while manually testing
254 let mut passphrase = String::new();
256 t!(io::stdin().read_to_string(&mut passphrase));
271 gpg_passphrase: passphrase,
272 digests: BTreeMap::new(),
279 clippy_version: None,
280 rustfmt_version: None,
281 llvm_tools_version: None,
285 rust_git_commit_hash: None,
286 cargo_git_commit_hash: None,
287 rls_git_commit_hash: None,
288 clippy_git_commit_hash: None,
289 rustfmt_git_commit_hash: None,
290 llvm_tools_git_commit_hash: None,
291 lldb_git_commit_hash: None,
292 miri_git_commit_hash: None,
299 fn build(&mut self) {
300 self.rust_version = self.version("rust", "x86_64-unknown-linux-gnu");
301 self.cargo_version = self.version("cargo", "x86_64-unknown-linux-gnu");
302 self.rls_version = self.version("rls", "x86_64-unknown-linux-gnu");
303 self.clippy_version = self.version("clippy", "x86_64-unknown-linux-gnu");
304 self.rustfmt_version = self.version("rustfmt", "x86_64-unknown-linux-gnu");
305 self.llvm_tools_version = self.version("llvm-tools", "x86_64-unknown-linux-gnu");
306 // lldb is only built for macOS.
307 self.lldb_version = self.version("lldb", "x86_64-apple-darwin");
308 self.miri_version = self.version("miri", "x86_64-unknown-linux-gnu");
310 self.rust_git_commit_hash = self.git_commit_hash("rust", "x86_64-unknown-linux-gnu");
311 self.cargo_git_commit_hash = self.git_commit_hash("cargo", "x86_64-unknown-linux-gnu");
312 self.rls_git_commit_hash = self.git_commit_hash("rls", "x86_64-unknown-linux-gnu");
313 self.clippy_git_commit_hash = self.git_commit_hash("clippy", "x86_64-unknown-linux-gnu");
314 self.rustfmt_git_commit_hash = self.git_commit_hash("rustfmt", "x86_64-unknown-linux-gnu");
315 self.llvm_tools_git_commit_hash = self.git_commit_hash("llvm-tools",
316 "x86_64-unknown-linux-gnu");
317 self.lldb_git_commit_hash = self.git_commit_hash("lldb", "x86_64-unknown-linux-gnu");
318 self.miri_git_commit_hash = self.git_commit_hash("miri", "x86_64-unknown-linux-gnu");
320 self.digest_and_sign();
321 let manifest = self.build_manifest();
322 self.write_channel_files(&self.rust_release, &manifest);
324 if self.rust_release != "beta" && self.rust_release != "nightly" {
325 self.write_channel_files("stable", &manifest);
329 fn digest_and_sign(&mut self) {
330 for file in t!(self.input.read_dir()).map(|e| t!(e).path()) {
331 let filename = file.file_name().unwrap().to_str().unwrap();
332 let digest = self.hash(&file);
334 assert!(self.digests.insert(filename.to_string(), digest).is_none());
338 fn build_manifest(&mut self) -> Manifest {
339 let mut manifest = Manifest {
340 manifest_version: "2".to_string(),
341 date: self.date.to_string(),
342 pkg: BTreeMap::new(),
343 renames: BTreeMap::new(),
344 profiles: BTreeMap::new(),
347 self.package("rustc", &mut manifest.pkg, HOSTS);
348 self.package("cargo", &mut manifest.pkg, HOSTS);
349 self.package("rust-mingw", &mut manifest.pkg, MINGW);
350 self.package("rust-std", &mut manifest.pkg, TARGETS);
351 self.package("rust-docs", &mut manifest.pkg, DOCS_TARGETS);
352 self.package("rust-src", &mut manifest.pkg, &["*"]);
353 self.package("rls-preview", &mut manifest.pkg, HOSTS);
354 self.package("clippy-preview", &mut manifest.pkg, HOSTS);
355 self.package("rustfmt-preview", &mut manifest.pkg, HOSTS);
356 self.package("rust-analysis", &mut manifest.pkg, TARGETS);
357 self.package("llvm-tools-preview", &mut manifest.pkg, TARGETS);
358 self.package("lldb-preview", &mut manifest.pkg, TARGETS);
360 self.profile("minimal",
361 &mut manifest.profiles,
362 &["rustc", "cargo", "rust-std", "rust-mingw"]);
363 self.profile("default",
364 &mut manifest.profiles,
365 &["rustc", "cargo", "rust-std", "rust-mingw",
366 "rust-docs", "rustfmt-preview", "clippy-preview"]);
367 self.profile("complete",
368 &mut manifest.profiles,
369 &["rustc", "cargo", "rust-std", "rust-mingw",
370 "rust-docs", "rustfmt-preview", "clippy-preview",
371 "rls-preview", "rust-src", "llvm-tools-preview",
372 "lldb-preview", "rust-analysis"]);
374 manifest.renames.insert("rls".to_owned(), Rename { to: "rls-preview".to_owned() });
375 manifest.renames.insert("rustfmt".to_owned(), Rename { to: "rustfmt-preview".to_owned() });
376 manifest.renames.insert("clippy".to_owned(), Rename { to: "clippy-preview".to_owned() });
378 let mut pkg = Package {
379 version: self.cached_version("rust")
381 .expect("Couldn't find Rust version")
383 git_commit_hash: self.cached_git_commit_hash("rust").clone(),
384 target: BTreeMap::new(),
387 let filename = self.filename("rust", host);
388 let digest = match self.digests.remove(&filename) {
389 Some(digest) => digest,
391 pkg.target.insert(host.to_string(), Target::unavailable());
395 let xz_filename = filename.replace(".tar.gz", ".tar.xz");
396 let xz_digest = self.digests.remove(&xz_filename);
397 let mut components = Vec::new();
398 let mut extensions = Vec::new();
400 // rustc/rust-std/cargo/docs are all required, and so is rust-mingw
401 // if it's available for the target.
402 components.extend(vec![
403 Component { pkg: "rustc".to_string(), target: host.to_string() },
404 Component { pkg: "rust-std".to_string(), target: host.to_string() },
405 Component { pkg: "cargo".to_string(), target: host.to_string() },
406 Component { pkg: "rust-docs".to_string(), target: host.to_string() },
408 if host.contains("pc-windows-gnu") {
409 components.push(Component {
410 pkg: "rust-mingw".to_string(),
411 target: host.to_string(),
415 // Tools are always present in the manifest, but might be marked as unavailable if they
417 extensions.extend(vec![
418 Component { pkg: "clippy-preview".to_string(), target: host.to_string() },
419 Component { pkg: "rls-preview".to_string(), target: host.to_string() },
420 Component { pkg: "rustfmt-preview".to_string(), target: host.to_string() },
421 Component { pkg: "llvm-tools-preview".to_string(), target: host.to_string() },
422 Component { pkg: "lldb-preview".to_string(), target: host.to_string() },
423 Component { pkg: "rust-analysis".to_string(), target: host.to_string() },
426 for target in TARGETS {
428 extensions.push(Component {
429 pkg: "rust-std".to_string(),
430 target: target.to_string(),
434 extensions.push(Component {
435 pkg: "rust-src".to_string(),
436 target: "*".to_string(),
439 // If the components/extensions don't actually exist for this
440 // particular host/target combination then nix it entirely from our
443 let has_component = |c: &Component| {
447 let pkg = match manifest.pkg.get(&c.pkg) {
449 None => return false,
451 pkg.target.get(&c.target).is_some()
453 extensions.retain(&has_component);
454 components.retain(&has_component);
457 pkg.target.insert(host.to_string(), Target {
459 url: Some(self.url(&filename)),
461 xz_url: xz_digest.as_ref().map(|_| self.url(&xz_filename)),
463 components: Some(components),
464 extensions: Some(extensions),
467 manifest.pkg.insert("rust".to_string(), pkg);
472 fn profile(&mut self,
474 dst: &mut BTreeMap<String, Vec<String>>,
476 dst.insert(profile_name.to_owned(), pkgs.iter().map(|s| (*s).to_owned()).collect());
479 fn package(&mut self,
481 dst: &mut BTreeMap<String, Package>,
483 let (version, is_present) = match *self.cached_version(pkgname) {
484 Some(ref version) => (version.clone(), true),
485 None => (String::new(), false),
488 let targets = targets.iter().map(|name| {
490 let filename = self.filename(pkgname, name);
491 let digest = match self.digests.remove(&filename) {
492 Some(digest) => digest,
493 None => return (name.to_string(), Target::unavailable()),
495 let xz_filename = filename.replace(".tar.gz", ".tar.xz");
496 let xz_digest = self.digests.remove(&xz_filename);
498 (name.to_string(), Target {
500 url: Some(self.url(&filename)),
502 xz_url: xz_digest.as_ref().map(|_| self.url(&xz_filename)),
508 // If the component is not present for this build add it anyway but mark it as
509 // unavailable -- this way rustup won't allow upgrades without --force
510 (name.to_string(), Target {
522 dst.insert(pkgname.to_string(), Package {
524 git_commit_hash: self.cached_git_commit_hash(pkgname).clone(),
529 fn url(&self, filename: &str) -> String {
536 fn filename(&self, component: &str, target: &str) -> String {
537 if component == "rust-src" {
538 format!("rust-src-{}.tar.gz", self.rust_release)
539 } else if component == "cargo" {
540 format!("cargo-{}-{}.tar.gz", self.cargo_release, target)
541 } else if component == "rls" || component == "rls-preview" {
542 format!("rls-{}-{}.tar.gz", self.rls_release, target)
543 } else if component == "clippy" || component == "clippy-preview" {
544 format!("clippy-{}-{}.tar.gz", self.clippy_release, target)
545 } else if component == "rustfmt" || component == "rustfmt-preview" {
546 format!("rustfmt-{}-{}.tar.gz", self.rustfmt_release, target)
547 } else if component == "llvm-tools" || component == "llvm-tools-preview" {
548 format!("llvm-tools-{}-{}.tar.gz", self.llvm_tools_release, target)
549 } else if component == "lldb" || component == "lldb-preview" {
550 format!("lldb-{}-{}.tar.gz", self.lldb_release, target)
551 } else if component == "miri" || component == "miri-preview" {
552 format!("miri-{}-{}.tar.gz", self.miri_release, target)
554 format!("{}-{}-{}.tar.gz", component, self.rust_release, target)
558 fn cached_version(&self, component: &str) -> &Option<String> {
559 if component == "cargo" {
561 } else if component == "rls" || component == "rls-preview" {
563 } else if component == "clippy" || component == "clippy-preview" {
565 } else if component == "rustfmt" || component == "rustfmt-preview" {
566 &self.rustfmt_version
567 } else if component == "llvm-tools" || component == "llvm-tools-preview" {
568 &self.llvm_tools_version
569 } else if component == "lldb" || component == "lldb-preview" {
571 } else if component == "miri" || component == "miri-preview" {
578 fn cached_git_commit_hash(&self, component: &str) -> &Option<String> {
579 if component == "cargo" {
580 &self.cargo_git_commit_hash
581 } else if component == "rls" || component == "rls-preview" {
582 &self.rls_git_commit_hash
583 } else if component == "clippy" || component == "clippy-preview" {
584 &self.clippy_git_commit_hash
585 } else if component == "rustfmt" || component == "rustfmt-preview" {
586 &self.rustfmt_git_commit_hash
587 } else if component == "llvm-tools" || component == "llvm-tools-preview" {
588 &self.llvm_tools_git_commit_hash
589 } else if component == "lldb" || component == "lldb-preview" {
590 &self.lldb_git_commit_hash
591 } else if component == "miri" || component == "miri-preview" {
592 &self.miri_git_commit_hash
594 &self.rust_git_commit_hash
598 fn version(&self, component: &str, target: &str) -> Option<String> {
599 let mut cmd = Command::new("tar");
600 let filename = self.filename(component, target);
602 .arg(self.input.join(&filename))
603 .arg(format!("{}/version", filename.replace(".tar.gz", "")))
605 let output = t!(cmd.output());
606 if output.status.success() {
607 Some(String::from_utf8_lossy(&output.stdout).trim().to_string())
609 // Perhaps we didn't build this package.
614 fn git_commit_hash(&self, component: &str, target: &str) -> Option<String> {
615 let mut cmd = Command::new("tar");
616 let filename = self.filename(component, target);
618 .arg(self.input.join(&filename))
619 .arg(format!("{}/git-commit-hash", filename.replace(".tar.gz", "")))
621 let output = t!(cmd.output());
622 if output.status.success() {
623 Some(String::from_utf8_lossy(&output.stdout).trim().to_string())
629 fn hash(&self, path: &Path) -> String {
630 let sha = t!(Command::new("shasum")
631 .arg("-a").arg("256")
632 .arg(path.file_name().unwrap())
633 .current_dir(path.parent().unwrap())
635 assert!(sha.status.success());
637 let filename = path.file_name().unwrap().to_str().unwrap();
638 let sha256 = self.output.join(format!("{}.sha256", filename));
639 t!(fs::write(&sha256, &sha.stdout));
641 let stdout = String::from_utf8_lossy(&sha.stdout);
642 stdout.split_whitespace().next().unwrap().to_string()
645 fn sign(&self, path: &Path) {
646 if !self.should_sign {
650 let filename = path.file_name().unwrap().to_str().unwrap();
651 let asc = self.output.join(format!("{}.asc", filename));
652 println!("signing: {:?}", path);
653 let mut cmd = Command::new("gpg");
654 cmd.arg("--pinentry-mode=loopback")
658 .arg("--passphrase-fd").arg("0")
659 .arg("--personal-digest-preferences").arg("SHA512")
661 .arg("--output").arg(&asc)
662 .arg("--detach-sign").arg(path)
663 .stdin(Stdio::piped());
664 let mut child = t!(cmd.spawn());
665 t!(child.stdin.take().unwrap().write_all(self.gpg_passphrase.as_bytes()));
666 assert!(t!(child.wait()).success());
669 fn write_channel_files(&self, channel_name: &str, manifest: &Manifest) {
670 self.write(&toml::to_string(&manifest).unwrap(), channel_name, ".toml");
671 self.write(&manifest.date, channel_name, "-date.txt");
672 self.write(manifest.pkg["rust"].git_commit_hash.as_ref().unwrap(),
673 channel_name, "-git-commit-hash.txt");
676 fn write(&self, contents: &str, channel_name: &str, suffix: &str) {
677 let dst = self.output.join(format!("channel-rust-{}{}", channel_name, suffix));
678 t!(fs::write(&dst, contents));