1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! Implementation of the various distribution aspects of the compiler.
13 //! This module is responsible for creating tarballs of the standard library,
14 //! compiler, and documentation. This ends up being what we distribute to
17 //! No tarball is actually created literally in this file, but rather we shell
18 //! out to `rust-installer` still. This may one day be replaced with bits and
19 //! pieces of `rustup.rs`!
22 use std::fs::{self, File};
23 use std::io::{Read, Write};
24 use std::path::{PathBuf, Path};
25 use std::process::{Command, Stdio};
27 use build_helper::output;
29 #[cfg(not(target_os = "solaris"))]
30 const SH_CMD: &'static str = "sh";
31 // On Solaris, sh is the historical bourne shell, not a POSIX shell, or bash.
32 #[cfg(target_os = "solaris")]
33 const SH_CMD: &'static str = "bash";
35 use {Build, Compiler, Mode};
37 use util::{cp_r, libdir, is_dylib, cp_filtered, copy, exe};
39 fn pkgname(build: &Build, component: &str) -> String {
40 if component == "cargo" {
41 format!("{}-{}", component, build.cargo_package_vers())
42 } else if component == "rls" {
43 format!("{}-{}", component, build.package_vers(&build.release_num("rls")))
45 assert!(component.starts_with("rust"));
46 format!("{}-{}", component, build.rust_package_vers())
50 fn distdir(build: &Build) -> PathBuf {
51 build.out.join("dist")
54 pub fn tmpdir(build: &Build) -> PathBuf {
55 build.out.join("tmp/dist")
58 /// Builds the `rust-docs` installer component.
60 /// Slurps up documentation from the `stage`'s `host`.
61 pub fn docs(build: &Build, stage: u32, host: &str) {
62 println!("Dist docs stage{} ({})", stage, host);
63 if !build.config.docs {
64 println!("\tskipping - docs disabled");
68 let name = pkgname(build, "rust-docs");
69 let image = tmpdir(build).join(format!("{}-{}-image", name, host));
70 let _ = fs::remove_dir_all(&image);
72 let dst = image.join("share/doc/rust/html");
73 t!(fs::create_dir_all(&dst));
74 let src = build.out.join(host).join("doc");
77 let mut cmd = Command::new(SH_CMD);
78 cmd.arg(sanitize_sh(&build.src.join("src/rust-installer/gen-installer.sh")))
79 .arg("--product-name=Rust-Documentation")
80 .arg("--rel-manifest-dir=rustlib")
81 .arg("--success-message=Rust-documentation-is-installed.")
82 .arg(format!("--image-dir={}", sanitize_sh(&image)))
83 .arg(format!("--work-dir={}", sanitize_sh(&tmpdir(build))))
84 .arg(format!("--output-dir={}", sanitize_sh(&distdir(build))))
85 .arg(format!("--package-name={}-{}", name, host))
86 .arg("--component-name=rust-docs")
87 .arg("--legacy-manifest-dirs=rustlib,cargo")
88 .arg("--bulk-dirs=share/doc/rust/html");
90 t!(fs::remove_dir_all(&image));
92 // As part of this step, *also* copy the docs directory to a directory which
93 // buildbot typically uploads.
94 if host == build.config.build {
95 let dst = distdir(build).join("doc").join(build.rust_package_vers());
96 t!(fs::create_dir_all(&dst));
101 /// Build the `rust-mingw` installer component.
103 /// This contains all the bits and pieces to run the MinGW Windows targets
104 /// without any extra installed software (e.g. we bundle gcc, libraries, etc).
105 /// Currently just shells out to a python script, but that should be rewritten
107 pub fn mingw(build: &Build, host: &str) {
108 println!("Dist mingw ({})", host);
109 let name = pkgname(build, "rust-mingw");
110 let image = tmpdir(build).join(format!("{}-{}-image", name, host));
111 let _ = fs::remove_dir_all(&image);
112 t!(fs::create_dir_all(&image));
114 // The first argument to the script is a "temporary directory" which is just
115 // thrown away (this contains the runtime DLLs included in the rustc package
116 // above) and the second argument is where to place all the MinGW components
117 // (which is what we want).
119 // FIXME: this script should be rewritten into Rust
120 let mut cmd = Command::new(build.python());
121 cmd.arg(build.src.join("src/etc/make-win-dist.py"))
127 let mut cmd = Command::new(SH_CMD);
128 cmd.arg(sanitize_sh(&build.src.join("src/rust-installer/gen-installer.sh")))
129 .arg("--product-name=Rust-MinGW")
130 .arg("--rel-manifest-dir=rustlib")
131 .arg("--success-message=Rust-MinGW-is-installed.")
132 .arg(format!("--image-dir={}", sanitize_sh(&image)))
133 .arg(format!("--work-dir={}", sanitize_sh(&tmpdir(build))))
134 .arg(format!("--output-dir={}", sanitize_sh(&distdir(build))))
135 .arg(format!("--package-name={}-{}", name, host))
136 .arg("--component-name=rust-mingw")
137 .arg("--legacy-manifest-dirs=rustlib,cargo");
139 t!(fs::remove_dir_all(&image));
142 /// Creates the `rustc` installer component.
143 pub fn rustc(build: &Build, stage: u32, host: &str) {
144 println!("Dist rustc stage{} ({})", stage, host);
145 let name = pkgname(build, "rustc");
146 let image = tmpdir(build).join(format!("{}-{}-image", name, host));
147 let _ = fs::remove_dir_all(&image);
148 let overlay = tmpdir(build).join(format!("{}-{}-overlay", name, host));
149 let _ = fs::remove_dir_all(&overlay);
151 // Prepare the rustc "image", what will actually end up getting installed
152 prepare_image(build, stage, host, &image);
154 // Prepare the overlay which is part of the tarball but won't actually be
156 let cp = |file: &str| {
157 install(&build.src.join(file), &overlay, 0o644);
160 cp("LICENSE-APACHE");
163 // tiny morsel of metadata is used by rust-packaging
164 let version = build.rust_version();
165 t!(t!(File::create(overlay.join("version"))).write_all(version.as_bytes()));
167 // On MinGW we've got a few runtime DLL dependencies that we need to
168 // include. The first argument to this script is where to put these DLLs
169 // (the image we're creating), and the second argument is a junk directory
170 // to ignore all other MinGW stuff the script creates.
172 // On 32-bit MinGW we're always including a DLL which needs some extra
173 // licenses to distribute. On 64-bit MinGW we don't actually distribute
174 // anything requiring us to distribute a license, but it's likely the
175 // install will *also* include the rust-mingw package, which also needs
176 // licenses, so to be safe we just include it here in all MinGW packages.
178 // FIXME: this script should be rewritten into Rust
179 if host.contains("pc-windows-gnu") {
180 let mut cmd = Command::new(build.python());
181 cmd.arg(build.src.join("src/etc/make-win-dist.py"))
187 let dst = image.join("share/doc");
188 t!(fs::create_dir_all(&dst));
189 cp_r(&build.src.join("src/etc/third-party"), &dst);
192 // Finally, wrap everything up in a nice tarball!
193 let mut cmd = Command::new(SH_CMD);
194 cmd.arg(sanitize_sh(&build.src.join("src/rust-installer/gen-installer.sh")))
195 .arg("--product-name=Rust")
196 .arg("--rel-manifest-dir=rustlib")
197 .arg("--success-message=Rust-is-ready-to-roll.")
198 .arg(format!("--image-dir={}", sanitize_sh(&image)))
199 .arg(format!("--work-dir={}", sanitize_sh(&tmpdir(build))))
200 .arg(format!("--output-dir={}", sanitize_sh(&distdir(build))))
201 .arg(format!("--non-installed-overlay={}", sanitize_sh(&overlay)))
202 .arg(format!("--package-name={}-{}", name, host))
203 .arg("--component-name=rustc")
204 .arg("--legacy-manifest-dirs=rustlib,cargo");
206 t!(fs::remove_dir_all(&image));
207 t!(fs::remove_dir_all(&overlay));
209 fn prepare_image(build: &Build, stage: u32, host: &str, image: &Path) {
210 let src = build.sysroot(&Compiler::new(stage, host));
211 let libdir = libdir(host);
213 // Copy rustc/rustdoc binaries
214 t!(fs::create_dir_all(image.join("bin")));
215 cp_r(&src.join("bin"), &image.join("bin"));
217 // Copy runtime DLLs needed by the compiler
219 for entry in t!(src.join(libdir).read_dir()).map(|e| t!(e)) {
220 let name = entry.file_name();
221 if let Some(s) = name.to_str() {
223 install(&entry.path(), &image.join(libdir), 0o644);
230 t!(fs::create_dir_all(image.join("share/man/man1")));
231 cp_r(&build.src.join("man"), &image.join("share/man/man1"));
234 debugger_scripts(build, &image, host);
237 let cp = |file: &str| {
238 install(&build.src.join(file), &image.join("share/doc/rust"), 0o644);
241 cp("LICENSE-APACHE");
247 /// Copies debugger scripts for `host` into the `sysroot` specified.
248 pub fn debugger_scripts(build: &Build,
251 let cp_debugger_script = |file: &str| {
252 let dst = sysroot.join("lib/rustlib/etc");
253 t!(fs::create_dir_all(&dst));
254 install(&build.src.join("src/etc/").join(file), &dst, 0o644);
256 if host.contains("windows-msvc") {
257 // no debugger scripts
259 cp_debugger_script("debugger_pretty_printers_common.py");
261 // gdb debugger scripts
262 install(&build.src.join("src/etc/rust-gdb"), &sysroot.join("bin"),
265 cp_debugger_script("gdb_load_rust_pretty_printers.py");
266 cp_debugger_script("gdb_rust_pretty_printing.py");
268 // lldb debugger scripts
269 install(&build.src.join("src/etc/rust-lldb"), &sysroot.join("bin"),
272 cp_debugger_script("lldb_rust_formatters.py");
276 /// Creates the `rust-std` installer component as compiled by `compiler` for the
278 pub fn std(build: &Build, compiler: &Compiler, target: &str) {
279 println!("Dist std stage{} ({} -> {})", compiler.stage, compiler.host,
282 // The only true set of target libraries came from the build triple, so
283 // let's reduce redundant work by only producing archives from that host.
284 if compiler.host != build.config.build {
285 println!("\tskipping, not a build host");
289 let name = pkgname(build, "rust-std");
290 let image = tmpdir(build).join(format!("{}-{}-image", name, target));
291 let _ = fs::remove_dir_all(&image);
293 let dst = image.join("lib/rustlib").join(target);
294 t!(fs::create_dir_all(&dst));
295 let src = build.sysroot(compiler).join("lib/rustlib");
296 cp_r(&src.join(target), &dst);
298 let mut cmd = Command::new(SH_CMD);
299 cmd.arg(sanitize_sh(&build.src.join("src/rust-installer/gen-installer.sh")))
300 .arg("--product-name=Rust")
301 .arg("--rel-manifest-dir=rustlib")
302 .arg("--success-message=std-is-standing-at-the-ready.")
303 .arg(format!("--image-dir={}", sanitize_sh(&image)))
304 .arg(format!("--work-dir={}", sanitize_sh(&tmpdir(build))))
305 .arg(format!("--output-dir={}", sanitize_sh(&distdir(build))))
306 .arg(format!("--package-name={}-{}", name, target))
307 .arg(format!("--component-name=rust-std-{}", target))
308 .arg("--legacy-manifest-dirs=rustlib,cargo");
310 t!(fs::remove_dir_all(&image));
313 pub fn rust_src_location(build: &Build) -> PathBuf {
314 let plain_name = format!("rustc-{}-src", build.rust_package_vers());
315 distdir(build).join(&format!("{}.tar.gz", plain_name))
318 /// Creates a tarball of save-analysis metadata, if available.
319 pub fn analysis(build: &Build, compiler: &Compiler, target: &str) {
320 assert!(build.config.extended);
321 println!("Dist analysis");
323 if compiler.host != build.config.build {
324 println!("\tskipping, not a build host");
328 // Package save-analysis from stage1 if not doing a full bootstrap, as the
329 // stage2 artifacts is simply copied from stage1 in that case.
330 let compiler = if build.force_use_stage1(compiler, target) {
331 Compiler::new(1, compiler.host)
336 let name = pkgname(build, "rust-analysis");
337 let image = tmpdir(build).join(format!("{}-{}-image", name, target));
339 let src = build.stage_out(&compiler, Mode::Libstd).join(target).join("release").join("deps");
341 let image_src = src.join("save-analysis");
342 let dst = image.join("lib/rustlib").join(target).join("analysis");
343 t!(fs::create_dir_all(&dst));
344 println!("image_src: {:?}, dst: {:?}", image_src, dst);
345 cp_r(&image_src, &dst);
347 let mut cmd = Command::new(SH_CMD);
348 cmd.arg(sanitize_sh(&build.src.join("src/rust-installer/gen-installer.sh")))
349 .arg("--product-name=Rust")
350 .arg("--rel-manifest-dir=rustlib")
351 .arg("--success-message=save-analysis-saved.")
352 .arg(format!("--image-dir={}", sanitize_sh(&image)))
353 .arg(format!("--work-dir={}", sanitize_sh(&tmpdir(build))))
354 .arg(format!("--output-dir={}", sanitize_sh(&distdir(build))))
355 .arg(format!("--package-name={}-{}", name, target))
356 .arg(format!("--component-name=rust-analysis-{}", target))
357 .arg("--legacy-manifest-dirs=rustlib,cargo");
359 t!(fs::remove_dir_all(&image));
362 const CARGO_VENDOR_VERSION: &'static str = "0.1.4";
364 /// Creates the `rust-src` installer component and the plain source tarball
365 pub fn rust_src(build: &Build) {
366 if !build.config.rust_dist_src {
370 println!("Dist src");
372 let name = pkgname(build, "rust-src");
373 let image = tmpdir(build).join(format!("{}-image", name));
374 let _ = fs::remove_dir_all(&image);
376 let dst = image.join("lib/rustlib/src");
377 let dst_src = dst.join("rust");
378 t!(fs::create_dir_all(&dst_src));
380 // This is the set of root paths which will become part of the source package
398 let filter_fn = move |path: &Path| {
399 let spath = match path.to_str() {
401 None => return false,
403 if spath.ends_with("~") || spath.ends_with(".pyc") {
406 if spath.contains("llvm/test") || spath.contains("llvm\\test") {
407 if spath.ends_with(".ll") ||
408 spath.ends_with(".td") ||
409 spath.ends_with(".s") {
415 "CVS", "RCS", "SCCS", ".git", ".gitignore", ".gitmodules",
416 ".gitattributes", ".cvsignore", ".svn", ".arch-ids", "{arch}",
417 "=RELEASE-ID", "=meta-update", "=update", ".bzr", ".bzrignore",
418 ".bzrtags", ".hg", ".hgignore", ".hgrags", "_darcs",
421 .map(|s| s.to_str().unwrap())
422 .any(|s| excludes.contains(&s))
425 // Copy the directories using our filter
426 for item in &src_dirs {
427 let dst = &dst_src.join(item);
428 t!(fs::create_dir(dst));
429 cp_filtered(&build.src.join(item), dst, &filter_fn);
431 // Copy the files normally
432 for item in &src_files {
433 copy(&build.src.join(item), &dst_src.join(item));
436 // If we're building from git sources, we need to vendor a complete distribution.
437 if build.src_is_git {
438 // Get cargo-vendor installed, if it isn't already.
439 let mut has_cargo_vendor = false;
440 let mut cmd = Command::new(&build.cargo);
441 for line in output(cmd.arg("install").arg("--list")).lines() {
442 has_cargo_vendor |= line.starts_with("cargo-vendor ");
444 if !has_cargo_vendor {
445 let mut cmd = Command::new(&build.cargo);
449 .arg("--vers").arg(CARGO_VENDOR_VERSION)
451 .env("RUSTC", &build.rustc);
455 // Vendor all Cargo dependencies
456 let mut cmd = Command::new(&build.cargo);
458 .current_dir(&dst_src.join("src"));
462 // Create source tarball in rust-installer format
463 let mut cmd = Command::new(SH_CMD);
464 cmd.arg(sanitize_sh(&build.src.join("src/rust-installer/gen-installer.sh")))
465 .arg("--product-name=Rust")
466 .arg("--rel-manifest-dir=rustlib")
467 .arg("--success-message=Awesome-Source.")
468 .arg(format!("--image-dir={}", sanitize_sh(&image)))
469 .arg(format!("--work-dir={}", sanitize_sh(&tmpdir(build))))
470 .arg(format!("--output-dir={}", sanitize_sh(&distdir(build))))
471 .arg(format!("--package-name={}", name))
472 .arg("--component-name=rust-src")
473 .arg("--legacy-manifest-dirs=rustlib,cargo");
476 // Rename directory, so that root folder of tarball has the correct name
477 let plain_name = format!("rustc-{}-src", build.rust_package_vers());
478 let plain_dst_src = tmpdir(build).join(&plain_name);
479 let _ = fs::remove_dir_all(&plain_dst_src);
480 t!(fs::create_dir_all(&plain_dst_src));
481 cp_r(&dst_src, &plain_dst_src);
483 // Create the version file
484 write_file(&plain_dst_src.join("version"), build.rust_version().as_bytes());
486 // Create plain source tarball
487 let mut cmd = Command::new("tar");
488 cmd.arg("-czf").arg(sanitize_sh(&rust_src_location(build)))
490 .current_dir(tmpdir(build));
493 t!(fs::remove_dir_all(&image));
494 t!(fs::remove_dir_all(&plain_dst_src));
497 fn install(src: &Path, dstdir: &Path, perms: u32) {
498 let dst = dstdir.join(src.file_name().unwrap());
499 t!(fs::create_dir_all(dstdir));
500 t!(fs::copy(src, &dst));
505 fn chmod(path: &Path, perms: u32) {
506 use std::os::unix::fs::*;
507 t!(fs::set_permissions(path, fs::Permissions::from_mode(perms)));
510 fn chmod(_path: &Path, _perms: u32) {}
512 // We have to run a few shell scripts, which choke quite a bit on both `\`
513 // characters and on `C:\` paths, so normalize both of them away.
514 pub fn sanitize_sh(path: &Path) -> String {
515 let path = path.to_str().unwrap().replace("\\", "/");
516 return change_drive(&path).unwrap_or(path);
518 fn change_drive(s: &str) -> Option<String> {
519 let mut ch = s.chars();
520 let drive = ch.next().unwrap_or('C');
521 if ch.next() != Some(':') {
524 if ch.next() != Some('/') {
527 Some(format!("/{}/{}", drive, &s[drive.len_utf8() + 2..]))
531 fn write_file(path: &Path, data: &[u8]) {
532 let mut vf = t!(fs::File::create(path));
533 t!(vf.write_all(data));
536 pub fn cargo(build: &Build, stage: u32, target: &str) {
537 println!("Dist cargo stage{} ({})", stage, target);
538 let compiler = Compiler::new(stage, &build.config.build);
540 let src = build.src.join("cargo");
541 let etc = src.join("src/etc");
542 let release_num = build.release_num("cargo");
543 let name = pkgname(build, "cargo");
544 let version = build.cargo_info.version(build, &release_num);
546 let tmp = tmpdir(build);
547 let image = tmp.join("cargo-image");
548 drop(fs::remove_dir_all(&image));
549 t!(fs::create_dir_all(&image));
551 // Prepare the image directory
552 t!(fs::create_dir_all(image.join("share/zsh/site-functions")));
553 t!(fs::create_dir_all(image.join("etc/bash_completions.d")));
554 let cargo = build.cargo_out(&compiler, Mode::Tool, target)
555 .join(exe("cargo", target));
556 install(&cargo, &image.join("bin"), 0o755);
557 for man in t!(etc.join("man").read_dir()) {
559 install(&man.path(), &image.join("share/man/man1"), 0o644);
561 install(&etc.join("_cargo"), &image.join("share/zsh/site-functions"), 0o644);
562 copy(&etc.join("cargo.bashcomp.sh"),
563 &image.join("etc/bash_completions.d/cargo"));
564 let doc = image.join("share/doc/cargo");
565 install(&src.join("README.md"), &doc, 0o644);
566 install(&src.join("LICENSE-MIT"), &doc, 0o644);
567 install(&src.join("LICENSE-APACHE"), &doc, 0o644);
568 install(&src.join("LICENSE-THIRD-PARTY"), &doc, 0o644);
570 // Prepare the overlay
571 let overlay = tmp.join("cargo-overlay");
572 drop(fs::remove_dir_all(&overlay));
573 t!(fs::create_dir_all(&overlay));
574 install(&src.join("README.md"), &overlay, 0o644);
575 install(&src.join("LICENSE-MIT"), &overlay, 0o644);
576 install(&src.join("LICENSE-APACHE"), &overlay, 0o644);
577 install(&src.join("LICENSE-THIRD-PARTY"), &overlay, 0o644);
578 t!(t!(File::create(overlay.join("version"))).write_all(version.as_bytes()));
580 // Generate the installer tarball
581 let mut cmd = Command::new("sh");
582 cmd.arg(sanitize_sh(&build.src.join("src/rust-installer/gen-installer.sh")))
583 .arg("--product-name=Rust")
584 .arg("--rel-manifest-dir=rustlib")
585 .arg("--success-message=Rust-is-ready-to-roll.")
586 .arg(format!("--image-dir={}", sanitize_sh(&image)))
587 .arg(format!("--work-dir={}", sanitize_sh(&tmpdir(build))))
588 .arg(format!("--output-dir={}", sanitize_sh(&distdir(build))))
589 .arg(format!("--non-installed-overlay={}", sanitize_sh(&overlay)))
590 .arg(format!("--package-name={}-{}", name, target))
591 .arg("--component-name=cargo")
592 .arg("--legacy-manifest-dirs=rustlib,cargo");
596 pub fn rls(build: &Build, stage: u32, target: &str) {
597 assert!(build.config.extended);
598 println!("Dist RLS stage{} ({})", stage, target);
599 let compiler = Compiler::new(stage, &build.config.build);
601 let src = build.src.join("rls");
602 let release_num = build.release_num("rls");
603 let name = pkgname(build, "rls");
604 let version = build.rls_info.version(build, &release_num);
606 let tmp = tmpdir(build);
607 let image = tmp.join("rls-image");
608 drop(fs::remove_dir_all(&image));
609 t!(fs::create_dir_all(&image));
611 // Prepare the image directory
612 let rls = build.cargo_out(&compiler, Mode::Tool, target)
613 .join(exe("rls", target));
614 install(&rls, &image.join("bin"), 0o755);
615 let doc = image.join("share/doc/rls");
616 install(&src.join("README.md"), &doc, 0o644);
617 install(&src.join("LICENSE-MIT"), &doc, 0o644);
618 install(&src.join("LICENSE-APACHE"), &doc, 0o644);
620 // Prepare the overlay
621 let overlay = tmp.join("rls-overlay");
622 drop(fs::remove_dir_all(&overlay));
623 t!(fs::create_dir_all(&overlay));
624 install(&src.join("README.md"), &overlay, 0o644);
625 install(&src.join("LICENSE-MIT"), &overlay, 0o644);
626 install(&src.join("LICENSE-APACHE"), &overlay, 0o644);
627 t!(t!(File::create(overlay.join("version"))).write_all(version.as_bytes()));
629 // Generate the installer tarball
630 let mut cmd = Command::new("sh");
631 cmd.arg(sanitize_sh(&build.src.join("src/rust-installer/gen-installer.sh")))
632 .arg("--product-name=Rust")
633 .arg("--rel-manifest-dir=rustlib")
634 .arg("--success-message=RLS-ready-to-serve.")
635 .arg(format!("--image-dir={}", sanitize_sh(&image)))
636 .arg(format!("--work-dir={}", sanitize_sh(&tmpdir(build))))
637 .arg(format!("--output-dir={}", sanitize_sh(&distdir(build))))
638 .arg(format!("--non-installed-overlay={}", sanitize_sh(&overlay)))
639 .arg(format!("--package-name={}-{}", name, target))
640 .arg("--component-name=rls")
641 .arg("--legacy-manifest-dirs=rustlib,cargo");
645 /// Creates a combined installer for the specified target in the provided stage.
646 pub fn extended(build: &Build, stage: u32, target: &str) {
647 println!("Dist extended stage{} ({})", stage, target);
649 let dist = distdir(build);
650 let rustc_installer = dist.join(format!("{}-{}.tar.gz",
651 pkgname(build, "rustc"),
653 let cargo_installer = dist.join(format!("{}-{}.tar.gz",
654 pkgname(build, "cargo"),
656 let rls_installer = dist.join(format!("{}-{}.tar.gz",
657 pkgname(build, "rls"),
659 let analysis_installer = dist.join(format!("{}-{}.tar.gz",
660 pkgname(build, "rust-analysis"),
662 let docs_installer = dist.join(format!("{}-{}.tar.gz",
663 pkgname(build, "rust-docs"),
665 let mingw_installer = dist.join(format!("{}-{}.tar.gz",
666 pkgname(build, "rust-mingw"),
668 let std_installer = dist.join(format!("{}-{}.tar.gz",
669 pkgname(build, "rust-std"),
672 let tmp = tmpdir(build);
673 let overlay = tmp.join("extended-overlay");
674 let etc = build.src.join("src/etc/installer");
675 let work = tmp.join("work");
677 let _ = fs::remove_dir_all(&overlay);
678 install(&build.src.join("COPYRIGHT"), &overlay, 0o644);
679 install(&build.src.join("LICENSE-APACHE"), &overlay, 0o644);
680 install(&build.src.join("LICENSE-MIT"), &overlay, 0o644);
681 let version = build.rust_version();
682 t!(t!(File::create(overlay.join("version"))).write_all(version.as_bytes()));
683 install(&etc.join("README.md"), &overlay, 0o644);
685 // When rust-std package split from rustc, we needed to ensure that during
686 // upgrades rustc was upgraded before rust-std. To avoid rustc clobbering
687 // the std files during uninstall. To do this ensure that rustc comes
688 // before rust-std in the list below.
689 let mut input_tarballs = format!("{},{},{},{},{},{}",
690 sanitize_sh(&rustc_installer),
691 sanitize_sh(&cargo_installer),
692 sanitize_sh(&rls_installer),
693 sanitize_sh(&analysis_installer),
694 sanitize_sh(&docs_installer),
695 sanitize_sh(&std_installer));
696 if target.contains("pc-windows-gnu") {
697 input_tarballs.push_str(",");
698 input_tarballs.push_str(&sanitize_sh(&mingw_installer));
701 let mut cmd = Command::new(SH_CMD);
702 cmd.arg(sanitize_sh(&build.src.join("src/rust-installer/combine-installers.sh")))
703 .arg("--product-name=Rust")
704 .arg("--rel-manifest-dir=rustlib")
705 .arg("--success-message=Rust-is-ready-to-roll.")
706 .arg(format!("--work-dir={}", sanitize_sh(&work)))
707 .arg(format!("--output-dir={}", sanitize_sh(&distdir(build))))
708 .arg(format!("--package-name={}-{}", pkgname(build, "rust"), target))
709 .arg("--legacy-manifest-dirs=rustlib,cargo")
710 .arg(format!("--input-tarballs={}", input_tarballs))
711 .arg(format!("--non-installed-overlay={}", sanitize_sh(&overlay)));
714 let mut license = String::new();
715 t!(t!(File::open(build.src.join("COPYRIGHT"))).read_to_string(&mut license));
716 license.push_str("\n");
717 t!(t!(File::open(build.src.join("LICENSE-APACHE"))).read_to_string(&mut license));
718 license.push_str("\n");
719 t!(t!(File::open(build.src.join("LICENSE-MIT"))).read_to_string(&mut license));
721 let rtf = r"{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 Arial;}}\nowwrap\fs18";
722 let mut rtf = rtf.to_string();
724 for line in license.lines() {
726 rtf.push_str("\\line ");
730 if target.contains("apple-darwin") {
731 let pkg = tmp.join("pkg");
732 let _ = fs::remove_dir_all(&pkg);
733 t!(fs::create_dir_all(pkg.join("rustc")));
734 t!(fs::create_dir_all(pkg.join("cargo")));
735 t!(fs::create_dir_all(pkg.join("rust-docs")));
736 t!(fs::create_dir_all(pkg.join("rust-std")));
738 cp_r(&work.join(&format!("{}-{}", pkgname(build, "rustc"), target)),
740 cp_r(&work.join(&format!("{}-{}", pkgname(build, "cargo"), target)),
742 cp_r(&work.join(&format!("{}-{}", pkgname(build, "rust-docs"), target)),
743 &pkg.join("rust-docs"));
744 cp_r(&work.join(&format!("{}-{}", pkgname(build, "rust-std"), target)),
745 &pkg.join("rust-std"));
747 install(&etc.join("pkg/postinstall"), &pkg.join("rustc"), 0o755);
748 install(&etc.join("pkg/postinstall"), &pkg.join("cargo"), 0o755);
749 install(&etc.join("pkg/postinstall"), &pkg.join("rust-docs"), 0o755);
750 install(&etc.join("pkg/postinstall"), &pkg.join("rust-std"), 0o755);
752 let pkgbuild = |component: &str| {
753 let mut cmd = Command::new("pkgbuild");
754 cmd.arg("--identifier").arg(format!("org.rust-lang.{}", component))
755 .arg("--scripts").arg(pkg.join(component))
757 .arg(pkg.join(component).with_extension("pkg"));
762 pkgbuild("rust-docs");
763 pkgbuild("rust-std");
765 // create an 'uninstall' package
766 install(&etc.join("pkg/postinstall"), &pkg.join("uninstall"), 0o755);
767 pkgbuild("uninstall");
769 t!(fs::create_dir_all(pkg.join("res")));
770 t!(t!(File::create(pkg.join("res/LICENSE.txt"))).write_all(license.as_bytes()));
771 install(&etc.join("gfx/rust-logo.png"), &pkg.join("res"), 0o644);
772 let mut cmd = Command::new("productbuild");
773 cmd.arg("--distribution").arg(etc.join("pkg/Distribution.xml"))
774 .arg("--resources").arg(pkg.join("res"))
775 .arg(distdir(build).join(format!("{}-{}.pkg",
776 pkgname(build, "rust"),
778 .arg("--package-path").arg(&pkg);
782 if target.contains("windows") {
783 let exe = tmp.join("exe");
784 let _ = fs::remove_dir_all(&exe);
785 t!(fs::create_dir_all(exe.join("rustc")));
786 t!(fs::create_dir_all(exe.join("cargo")));
787 t!(fs::create_dir_all(exe.join("rust-docs")));
788 t!(fs::create_dir_all(exe.join("rust-std")));
789 cp_r(&work.join(&format!("{}-{}", pkgname(build, "rustc"), target))
792 cp_r(&work.join(&format!("{}-{}", pkgname(build, "cargo"), target))
795 cp_r(&work.join(&format!("{}-{}", pkgname(build, "rust-docs"), target))
797 &exe.join("rust-docs"));
798 cp_r(&work.join(&format!("{}-{}", pkgname(build, "rust-std"), target))
799 .join(format!("rust-std-{}", target)),
800 &exe.join("rust-std"));
802 t!(fs::remove_file(exe.join("rustc/manifest.in")));
803 t!(fs::remove_file(exe.join("cargo/manifest.in")));
804 t!(fs::remove_file(exe.join("rust-docs/manifest.in")));
805 t!(fs::remove_file(exe.join("rust-std/manifest.in")));
807 if target.contains("windows-gnu") {
808 t!(fs::create_dir_all(exe.join("rust-mingw")));
809 cp_r(&work.join(&format!("{}-{}", pkgname(build, "rust-mingw"), target))
811 &exe.join("rust-mingw"));
812 t!(fs::remove_file(exe.join("rust-mingw/manifest.in")));
815 install(&etc.join("exe/rust.iss"), &exe, 0o644);
816 install(&etc.join("exe/modpath.iss"), &exe, 0o644);
817 install(&etc.join("exe/upgrade.iss"), &exe, 0o644);
818 install(&etc.join("gfx/rust-logo.ico"), &exe, 0o644);
819 t!(t!(File::create(exe.join("LICENSE.txt"))).write_all(license.as_bytes()));
821 // Generate exe installer
822 let mut cmd = Command::new("iscc");
825 if target.contains("windows-gnu") {
828 add_env(build, &mut cmd, target);
830 install(&exe.join(format!("{}-{}.exe", pkgname(build, "rust"), target)),
834 // Generate msi installer
835 let wix = PathBuf::from(env::var_os("WIX").unwrap());
836 let heat = wix.join("bin/heat.exe");
837 let candle = wix.join("bin/candle.exe");
838 let light = wix.join("bin/light.exe");
840 let heat_flags = ["-nologo", "-gg", "-sfrag", "-srd", "-sreg"];
841 build.run(Command::new(&heat)
846 .arg("-cg").arg("RustcGroup")
847 .arg("-dr").arg("Rustc")
848 .arg("-var").arg("var.RustcDir")
849 .arg("-out").arg(exe.join("RustcGroup.wxs")));
850 build.run(Command::new(&heat)
855 .arg("-cg").arg("DocsGroup")
856 .arg("-dr").arg("Docs")
857 .arg("-var").arg("var.DocsDir")
858 .arg("-out").arg(exe.join("DocsGroup.wxs"))
859 .arg("-t").arg(etc.join("msi/squash-components.xsl")));
860 build.run(Command::new(&heat)
865 .arg("-cg").arg("CargoGroup")
866 .arg("-dr").arg("Cargo")
867 .arg("-var").arg("var.CargoDir")
868 .arg("-out").arg(exe.join("CargoGroup.wxs"))
869 .arg("-t").arg(etc.join("msi/remove-duplicates.xsl")));
870 build.run(Command::new(&heat)
875 .arg("-cg").arg("StdGroup")
876 .arg("-dr").arg("Std")
877 .arg("-var").arg("var.StdDir")
878 .arg("-out").arg(exe.join("StdGroup.wxs")));
879 if target.contains("windows-gnu") {
880 build.run(Command::new(&heat)
885 .arg("-cg").arg("GccGroup")
886 .arg("-dr").arg("Gcc")
887 .arg("-var").arg("var.GccDir")
888 .arg("-out").arg(exe.join("GccGroup.wxs")));
891 let candle = |input: &Path| {
892 let output = exe.join(input.file_stem().unwrap())
893 .with_extension("wixobj");
894 let arch = if target.contains("x86_64") {"x64"} else {"x86"};
895 let mut cmd = Command::new(&candle);
896 cmd.current_dir(&exe)
898 .arg("-dRustcDir=rustc")
899 .arg("-dDocsDir=rust-docs")
900 .arg("-dCargoDir=cargo")
901 .arg("-dStdDir=rust-std")
902 .arg("-arch").arg(&arch)
903 .arg("-out").arg(&output)
905 add_env(build, &mut cmd, target);
907 if target.contains("windows-gnu") {
908 cmd.arg("-dGccDir=rust-mingw");
912 candle(&etc.join("msi/rust.wxs"));
913 candle(&etc.join("msi/ui.wxs"));
914 candle(&etc.join("msi/rustwelcomedlg.wxs"));
915 candle("RustcGroup.wxs".as_ref());
916 candle("DocsGroup.wxs".as_ref());
917 candle("CargoGroup.wxs".as_ref());
918 candle("StdGroup.wxs".as_ref());
920 if target.contains("windows-gnu") {
921 candle("GccGroup.wxs".as_ref());
924 t!(t!(File::create(exe.join("LICENSE.rtf"))).write_all(rtf.as_bytes()));
925 install(&etc.join("gfx/banner.bmp"), &exe, 0o644);
926 install(&etc.join("gfx/dialogbg.bmp"), &exe, 0o644);
928 let filename = format!("{}-{}.msi", pkgname(build, "rust"), target);
929 let mut cmd = Command::new(&light);
931 .arg("-ext").arg("WixUIExtension")
932 .arg("-ext").arg("WixUtilExtension")
933 .arg("-out").arg(exe.join(&filename))
936 .arg("rustwelcomedlg.wixobj")
937 .arg("RustcGroup.wixobj")
938 .arg("DocsGroup.wixobj")
939 .arg("CargoGroup.wixobj")
940 .arg("StdGroup.wixobj")
943 if target.contains("windows-gnu") {
944 cmd.arg("GccGroup.wixobj");
946 // ICE57 wrongly complains about the shortcuts
947 cmd.arg("-sice:ICE57");
951 t!(fs::rename(exe.join(&filename), distdir(build).join(&filename)));
955 fn add_env(build: &Build, cmd: &mut Command, target: &str) {
956 let mut parts = channel::CFG_RELEASE_NUM.split('.');
957 cmd.env("CFG_RELEASE_INFO", build.rust_version())
958 .env("CFG_RELEASE_NUM", channel::CFG_RELEASE_NUM)
959 .env("CFG_RELEASE", build.rust_release())
960 .env("CFG_PRERELEASE_VERSION", channel::CFG_PRERELEASE_VERSION)
961 .env("CFG_VER_MAJOR", parts.next().unwrap())
962 .env("CFG_VER_MINOR", parts.next().unwrap())
963 .env("CFG_VER_PATCH", parts.next().unwrap())
964 .env("CFG_VER_BUILD", "0") // just needed to build
965 .env("CFG_PACKAGE_VERS", build.rust_package_vers())
966 .env("CFG_PACKAGE_NAME", pkgname(build, "rust"))
967 .env("CFG_BUILD", target)
968 .env("CFG_CHANNEL", &build.config.channel);
970 if target.contains("windows-gnu") {
971 cmd.env("CFG_MINGW", "1")
972 .env("CFG_ABI", "GNU");
974 cmd.env("CFG_MINGW", "0")
975 .env("CFG_ABI", "MSVC");
978 if target.contains("x86_64") {
979 cmd.env("CFG_PLATFORM", "x64");
981 cmd.env("CFG_PLATFORM", "x86");
985 pub fn hash_and_sign(build: &Build) {
986 let compiler = Compiler::new(0, &build.config.build);
987 let mut cmd = build.tool_cmd(&compiler, "build-manifest");
988 let sign = build.config.dist_sign_folder.as_ref().unwrap_or_else(|| {
989 panic!("\n\nfailed to specify `dist.sign-folder` in `config.toml`\n\n")
991 let addr = build.config.dist_upload_addr.as_ref().unwrap_or_else(|| {
992 panic!("\n\nfailed to specify `dist.upload-addr` in `config.toml`\n\n")
994 let file = build.config.dist_gpg_password_file.as_ref().unwrap_or_else(|| {
995 panic!("\n\nfailed to specify `dist.gpg-password-file` in `config.toml`\n\n")
997 let mut pass = String::new();
998 t!(t!(File::open(&file)).read_to_string(&mut pass));
1000 let today = output(Command::new("date").arg("+%Y-%m-%d"));
1003 cmd.arg(distdir(build));
1004 cmd.arg(today.trim());
1005 cmd.arg(build.rust_package_vers());
1006 cmd.arg(build.package_vers(&build.release_num("cargo")));
1007 cmd.arg(build.package_vers(&build.release_num("rls")));
1010 t!(fs::create_dir_all(distdir(build)));
1012 let mut child = t!(cmd.stdin(Stdio::piped()).spawn());
1013 t!(child.stdin.take().unwrap().write_all(pass.as_bytes()));
1014 let status = t!(child.wait());
1015 assert!(status.success());