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>
140 git_commit_hash: Option<String>,
141 target: BTreeMap<String, Target>,
153 hash: Option<String>,
154 xz_url: Option<String>,
155 xz_hash: Option<String>,
156 components: Option<Vec<Component>>,
157 extensions: Option<Vec<Component>>,
161 fn unavailable() -> Target {
181 ($e:expr) => (match $e {
183 Err(e) => panic!("{} failed with {}", stringify!($e), e),
188 rust_release: String,
189 cargo_release: String,
191 clippy_release: String,
192 rustfmt_release: String,
193 llvm_tools_release: String,
194 lldb_release: String,
195 miri_release: String,
199 gpg_passphrase: String,
200 digests: BTreeMap<String, String>,
204 rust_version: Option<String>,
205 cargo_version: Option<String>,
206 rls_version: Option<String>,
207 clippy_version: Option<String>,
208 rustfmt_version: Option<String>,
209 llvm_tools_version: Option<String>,
210 lldb_version: Option<String>,
211 miri_version: Option<String>,
213 rust_git_commit_hash: Option<String>,
214 cargo_git_commit_hash: Option<String>,
215 rls_git_commit_hash: Option<String>,
216 clippy_git_commit_hash: Option<String>,
217 rustfmt_git_commit_hash: Option<String>,
218 llvm_tools_git_commit_hash: Option<String>,
219 lldb_git_commit_hash: Option<String>,
220 miri_git_commit_hash: Option<String>,
226 // Avoid signing packages while manually testing
227 // Do NOT set this envvar in CI
228 let should_sign = env::var("BUILD_MANIFEST_DISABLE_SIGNING").is_err();
230 // Safety check to ensure signing is always enabled on CI
231 // The CI environment variable is set by both Travis and AppVeyor
232 if !should_sign && env::var("CI").is_ok() {
233 println!("The 'BUILD_MANIFEST_DISABLE_SIGNING' env var can't be enabled on CI.");
234 println!("If you're not running this on CI, unset the 'CI' env var.");
238 let mut args = env::args().skip(1);
239 let input = PathBuf::from(args.next().unwrap());
240 let output = PathBuf::from(args.next().unwrap());
241 let date = args.next().unwrap();
242 let rust_release = args.next().unwrap();
243 let s3_address = args.next().unwrap();
244 let cargo_release = args.next().unwrap();
245 let rls_release = args.next().unwrap();
246 let clippy_release = args.next().unwrap();
247 let miri_release = args.next().unwrap();
248 let rustfmt_release = args.next().unwrap();
249 let llvm_tools_release = args.next().unwrap();
250 let lldb_release = args.next().unwrap();
252 // Do not ask for a passphrase while manually testing
253 let mut passphrase = String::new();
255 t!(io::stdin().read_to_string(&mut passphrase));
270 gpg_passphrase: passphrase,
271 digests: BTreeMap::new(),
278 clippy_version: None,
279 rustfmt_version: None,
280 llvm_tools_version: None,
284 rust_git_commit_hash: None,
285 cargo_git_commit_hash: None,
286 rls_git_commit_hash: None,
287 clippy_git_commit_hash: None,
288 rustfmt_git_commit_hash: None,
289 llvm_tools_git_commit_hash: None,
290 lldb_git_commit_hash: None,
291 miri_git_commit_hash: None,
298 fn build(&mut self) {
299 self.rust_version = self.version("rust", "x86_64-unknown-linux-gnu");
300 self.cargo_version = self.version("cargo", "x86_64-unknown-linux-gnu");
301 self.rls_version = self.version("rls", "x86_64-unknown-linux-gnu");
302 self.clippy_version = self.version("clippy", "x86_64-unknown-linux-gnu");
303 self.rustfmt_version = self.version("rustfmt", "x86_64-unknown-linux-gnu");
304 self.llvm_tools_version = self.version("llvm-tools", "x86_64-unknown-linux-gnu");
305 // lldb is only built for macOS.
306 self.lldb_version = self.version("lldb", "x86_64-apple-darwin");
307 self.miri_version = self.version("miri", "x86_64-unknown-linux-gnu");
309 self.rust_git_commit_hash = self.git_commit_hash("rust", "x86_64-unknown-linux-gnu");
310 self.cargo_git_commit_hash = self.git_commit_hash("cargo", "x86_64-unknown-linux-gnu");
311 self.rls_git_commit_hash = self.git_commit_hash("rls", "x86_64-unknown-linux-gnu");
312 self.clippy_git_commit_hash = self.git_commit_hash("clippy", "x86_64-unknown-linux-gnu");
313 self.rustfmt_git_commit_hash = self.git_commit_hash("rustfmt", "x86_64-unknown-linux-gnu");
314 self.llvm_tools_git_commit_hash = self.git_commit_hash("llvm-tools",
315 "x86_64-unknown-linux-gnu");
316 self.lldb_git_commit_hash = self.git_commit_hash("lldb", "x86_64-unknown-linux-gnu");
317 self.miri_git_commit_hash = self.git_commit_hash("miri", "x86_64-unknown-linux-gnu");
319 self.digest_and_sign();
320 let manifest = self.build_manifest();
321 self.write_channel_files(&self.rust_release, &manifest);
323 if self.rust_release != "beta" && self.rust_release != "nightly" {
324 self.write_channel_files("stable", &manifest);
328 fn digest_and_sign(&mut self) {
329 for file in t!(self.input.read_dir()).map(|e| t!(e).path()) {
330 let filename = file.file_name().unwrap().to_str().unwrap();
331 let digest = self.hash(&file);
333 assert!(self.digests.insert(filename.to_string(), digest).is_none());
337 fn build_manifest(&mut self) -> Manifest {
338 let mut manifest = Manifest {
339 manifest_version: "2".to_string(),
340 date: self.date.to_string(),
341 pkg: BTreeMap::new(),
342 renames: BTreeMap::new(),
345 self.package("rustc", &mut manifest.pkg, HOSTS);
346 self.package("cargo", &mut manifest.pkg, HOSTS);
347 self.package("rust-mingw", &mut manifest.pkg, MINGW);
348 self.package("rust-std", &mut manifest.pkg, TARGETS);
349 self.package("rust-docs", &mut manifest.pkg, DOCS_TARGETS);
350 self.package("rust-src", &mut manifest.pkg, &["*"]);
351 self.package("rls-preview", &mut manifest.pkg, HOSTS);
352 self.package("clippy-preview", &mut manifest.pkg, HOSTS);
353 self.package("rustfmt-preview", &mut manifest.pkg, HOSTS);
354 self.package("rust-analysis", &mut manifest.pkg, TARGETS);
355 self.package("llvm-tools-preview", &mut manifest.pkg, TARGETS);
356 self.package("lldb-preview", &mut manifest.pkg, TARGETS);
358 manifest.renames.insert("rls".to_owned(), Rename { to: "rls-preview".to_owned() });
359 manifest.renames.insert("rustfmt".to_owned(), Rename { to: "rustfmt-preview".to_owned() });
360 manifest.renames.insert("clippy".to_owned(), Rename { to: "clippy-preview".to_owned() });
362 let mut pkg = Package {
363 version: self.cached_version("rust")
365 .expect("Couldn't find Rust version")
367 git_commit_hash: self.cached_git_commit_hash("rust").clone(),
368 target: BTreeMap::new(),
371 let filename = self.filename("rust", host);
372 let digest = match self.digests.remove(&filename) {
373 Some(digest) => digest,
375 pkg.target.insert(host.to_string(), Target::unavailable());
379 let xz_filename = filename.replace(".tar.gz", ".tar.xz");
380 let xz_digest = self.digests.remove(&xz_filename);
381 let mut components = Vec::new();
382 let mut extensions = Vec::new();
384 // rustc/rust-std/cargo/docs are all required, and so is rust-mingw
385 // if it's available for the target.
386 components.extend(vec![
387 Component { pkg: "rustc".to_string(), target: host.to_string() },
388 Component { pkg: "rust-std".to_string(), target: host.to_string() },
389 Component { pkg: "cargo".to_string(), target: host.to_string() },
390 Component { pkg: "rust-docs".to_string(), target: host.to_string() },
392 if host.contains("pc-windows-gnu") {
393 components.push(Component {
394 pkg: "rust-mingw".to_string(),
395 target: host.to_string(),
399 // Tools are always present in the manifest, but might be marked as unavailable if they
401 extensions.extend(vec![
402 Component { pkg: "clippy-preview".to_string(), target: host.to_string() },
403 Component { pkg: "rls-preview".to_string(), target: host.to_string() },
404 Component { pkg: "rustfmt-preview".to_string(), target: host.to_string() },
405 Component { pkg: "llvm-tools-preview".to_string(), target: host.to_string() },
406 Component { pkg: "lldb-preview".to_string(), target: host.to_string() },
407 Component { pkg: "rust-analysis".to_string(), target: host.to_string() },
410 for target in TARGETS {
412 extensions.push(Component {
413 pkg: "rust-std".to_string(),
414 target: target.to_string(),
418 extensions.push(Component {
419 pkg: "rust-src".to_string(),
420 target: "*".to_string(),
423 // If the components/extensions don't actually exist for this
424 // particular host/target combination then nix it entirely from our
427 let has_component = |c: &Component| {
431 let pkg = match manifest.pkg.get(&c.pkg) {
433 None => return false,
435 pkg.target.get(&c.target).is_some()
437 extensions.retain(&has_component);
438 components.retain(&has_component);
441 pkg.target.insert(host.to_string(), Target {
443 url: Some(self.url(&filename)),
445 xz_url: xz_digest.as_ref().map(|_| self.url(&xz_filename)),
447 components: Some(components),
448 extensions: Some(extensions),
451 manifest.pkg.insert("rust".to_string(), pkg);
456 fn package(&mut self,
458 dst: &mut BTreeMap<String, Package>,
460 let (version, is_present) = match *self.cached_version(pkgname) {
461 Some(ref version) => (version.clone(), true),
462 None => (String::new(), false),
465 let targets = targets.iter().map(|name| {
467 let filename = self.filename(pkgname, name);
468 let digest = match self.digests.remove(&filename) {
469 Some(digest) => digest,
470 None => return (name.to_string(), Target::unavailable()),
472 let xz_filename = filename.replace(".tar.gz", ".tar.xz");
473 let xz_digest = self.digests.remove(&xz_filename);
475 (name.to_string(), Target {
477 url: Some(self.url(&filename)),
479 xz_url: xz_digest.as_ref().map(|_| self.url(&xz_filename)),
485 // If the component is not present for this build add it anyway but mark it as
486 // unavailable -- this way rustup won't allow upgrades without --force
487 (name.to_string(), Target {
499 dst.insert(pkgname.to_string(), Package {
501 git_commit_hash: self.cached_git_commit_hash(pkgname).clone(),
506 fn url(&self, filename: &str) -> String {
513 fn filename(&self, component: &str, target: &str) -> String {
514 if component == "rust-src" {
515 format!("rust-src-{}.tar.gz", self.rust_release)
516 } else if component == "cargo" {
517 format!("cargo-{}-{}.tar.gz", self.cargo_release, target)
518 } else if component == "rls" || component == "rls-preview" {
519 format!("rls-{}-{}.tar.gz", self.rls_release, target)
520 } else if component == "clippy" || component == "clippy-preview" {
521 format!("clippy-{}-{}.tar.gz", self.clippy_release, target)
522 } else if component == "rustfmt" || component == "rustfmt-preview" {
523 format!("rustfmt-{}-{}.tar.gz", self.rustfmt_release, target)
524 } else if component == "llvm-tools" || component == "llvm-tools-preview" {
525 format!("llvm-tools-{}-{}.tar.gz", self.llvm_tools_release, target)
526 } else if component == "lldb" || component == "lldb-preview" {
527 format!("lldb-{}-{}.tar.gz", self.lldb_release, target)
528 } else if component == "miri" || component == "miri-preview" {
529 format!("miri-{}-{}.tar.gz", self.miri_release, target)
531 format!("{}-{}-{}.tar.gz", component, self.rust_release, target)
535 fn cached_version(&self, component: &str) -> &Option<String> {
536 if component == "cargo" {
538 } else if component == "rls" || component == "rls-preview" {
540 } else if component == "clippy" || component == "clippy-preview" {
542 } else if component == "rustfmt" || component == "rustfmt-preview" {
543 &self.rustfmt_version
544 } else if component == "llvm-tools" || component == "llvm-tools-preview" {
545 &self.llvm_tools_version
546 } else if component == "lldb" || component == "lldb-preview" {
548 } else if component == "miri" || component == "miri-preview" {
555 fn cached_git_commit_hash(&self, component: &str) -> &Option<String> {
556 if component == "cargo" {
557 &self.cargo_git_commit_hash
558 } else if component == "rls" || component == "rls-preview" {
559 &self.rls_git_commit_hash
560 } else if component == "clippy" || component == "clippy-preview" {
561 &self.clippy_git_commit_hash
562 } else if component == "rustfmt" || component == "rustfmt-preview" {
563 &self.rustfmt_git_commit_hash
564 } else if component == "llvm-tools" || component == "llvm-tools-preview" {
565 &self.llvm_tools_git_commit_hash
566 } else if component == "lldb" || component == "lldb-preview" {
567 &self.lldb_git_commit_hash
568 } else if component == "miri" || component == "miri-preview" {
569 &self.miri_git_commit_hash
571 &self.rust_git_commit_hash
575 fn version(&self, component: &str, target: &str) -> Option<String> {
576 let mut cmd = Command::new("tar");
577 let filename = self.filename(component, target);
579 .arg(self.input.join(&filename))
580 .arg(format!("{}/version", filename.replace(".tar.gz", "")))
582 let output = t!(cmd.output());
583 if output.status.success() {
584 Some(String::from_utf8_lossy(&output.stdout).trim().to_string())
586 // Perhaps we didn't build this package.
591 fn git_commit_hash(&self, component: &str, target: &str) -> Option<String> {
592 let mut cmd = Command::new("tar");
593 let filename = self.filename(component, target);
595 .arg(self.input.join(&filename))
596 .arg(format!("{}/git-commit-hash", filename.replace(".tar.gz", "")))
598 let output = t!(cmd.output());
599 if output.status.success() {
600 Some(String::from_utf8_lossy(&output.stdout).trim().to_string())
606 fn hash(&self, path: &Path) -> String {
607 let sha = t!(Command::new("shasum")
608 .arg("-a").arg("256")
609 .arg(path.file_name().unwrap())
610 .current_dir(path.parent().unwrap())
612 assert!(sha.status.success());
614 let filename = path.file_name().unwrap().to_str().unwrap();
615 let sha256 = self.output.join(format!("{}.sha256", filename));
616 t!(fs::write(&sha256, &sha.stdout));
618 let stdout = String::from_utf8_lossy(&sha.stdout);
619 stdout.split_whitespace().next().unwrap().to_string()
622 fn sign(&self, path: &Path) {
623 if !self.should_sign {
627 let filename = path.file_name().unwrap().to_str().unwrap();
628 let asc = self.output.join(format!("{}.asc", filename));
629 println!("signing: {:?}", path);
630 let mut cmd = Command::new("gpg");
631 cmd.arg("--pinentry-mode=loopback")
635 .arg("--passphrase-fd").arg("0")
636 .arg("--personal-digest-preferences").arg("SHA512")
638 .arg("--output").arg(&asc)
639 .arg("--detach-sign").arg(path)
640 .stdin(Stdio::piped());
641 let mut child = t!(cmd.spawn());
642 t!(child.stdin.take().unwrap().write_all(self.gpg_passphrase.as_bytes()));
643 assert!(t!(child.wait()).success());
646 fn write_channel_files(&self, channel_name: &str, manifest: &Manifest) {
647 self.write(&toml::to_string(&manifest).unwrap(), channel_name, ".toml");
648 self.write(&manifest.date, channel_name, "-date.txt");
649 self.write(manifest.pkg["rust"].git_commit_hash.as_ref().unwrap(),
650 channel_name, "-git-commit-hash.txt");
653 fn write(&self, contents: &str, channel_name: &str, suffix: &str) {
654 let dst = self.output.join(format!("channel-rust-{}{}", channel_name, suffix));
655 t!(fs::write(&dst, contents));