1 //! Implementation of the various distribution aspects of the compiler.
3 //! This module is responsible for creating tarballs of the standard library,
4 //! compiler, and documentation. This ends up being what we distribute to
7 //! No tarball is actually created literally in this file, but rather we shell
8 //! out to `rust-installer` still. This may one day be replaced with bits and
9 //! pieces of `rustup.rs`!
13 use std::path::{Path, PathBuf};
14 use std::process::Command;
16 use build_helper::{output, t};
18 use crate::builder::{Builder, RunConfig, ShouldRun, Step};
19 use crate::cache::{Interned, INTERNER};
21 use crate::config::TargetSelection;
22 use crate::tool::{self, Tool};
23 use crate::util::{exe, is_dylib, timeit};
24 use crate::{Compiler, DependencyType, Mode, LLVM_TOOLS};
25 use time::{self, Timespec};
27 pub fn pkgname(builder: &Builder<'_>, component: &str) -> String {
28 format!("{}-{}", component, builder.rust_package_vers())
31 pub(crate) fn distdir(builder: &Builder<'_>) -> PathBuf {
32 builder.out.join("dist")
35 pub fn tmpdir(builder: &Builder<'_>) -> PathBuf {
36 builder.out.join("tmp/dist")
39 fn rust_installer(builder: &Builder<'_>) -> Command {
40 builder.tool_cmd(Tool::RustInstaller)
43 fn missing_tool(tool_name: &str, skip: bool) {
45 println!("Unable to build {}, skipping dist", tool_name)
47 panic!("Unable to build {}", tool_name)
51 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
53 pub host: TargetSelection,
57 type Output = PathBuf;
58 const DEFAULT: bool = true;
60 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
64 fn make_run(run: RunConfig<'_>) {
65 run.builder.ensure(Docs { host: run.target });
68 /// Builds the `rust-docs` installer component.
69 fn run(self, builder: &Builder<'_>) -> PathBuf {
72 let name = pkgname(builder, "rust-docs");
74 if !builder.config.docs {
75 return distdir(builder).join(format!("{}-{}.tar.gz", name, host.triple));
78 builder.default_doc(None);
80 builder.info(&format!("Dist docs ({})", host));
81 let _time = timeit(builder);
83 let image = tmpdir(builder).join(format!("{}-{}-image", name, host.triple));
84 let _ = fs::remove_dir_all(&image);
86 let dst = image.join("share/doc/rust/html");
87 t!(fs::create_dir_all(&dst));
88 let src = builder.doc_out(host);
89 builder.cp_r(&src, &dst);
90 builder.install(&builder.src.join("src/doc/robots.txt"), &dst, 0o644);
92 let mut cmd = rust_installer(builder);
94 .arg("--product-name=Rust-Documentation")
95 .arg("--rel-manifest-dir=rustlib")
96 .arg("--success-message=Rust-documentation-is-installed.")
100 .arg(&tmpdir(builder))
102 .arg(&distdir(builder))
103 .arg(format!("--package-name={}-{}", name, host.triple))
104 .arg("--component-name=rust-docs")
105 .arg("--legacy-manifest-dirs=rustlib,cargo")
106 .arg("--bulk-dirs=share/doc/rust/html");
107 builder.run(&mut cmd);
108 builder.remove_dir(&image);
110 distdir(builder).join(format!("{}-{}.tar.gz", name, host.triple))
114 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
115 pub struct RustcDocs {
116 pub host: TargetSelection,
119 impl Step for RustcDocs {
120 type Output = PathBuf;
121 const DEFAULT: bool = true;
123 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
124 run.path("src/librustc")
127 fn make_run(run: RunConfig<'_>) {
128 run.builder.ensure(RustcDocs { host: run.target });
131 /// Builds the `rustc-docs` installer component.
132 fn run(self, builder: &Builder<'_>) -> PathBuf {
133 let host = self.host;
135 let name = pkgname(builder, "rustc-docs");
137 if !builder.config.compiler_docs {
138 return distdir(builder).join(format!("{}-{}.tar.gz", name, host.triple));
141 builder.default_doc(None);
143 let image = tmpdir(builder).join(format!("{}-{}-image", name, host.triple));
144 let _ = fs::remove_dir_all(&image);
146 let dst = image.join("share/doc/rust/html/rustc");
147 t!(fs::create_dir_all(&dst));
148 let src = builder.compiler_doc_out(host);
149 builder.cp_r(&src, &dst);
151 let mut cmd = rust_installer(builder);
153 .arg("--product-name=Rustc-Documentation")
154 .arg("--rel-manifest-dir=rustlib")
155 .arg("--success-message=Rustc-documentation-is-installed.")
159 .arg(&tmpdir(builder))
161 .arg(&distdir(builder))
162 .arg(format!("--package-name={}-{}", name, host.triple))
163 .arg("--component-name=rustc-docs")
164 .arg("--legacy-manifest-dirs=rustlib,cargo")
165 .arg("--bulk-dirs=share/doc/rust/html/rustc");
167 builder.info(&format!("Dist compiler docs ({})", host));
168 let _time = timeit(builder);
169 builder.run(&mut cmd);
170 builder.remove_dir(&image);
172 distdir(builder).join(format!("{}-{}.tar.gz", name, host.triple))
176 fn find_files(files: &[&str], path: &[PathBuf]) -> Vec<PathBuf> {
177 let mut found = Vec::with_capacity(files.len());
180 let file_path = path.iter().map(|dir| dir.join(file)).find(|p| p.exists());
182 if let Some(file_path) = file_path {
183 found.push(file_path);
185 panic!("Could not find '{}' in {:?}", file, path);
195 target: TargetSelection,
196 builder: &Builder<'_>,
198 //Ask gcc where it keeps its stuff
199 let mut cmd = Command::new(builder.cc(target));
200 cmd.arg("-print-search-dirs");
201 let gcc_out = output(&mut cmd);
203 let mut bin_path: Vec<_> = env::split_paths(&env::var_os("PATH").unwrap_or_default()).collect();
204 let mut lib_path = Vec::new();
206 for line in gcc_out.lines() {
207 let idx = line.find(':').unwrap();
208 let key = &line[..idx];
209 let trim_chars: &[_] = &[' ', '='];
210 let value = env::split_paths(line[(idx + 1)..].trim_start_matches(trim_chars));
212 if key == "programs" {
213 bin_path.extend(value);
214 } else if key == "libraries" {
215 lib_path.extend(value);
219 let compiler = if target == "i686-pc-windows-gnu" {
220 "i686-w64-mingw32-gcc.exe"
221 } else if target == "x86_64-pc-windows-gnu" {
222 "x86_64-w64-mingw32-gcc.exe"
226 let target_tools = [compiler, "ld.exe", "dlltool.exe", "libwinpthread-1.dll"];
227 let mut rustc_dlls = vec!["libwinpthread-1.dll"];
228 if target.starts_with("i686-") {
229 rustc_dlls.push("libgcc_s_dw2-1.dll");
231 rustc_dlls.push("libgcc_s_seh-1.dll");
246 //Windows import libs
269 "libsynchronization.a",
280 //Find mingw artifacts we want to bundle
281 let target_tools = find_files(&target_tools, &bin_path);
282 let rustc_dlls = find_files(&rustc_dlls, &bin_path);
283 let target_libs = find_files(&target_libs, &lib_path);
285 // Copy runtime dlls next to rustc.exe
286 let dist_bin_dir = rust_root.join("bin/");
287 fs::create_dir_all(&dist_bin_dir).expect("creating dist_bin_dir failed");
288 for src in rustc_dlls {
289 builder.copy_to_folder(&src, &dist_bin_dir);
292 //Copy platform tools to platform-specific bin directory
293 let target_bin_dir = plat_root
298 .join("self-contained");
299 fs::create_dir_all(&target_bin_dir).expect("creating target_bin_dir failed");
300 for src in target_tools {
301 builder.copy_to_folder(&src, &target_bin_dir);
304 // Warn windows-gnu users that the bundled GCC cannot compile C files
306 &target_bin_dir.join("GCC-WARNING.txt"),
307 "gcc.exe contained in this folder cannot be used for compiling C files - it is only \
308 used as a linker. In order to be able to compile projects containing C code use \
309 the GCC provided by MinGW or Cygwin.",
312 //Copy platform libs to platform-specific lib directory
313 let target_lib_dir = plat_root
318 .join("self-contained");
319 fs::create_dir_all(&target_lib_dir).expect("creating target_lib_dir failed");
320 for src in target_libs {
321 builder.copy_to_folder(&src, &target_lib_dir);
325 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
327 pub host: TargetSelection,
330 impl Step for Mingw {
331 type Output = Option<PathBuf>;
332 const DEFAULT: bool = true;
334 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
338 fn make_run(run: RunConfig<'_>) {
339 run.builder.ensure(Mingw { host: run.target });
342 /// Builds the `rust-mingw` installer component.
344 /// This contains all the bits and pieces to run the MinGW Windows targets
345 /// without any extra installed software (e.g., we bundle gcc, libraries, etc).
346 fn run(self, builder: &Builder<'_>) -> Option<PathBuf> {
347 let host = self.host;
349 if !host.contains("pc-windows-gnu") {
353 builder.info(&format!("Dist mingw ({})", host));
354 let _time = timeit(builder);
355 let name = pkgname(builder, "rust-mingw");
356 let image = tmpdir(builder).join(format!("{}-{}-image", name, host.triple));
357 let _ = fs::remove_dir_all(&image);
358 t!(fs::create_dir_all(&image));
360 // The first argument is a "temporary directory" which is just
361 // thrown away (this contains the runtime DLLs included in the rustc package
362 // above) and the second argument is where to place all the MinGW components
363 // (which is what we want).
364 make_win_dist(&tmpdir(builder), &image, host, &builder);
366 let mut cmd = rust_installer(builder);
368 .arg("--product-name=Rust-MinGW")
369 .arg("--rel-manifest-dir=rustlib")
370 .arg("--success-message=Rust-MinGW-is-installed.")
374 .arg(&tmpdir(builder))
376 .arg(&distdir(builder))
377 .arg(format!("--package-name={}-{}", name, host.triple))
378 .arg("--component-name=rust-mingw")
379 .arg("--legacy-manifest-dirs=rustlib,cargo");
380 builder.run(&mut cmd);
381 t!(fs::remove_dir_all(&image));
382 Some(distdir(builder).join(format!("{}-{}.tar.gz", name, host.triple)))
386 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
388 pub compiler: Compiler,
391 impl Step for Rustc {
392 type Output = PathBuf;
393 const DEFAULT: bool = true;
394 const ONLY_HOSTS: bool = true;
396 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
397 run.path("src/librustc")
400 fn make_run(run: RunConfig<'_>) {
402 .ensure(Rustc { compiler: run.builder.compiler(run.builder.top_stage, run.target) });
405 /// Creates the `rustc` installer component.
406 fn run(self, builder: &Builder<'_>) -> PathBuf {
407 let compiler = self.compiler;
408 let host = self.compiler.host;
410 let name = pkgname(builder, "rustc");
411 let image = tmpdir(builder).join(format!("{}-{}-image", name, host.triple));
412 let _ = fs::remove_dir_all(&image);
413 let overlay = tmpdir(builder).join(format!("{}-{}-overlay", name, host.triple));
414 let _ = fs::remove_dir_all(&overlay);
416 // Prepare the rustc "image", what will actually end up getting installed
417 prepare_image(builder, compiler, &image);
419 // Prepare the overlay which is part of the tarball but won't actually be
421 let cp = |file: &str| {
422 builder.install(&builder.src.join(file), &overlay, 0o644);
425 cp("LICENSE-APACHE");
428 // tiny morsel of metadata is used by rust-packaging
429 let version = builder.rust_version();
430 builder.create(&overlay.join("version"), &version);
431 if let Some(sha) = builder.rust_sha() {
432 builder.create(&overlay.join("git-commit-hash"), &sha);
435 // On MinGW we've got a few runtime DLL dependencies that we need to
436 // include. The first argument to this script is where to put these DLLs
437 // (the image we're creating), and the second argument is a junk directory
438 // to ignore all other MinGW stuff the script creates.
440 // On 32-bit MinGW we're always including a DLL which needs some extra
441 // licenses to distribute. On 64-bit MinGW we don't actually distribute
442 // anything requiring us to distribute a license, but it's likely the
443 // install will *also* include the rust-mingw package, which also needs
444 // licenses, so to be safe we just include it here in all MinGW packages.
445 if host.contains("pc-windows-gnu") {
446 make_win_dist(&image, &tmpdir(builder), host, builder);
448 let dst = image.join("share/doc");
449 t!(fs::create_dir_all(&dst));
450 builder.cp_r(&builder.src.join("src/etc/third-party"), &dst);
453 // Finally, wrap everything up in a nice tarball!
454 let mut cmd = rust_installer(builder);
456 .arg("--product-name=Rust")
457 .arg("--rel-manifest-dir=rustlib")
458 .arg("--success-message=Rust-is-ready-to-roll.")
462 .arg(&tmpdir(builder))
464 .arg(&distdir(builder))
465 .arg("--non-installed-overlay")
467 .arg(format!("--package-name={}-{}", name, host.triple))
468 .arg("--component-name=rustc")
469 .arg("--legacy-manifest-dirs=rustlib,cargo");
471 builder.info(&format!("Dist rustc stage{} ({})", compiler.stage, host.triple));
472 let _time = timeit(builder);
473 builder.run(&mut cmd);
474 builder.remove_dir(&image);
475 builder.remove_dir(&overlay);
477 return distdir(builder).join(format!("{}-{}.tar.gz", name, host.triple));
479 fn prepare_image(builder: &Builder<'_>, compiler: Compiler, image: &Path) {
480 let host = compiler.host;
481 let src = builder.sysroot(compiler);
483 // Copy rustc/rustdoc binaries
484 t!(fs::create_dir_all(image.join("bin")));
485 builder.cp_r(&src.join("bin"), &image.join("bin"));
487 builder.install(&builder.rustdoc(compiler), &image.join("bin"), 0o755);
489 let libdir_relative = builder.libdir_relative(compiler);
491 // Copy runtime DLLs needed by the compiler
492 if libdir_relative.to_str() != Some("bin") {
493 let libdir = builder.rustc_libdir(compiler);
494 for entry in builder.read_dir(&libdir) {
495 let name = entry.file_name();
496 if let Some(s) = name.to_str() {
498 // Don't use custom libdir here because ^lib/ will be resolved again
500 builder.install(&entry.path(), &image.join("lib"), 0o644);
506 // Copy over the codegen backends
507 let backends_src = builder.sysroot_codegen_backends(compiler);
508 let backends_rel = backends_src
511 .strip_prefix(builder.sysroot_libdir_relative(compiler))
513 // Don't use custom libdir here because ^lib/ will be resolved again with installer
514 let backends_dst = image.join("lib").join(&backends_rel);
516 t!(fs::create_dir_all(&backends_dst));
517 builder.cp_r(&backends_src, &backends_dst);
519 // Copy libLLVM.so to the lib dir as well, if needed. While not
520 // technically needed by rustc itself it's needed by lots of other
521 // components like the llvm tools and LLD. LLD is included below and
522 // tools/LLDB come later, so let's just throw it in the rustc
523 // component for now.
524 maybe_install_llvm_runtime(builder, host, image);
526 // Copy over lld if it's there
527 if builder.config.lld_enabled {
528 let exe = exe("rust-lld", compiler.host);
530 builder.sysroot_libdir(compiler, host).parent().unwrap().join("bin").join(&exe);
531 // for the rationale about this rename check `compile::copy_lld_to_sysroot`
532 let dst = image.join("lib/rustlib").join(&*host.triple).join("bin").join(&exe);
533 t!(fs::create_dir_all(&dst.parent().unwrap()));
534 builder.copy(&src, &dst);
538 t!(fs::create_dir_all(image.join("share/man/man1")));
539 let man_src = builder.src.join("src/doc/man");
540 let man_dst = image.join("share/man/man1");
542 // Reproducible builds: If SOURCE_DATE_EPOCH is set, use that as the time.
543 let time = env::var("SOURCE_DATE_EPOCH")
545 let epoch = timestamp
547 .map_err(|err| format!("could not parse SOURCE_DATE_EPOCH: {}", err))
550 time::at(Timespec::new(epoch, 0))
552 .unwrap_or_else(|_| time::now());
554 let month_year = t!(time::strftime("%B %Y", &time));
555 // don't use our `bootstrap::util::{copy, cp_r}`, because those try
556 // to hardlink, and we don't want to edit the source templates
557 for file_entry in builder.read_dir(&man_src) {
558 let page_src = file_entry.path();
559 let page_dst = man_dst.join(file_entry.file_name());
560 t!(fs::copy(&page_src, &page_dst));
561 // template in month/year and version number
562 builder.replace_in_file(
565 ("<INSERT DATE HERE>", &month_year),
566 ("<INSERT VERSION HERE>", &builder.version),
573 .ensure(DebuggerScripts { sysroot: INTERNER.intern_path(image.to_owned()), host });
576 let cp = |file: &str| {
577 builder.install(&builder.src.join(file), &image.join("share/doc/rust"), 0o644);
580 cp("LICENSE-APACHE");
587 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
588 pub struct DebuggerScripts {
589 pub sysroot: Interned<PathBuf>,
590 pub host: TargetSelection,
593 impl Step for DebuggerScripts {
596 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
597 run.path("src/lldb_batchmode.py")
600 fn make_run(run: RunConfig<'_>) {
601 run.builder.ensure(DebuggerScripts {
604 .sysroot(run.builder.compiler(run.builder.top_stage, run.build_triple())),
609 /// Copies debugger scripts for `target` into the `sysroot` specified.
610 fn run(self, builder: &Builder<'_>) {
611 let host = self.host;
612 let sysroot = self.sysroot;
613 let dst = sysroot.join("lib/rustlib/etc");
614 t!(fs::create_dir_all(&dst));
615 let cp_debugger_script = |file: &str| {
616 builder.install(&builder.src.join("src/etc/").join(file), &dst, 0o644);
618 if host.contains("windows-msvc") {
619 // windbg debugger scripts
621 &builder.src.join("src/etc/rust-windbg.cmd"),
622 &sysroot.join("bin"),
626 cp_debugger_script("natvis/intrinsic.natvis");
627 cp_debugger_script("natvis/liballoc.natvis");
628 cp_debugger_script("natvis/libcore.natvis");
629 cp_debugger_script("natvis/libstd.natvis");
631 cp_debugger_script("rust_types.py");
633 // gdb debugger scripts
634 builder.install(&builder.src.join("src/etc/rust-gdb"), &sysroot.join("bin"), 0o755);
635 builder.install(&builder.src.join("src/etc/rust-gdbgui"), &sysroot.join("bin"), 0o755);
637 cp_debugger_script("gdb_load_rust_pretty_printers.py");
638 cp_debugger_script("gdb_lookup.py");
639 cp_debugger_script("gdb_providers.py");
641 // lldb debugger scripts
642 builder.install(&builder.src.join("src/etc/rust-lldb"), &sysroot.join("bin"), 0o755);
644 cp_debugger_script("lldb_lookup.py");
645 cp_debugger_script("lldb_providers.py");
646 cp_debugger_script("lldb_commands")
651 fn skip_host_target_lib(builder: &Builder<'_>, compiler: Compiler) -> bool {
652 // The only true set of target libraries came from the build triple, so
653 // let's reduce redundant work by only producing archives from that host.
654 if compiler.host != builder.config.build {
655 builder.info("\tskipping, not a build host");
662 /// Copy stamped files into an image's `target/lib` directory.
663 fn copy_target_libs(builder: &Builder<'_>, target: TargetSelection, image: &Path, stamp: &Path) {
664 let dst = image.join("lib/rustlib").join(target.triple).join("lib");
665 let self_contained_dst = dst.join("self-contained");
666 t!(fs::create_dir_all(&dst));
667 t!(fs::create_dir_all(&self_contained_dst));
668 for (path, dependency_type) in builder.read_stamp_file(stamp) {
669 if dependency_type == DependencyType::TargetSelfContained {
670 builder.copy(&path, &self_contained_dst.join(path.file_name().unwrap()));
671 } else if dependency_type == DependencyType::Target || builder.config.build == target {
672 builder.copy(&path, &dst.join(path.file_name().unwrap()));
677 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
679 pub compiler: Compiler,
680 pub target: TargetSelection,
684 type Output = PathBuf;
685 const DEFAULT: bool = true;
687 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
688 run.path("library/std")
691 fn make_run(run: RunConfig<'_>) {
692 run.builder.ensure(Std {
693 compiler: run.builder.compiler_for(
694 run.builder.top_stage,
695 run.builder.config.build,
702 fn run(self, builder: &Builder<'_>) -> PathBuf {
703 let compiler = self.compiler;
704 let target = self.target;
706 let name = pkgname(builder, "rust-std");
707 let archive = distdir(builder).join(format!("{}-{}.tar.gz", name, target.triple));
708 if skip_host_target_lib(builder, compiler) {
712 builder.ensure(compile::Std { compiler, target });
714 let image = tmpdir(builder).join(format!("{}-{}-image", name, target.triple));
715 let _ = fs::remove_dir_all(&image);
717 let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target);
718 let stamp = compile::libstd_stamp(builder, compiler_to_use, target);
719 copy_target_libs(builder, target, &image, &stamp);
721 let mut cmd = rust_installer(builder);
723 .arg("--product-name=Rust")
724 .arg("--rel-manifest-dir=rustlib")
725 .arg("--success-message=std-is-standing-at-the-ready.")
729 .arg(&tmpdir(builder))
731 .arg(&distdir(builder))
732 .arg(format!("--package-name={}-{}", name, target.triple))
733 .arg(format!("--component-name=rust-std-{}", target.triple))
734 .arg("--legacy-manifest-dirs=rustlib,cargo");
737 .info(&format!("Dist std stage{} ({} -> {})", compiler.stage, &compiler.host, target));
738 let _time = timeit(builder);
739 builder.run(&mut cmd);
740 builder.remove_dir(&image);
745 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
746 pub struct RustcDev {
747 pub compiler: Compiler,
748 pub target: TargetSelection,
751 impl Step for RustcDev {
752 type Output = PathBuf;
753 const DEFAULT: bool = true;
754 const ONLY_HOSTS: bool = true;
756 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
757 run.path("rustc-dev")
760 fn make_run(run: RunConfig<'_>) {
761 run.builder.ensure(RustcDev {
762 compiler: run.builder.compiler_for(
763 run.builder.top_stage,
764 run.builder.config.build,
771 fn run(self, builder: &Builder<'_>) -> PathBuf {
772 let compiler = self.compiler;
773 let target = self.target;
775 let name = pkgname(builder, "rustc-dev");
776 let archive = distdir(builder).join(format!("{}-{}.tar.gz", name, target.triple));
777 if skip_host_target_lib(builder, compiler) {
781 builder.ensure(compile::Rustc { compiler, target });
783 let image = tmpdir(builder).join(format!("{}-{}-image", name, target.triple));
784 let _ = fs::remove_dir_all(&image);
786 let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target);
787 let stamp = compile::librustc_stamp(builder, compiler_to_use, target);
788 copy_target_libs(builder, target, &image, &stamp);
790 // Copy compiler sources.
791 let dst_src = image.join("lib/rustlib/rustc-src/rust");
792 t!(fs::create_dir_all(&dst_src));
794 let src_files = ["Cargo.lock"];
795 // This is the reduced set of paths which will become the rustc-dev component
796 // (essentially the compiler crates and all of their path dependencies).
797 copy_src_dirs(builder, &builder.src, &["compiler"], &[], &dst_src);
798 for file in src_files.iter() {
799 builder.copy(&builder.src.join(file), &dst_src.join(file));
802 let mut cmd = rust_installer(builder);
804 .arg("--product-name=Rust")
805 .arg("--rel-manifest-dir=rustlib")
806 .arg("--success-message=Rust-is-ready-to-develop.")
810 .arg(&tmpdir(builder))
812 .arg(&distdir(builder))
813 .arg(format!("--package-name={}-{}", name, target.triple))
814 .arg(format!("--component-name=rustc-dev-{}", target.triple))
815 .arg("--legacy-manifest-dirs=rustlib,cargo");
817 builder.info(&format!(
818 "Dist rustc-dev stage{} ({} -> {})",
819 compiler.stage, &compiler.host, target
821 let _time = timeit(builder);
822 builder.run(&mut cmd);
823 builder.remove_dir(&image);
828 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
829 pub struct Analysis {
830 pub compiler: Compiler,
831 pub target: TargetSelection,
834 impl Step for Analysis {
835 type Output = PathBuf;
836 const DEFAULT: bool = true;
838 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
839 let builder = run.builder;
840 run.path("analysis").default_condition(builder.config.extended)
843 fn make_run(run: RunConfig<'_>) {
844 run.builder.ensure(Analysis {
845 // Find the actual compiler (handling the full bootstrap option) which
846 // produced the save-analysis data because that data isn't copied
847 // through the sysroot uplifting.
848 compiler: run.builder.compiler_for(
849 run.builder.top_stage,
850 run.builder.config.build,
857 /// Creates a tarball of save-analysis metadata, if available.
858 fn run(self, builder: &Builder<'_>) -> PathBuf {
859 let compiler = self.compiler;
860 let target = self.target;
861 assert!(builder.config.extended);
862 let name = pkgname(builder, "rust-analysis");
864 if compiler.host != builder.config.build {
865 return distdir(builder).join(format!("{}-{}.tar.gz", name, target.triple));
868 builder.ensure(compile::Std { compiler, target });
870 let image = tmpdir(builder).join(format!("{}-{}-image", name, target.triple));
873 .stage_out(compiler, Mode::Std)
875 .join(builder.cargo_dir())
878 let image_src = src.join("save-analysis");
879 let dst = image.join("lib/rustlib").join(target.triple).join("analysis");
880 t!(fs::create_dir_all(&dst));
881 builder.info(&format!("image_src: {:?}, dst: {:?}", image_src, dst));
882 builder.cp_r(&image_src, &dst);
884 let mut cmd = rust_installer(builder);
886 .arg("--product-name=Rust")
887 .arg("--rel-manifest-dir=rustlib")
888 .arg("--success-message=save-analysis-saved.")
892 .arg(&tmpdir(builder))
894 .arg(&distdir(builder))
895 .arg(format!("--package-name={}-{}", name, target.triple))
896 .arg(format!("--component-name=rust-analysis-{}", target.triple))
897 .arg("--legacy-manifest-dirs=rustlib,cargo");
899 builder.info("Dist analysis");
900 let _time = timeit(builder);
901 builder.run(&mut cmd);
902 builder.remove_dir(&image);
903 distdir(builder).join(format!("{}-{}.tar.gz", name, target.triple))
907 /// Use the `builder` to make a filtered copy of `base`/X for X in (`src_dirs` - `exclude_dirs`) to
910 builder: &Builder<'_>,
913 exclude_dirs: &[&str],
916 fn filter_fn(exclude_dirs: &[&str], dir: &str, path: &Path) -> bool {
917 let spath = match path.to_str() {
919 None => return false,
921 if spath.ends_with('~') || spath.ends_with(".pyc") {
925 const LLVM_PROJECTS: &[&str] = &[
926 "llvm-project/clang",
927 "llvm-project\\clang",
928 "llvm-project/libunwind",
929 "llvm-project\\libunwind",
933 "llvm-project\\lldb",
935 "llvm-project\\llvm",
936 "llvm-project/compiler-rt",
937 "llvm-project\\compiler-rt",
939 if spath.contains("llvm-project")
940 && !spath.ends_with("llvm-project")
941 && !LLVM_PROJECTS.iter().any(|path| spath.contains(path))
946 const LLVM_TEST: &[&str] = &["llvm-project/llvm/test", "llvm-project\\llvm\\test"];
947 if LLVM_TEST.iter().any(|path| spath.contains(path))
948 && (spath.ends_with(".ll") || spath.ends_with(".td") || spath.ends_with(".s"))
953 let full_path = Path::new(dir).join(path);
954 if exclude_dirs.iter().any(|excl| full_path == Path::new(excl)) {
981 !path.iter().map(|s| s.to_str().unwrap()).any(|s| excludes.contains(&s))
984 // Copy the directories using our filter
985 for item in src_dirs {
986 let dst = &dst_dir.join(item);
987 t!(fs::create_dir_all(dst));
988 builder.cp_filtered(&base.join(item), dst, &|path| filter_fn(exclude_dirs, item, path));
992 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
996 /// The output path of the src installer tarball
997 type Output = PathBuf;
998 const DEFAULT: bool = true;
999 const ONLY_HOSTS: bool = true;
1001 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1005 fn make_run(run: RunConfig<'_>) {
1006 run.builder.ensure(Src);
1009 /// Creates the `rust-src` installer component
1010 fn run(self, builder: &Builder<'_>) -> PathBuf {
1011 let name = pkgname(builder, "rust-src");
1012 let image = tmpdir(builder).join(format!("{}-image", name));
1013 let _ = fs::remove_dir_all(&image);
1015 // A lot of tools expect the rust-src component to be entirely in this directory, so if you
1016 // change that (e.g. by adding another directory `lib/rustlib/src/foo` or
1017 // `lib/rustlib/src/rust/foo`), you will need to go around hunting for implicit assumptions
1020 // NOTE: if you update the paths here, you also should update the "virtual" path
1021 // translation code in `imported_source_files` in `src/librustc_metadata/rmeta/decoder.rs`
1022 let dst_src = image.join("lib/rustlib/src/rust");
1023 t!(fs::create_dir_all(&dst_src));
1025 let src_files = ["Cargo.lock"];
1026 // This is the reduced set of paths which will become the rust-src component
1027 // (essentially libstd and all of its path dependencies).
1031 &["library", "src/llvm-project/libunwind"],
1033 // not needed and contains symlinks which rustup currently
1034 // chokes on when unpacking.
1035 "library/backtrace/crates",
1039 for file in src_files.iter() {
1040 builder.copy(&builder.src.join(file), &dst_src.join(file));
1043 // libtest includes std and everything else, so vendoring it
1044 // creates exactly what's needed for `cargo -Zbuild-std` or any
1045 // other analysis of the stdlib's source. Cargo also needs help
1046 // finding the lock, so we copy it to libtest temporarily.
1048 // Note that this requires std to only have one version of each
1049 // crate. e.g. two versions of getopts won't be patchable.
1050 let dst_libtest = dst_src.join("library/test");
1051 let dst_vendor = dst_src.join("vendor");
1052 let root_lock = dst_src.join("Cargo.lock");
1053 let temp_lock = dst_libtest.join("Cargo.lock");
1055 // `cargo vendor` will delete everything from the lockfile that
1056 // isn't used by libtest, so we need to not use any links!
1057 builder.really_copy(&root_lock, &temp_lock);
1059 let mut cmd = Command::new(&builder.initial_cargo);
1060 cmd.arg("vendor").arg(dst_vendor).current_dir(&dst_libtest);
1061 builder.info("Dist src");
1062 let _time = timeit(builder);
1063 builder.run(&mut cmd);
1065 builder.remove(&temp_lock);
1067 // Create source tarball in rust-installer format
1068 let mut cmd = rust_installer(builder);
1070 .arg("--product-name=Rust")
1071 .arg("--rel-manifest-dir=rustlib")
1072 .arg("--success-message=Awesome-Source.")
1076 .arg(&tmpdir(builder))
1077 .arg("--output-dir")
1078 .arg(&distdir(builder))
1079 .arg(format!("--package-name={}", name))
1080 .arg("--component-name=rust-src")
1081 .arg("--legacy-manifest-dirs=rustlib,cargo");
1083 builder.run(&mut cmd);
1085 builder.remove_dir(&image);
1086 distdir(builder).join(&format!("{}.tar.gz", name))
1090 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
1091 pub struct PlainSourceTarball;
1093 impl Step for PlainSourceTarball {
1094 /// Produces the location of the tarball generated
1095 type Output = PathBuf;
1096 const DEFAULT: bool = true;
1097 const ONLY_HOSTS: bool = true;
1099 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1100 let builder = run.builder;
1101 run.path("src").default_condition(builder.config.rust_dist_src)
1104 fn make_run(run: RunConfig<'_>) {
1105 run.builder.ensure(PlainSourceTarball);
1108 /// Creates the plain source tarball
1109 fn run(self, builder: &Builder<'_>) -> PathBuf {
1110 // Make sure that the root folder of tarball has the correct name
1111 let plain_name = format!("{}-src", pkgname(builder, "rustc"));
1112 let plain_dst_src = tmpdir(builder).join(&plain_name);
1113 let _ = fs::remove_dir_all(&plain_dst_src);
1114 t!(fs::create_dir_all(&plain_dst_src));
1116 // This is the set of root paths which will become part of the source package
1126 "config.toml.example",
1130 let src_dirs = ["src", "compiler", "library"];
1132 copy_src_dirs(builder, &builder.src, &src_dirs, &[], &plain_dst_src);
1134 // Copy the files normally
1135 for item in &src_files {
1136 builder.copy(&builder.src.join(item), &plain_dst_src.join(item));
1139 // Create the version file
1140 builder.create(&plain_dst_src.join("version"), &builder.rust_version());
1141 if let Some(sha) = builder.rust_sha() {
1142 builder.create(&plain_dst_src.join("git-commit-hash"), &sha);
1145 // If we're building from git sources, we need to vendor a complete distribution.
1146 if builder.rust_info.is_git() {
1147 // Vendor all Cargo dependencies
1148 let mut cmd = Command::new(&builder.initial_cargo);
1151 .arg(builder.src.join("./src/tools/rust-analyzer/Cargo.toml"))
1152 .arg(builder.src.join("./compiler/rustc_codegen_cranelift/Cargo.toml"))
1153 .current_dir(&plain_dst_src);
1154 builder.run(&mut cmd);
1157 // Create plain source tarball
1158 let plain_name = format!("rustc-{}-src", builder.rust_package_vers());
1159 let mut tarball = distdir(builder).join(&format!("{}.tar.gz", plain_name));
1160 tarball.set_extension(""); // strip .gz
1161 tarball.set_extension(""); // strip .tar
1162 if let Some(dir) = tarball.parent() {
1163 builder.create_dir(&dir);
1165 builder.info("running installer");
1166 let mut cmd = rust_installer(builder);
1172 .arg("--work-dir=.")
1173 .current_dir(tmpdir(builder));
1175 builder.info("Create plain source tarball");
1176 let _time = timeit(builder);
1177 builder.run(&mut cmd);
1178 distdir(builder).join(&format!("{}.tar.gz", plain_name))
1182 // We have to run a few shell scripts, which choke quite a bit on both `\`
1183 // characters and on `C:\` paths, so normalize both of them away.
1184 pub fn sanitize_sh(path: &Path) -> String {
1185 let path = path.to_str().unwrap().replace("\\", "/");
1186 return change_drive(unc_to_lfs(&path)).unwrap_or(path);
1188 fn unc_to_lfs(s: &str) -> &str {
1189 if s.starts_with("//?/") { &s[4..] } else { s }
1192 fn change_drive(s: &str) -> Option<String> {
1193 let mut ch = s.chars();
1194 let drive = ch.next().unwrap_or('C');
1195 if ch.next() != Some(':') {
1198 if ch.next() != Some('/') {
1201 Some(format!("/{}/{}", drive, &s[drive.len_utf8() + 2..]))
1205 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
1207 pub compiler: Compiler,
1208 pub target: TargetSelection,
1211 impl Step for Cargo {
1212 type Output = PathBuf;
1213 const ONLY_HOSTS: bool = true;
1215 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1219 fn make_run(run: RunConfig<'_>) {
1220 run.builder.ensure(Cargo {
1221 compiler: run.builder.compiler_for(
1222 run.builder.top_stage,
1223 run.builder.config.build,
1230 fn run(self, builder: &Builder<'_>) -> PathBuf {
1231 let compiler = self.compiler;
1232 let target = self.target;
1234 let src = builder.src.join("src/tools/cargo");
1235 let etc = src.join("src/etc");
1236 let release_num = builder.release_num("cargo");
1237 let name = pkgname(builder, "cargo");
1238 let version = builder.cargo_info.version(builder, &release_num);
1240 let tmp = tmpdir(builder);
1241 let image = tmp.join("cargo-image");
1242 drop(fs::remove_dir_all(&image));
1243 builder.create_dir(&image);
1245 // Prepare the image directory
1246 builder.create_dir(&image.join("share/zsh/site-functions"));
1247 builder.create_dir(&image.join("etc/bash_completion.d"));
1248 let cargo = builder.ensure(tool::Cargo { compiler, target });
1249 builder.install(&cargo, &image.join("bin"), 0o755);
1250 for man in t!(etc.join("man").read_dir()) {
1252 builder.install(&man.path(), &image.join("share/man/man1"), 0o644);
1254 builder.install(&etc.join("_cargo"), &image.join("share/zsh/site-functions"), 0o644);
1255 builder.copy(&etc.join("cargo.bashcomp.sh"), &image.join("etc/bash_completion.d/cargo"));
1256 let doc = image.join("share/doc/cargo");
1257 builder.install(&src.join("README.md"), &doc, 0o644);
1258 builder.install(&src.join("LICENSE-MIT"), &doc, 0o644);
1259 builder.install(&src.join("LICENSE-APACHE"), &doc, 0o644);
1260 builder.install(&src.join("LICENSE-THIRD-PARTY"), &doc, 0o644);
1262 // Prepare the overlay
1263 let overlay = tmp.join("cargo-overlay");
1264 drop(fs::remove_dir_all(&overlay));
1265 builder.create_dir(&overlay);
1266 builder.install(&src.join("README.md"), &overlay, 0o644);
1267 builder.install(&src.join("LICENSE-MIT"), &overlay, 0o644);
1268 builder.install(&src.join("LICENSE-APACHE"), &overlay, 0o644);
1269 builder.install(&src.join("LICENSE-THIRD-PARTY"), &overlay, 0o644);
1270 builder.create(&overlay.join("version"), &version);
1272 // Generate the installer tarball
1273 let mut cmd = rust_installer(builder);
1275 .arg("--product-name=Rust")
1276 .arg("--rel-manifest-dir=rustlib")
1277 .arg("--success-message=Rust-is-ready-to-roll.")
1281 .arg(&tmpdir(builder))
1282 .arg("--output-dir")
1283 .arg(&distdir(builder))
1284 .arg("--non-installed-overlay")
1286 .arg(format!("--package-name={}-{}", name, target.triple))
1287 .arg("--component-name=cargo")
1288 .arg("--legacy-manifest-dirs=rustlib,cargo");
1290 builder.info(&format!("Dist cargo stage{} ({})", compiler.stage, target));
1291 let _time = timeit(builder);
1292 builder.run(&mut cmd);
1293 distdir(builder).join(format!("{}-{}.tar.gz", name, target.triple))
1297 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
1299 pub compiler: Compiler,
1300 pub target: TargetSelection,
1304 type Output = Option<PathBuf>;
1305 const ONLY_HOSTS: bool = true;
1307 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1311 fn make_run(run: RunConfig<'_>) {
1312 run.builder.ensure(Rls {
1313 compiler: run.builder.compiler_for(
1314 run.builder.top_stage,
1315 run.builder.config.build,
1322 fn run(self, builder: &Builder<'_>) -> Option<PathBuf> {
1323 let compiler = self.compiler;
1324 let target = self.target;
1325 assert!(builder.config.extended);
1327 let src = builder.src.join("src/tools/rls");
1328 let release_num = builder.release_num("rls");
1329 let name = pkgname(builder, "rls");
1330 let version = builder.rls_info.version(builder, &release_num);
1332 let tmp = tmpdir(builder);
1333 let image = tmp.join("rls-image");
1334 drop(fs::remove_dir_all(&image));
1335 t!(fs::create_dir_all(&image));
1337 // Prepare the image directory
1338 // We expect RLS to build, because we've exited this step above if tool
1339 // state for RLS isn't testing.
1341 .ensure(tool::Rls { compiler, target, extra_features: Vec::new() })
1343 missing_tool("RLS", builder.build.config.missing_tools);
1347 builder.install(&rls, &image.join("bin"), 0o755);
1348 let doc = image.join("share/doc/rls");
1349 builder.install(&src.join("README.md"), &doc, 0o644);
1350 builder.install(&src.join("LICENSE-MIT"), &doc, 0o644);
1351 builder.install(&src.join("LICENSE-APACHE"), &doc, 0o644);
1353 // Prepare the overlay
1354 let overlay = tmp.join("rls-overlay");
1355 drop(fs::remove_dir_all(&overlay));
1356 t!(fs::create_dir_all(&overlay));
1357 builder.install(&src.join("README.md"), &overlay, 0o644);
1358 builder.install(&src.join("LICENSE-MIT"), &overlay, 0o644);
1359 builder.install(&src.join("LICENSE-APACHE"), &overlay, 0o644);
1360 builder.create(&overlay.join("version"), &version);
1362 // Generate the installer tarball
1363 let mut cmd = rust_installer(builder);
1365 .arg("--product-name=Rust")
1366 .arg("--rel-manifest-dir=rustlib")
1367 .arg("--success-message=RLS-ready-to-serve.")
1371 .arg(&tmpdir(builder))
1372 .arg("--output-dir")
1373 .arg(&distdir(builder))
1374 .arg("--non-installed-overlay")
1376 .arg(format!("--package-name={}-{}", name, target.triple))
1377 .arg("--legacy-manifest-dirs=rustlib,cargo")
1378 .arg("--component-name=rls-preview");
1380 builder.info(&format!("Dist RLS stage{} ({})", compiler.stage, target.triple));
1381 let _time = timeit(builder);
1382 builder.run(&mut cmd);
1383 Some(distdir(builder).join(format!("{}-{}.tar.gz", name, target.triple)))
1387 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
1388 pub struct RustAnalyzer {
1389 pub compiler: Compiler,
1390 pub target: TargetSelection,
1393 impl Step for RustAnalyzer {
1394 type Output = Option<PathBuf>;
1395 const ONLY_HOSTS: bool = true;
1397 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1398 run.path("rust-analyzer")
1401 fn make_run(run: RunConfig<'_>) {
1402 run.builder.ensure(RustAnalyzer {
1403 compiler: run.builder.compiler_for(
1404 run.builder.top_stage,
1405 run.builder.config.build,
1412 fn run(self, builder: &Builder<'_>) -> Option<PathBuf> {
1413 let compiler = self.compiler;
1414 let target = self.target;
1415 assert!(builder.config.extended);
1417 if target.contains("riscv64") {
1418 // riscv64 currently has an LLVM bug that makes rust-analyzer unable
1419 // to build. See #74813 for details.
1423 let src = builder.src.join("src/tools/rust-analyzer");
1424 let release_num = builder.release_num("rust-analyzer/crates/rust-analyzer");
1425 let name = pkgname(builder, "rust-analyzer");
1426 let version = builder.rust_analyzer_info.version(builder, &release_num);
1428 let tmp = tmpdir(builder);
1429 let image = tmp.join("rust-analyzer-image");
1430 drop(fs::remove_dir_all(&image));
1431 builder.create_dir(&image);
1433 // Prepare the image directory
1434 // We expect rust-analyer to always build, as it doesn't depend on rustc internals
1435 // and doesn't have associated toolstate.
1436 let rust_analyzer = builder
1437 .ensure(tool::RustAnalyzer { compiler, target, extra_features: Vec::new() })
1438 .expect("rust-analyzer always builds");
1440 builder.install(&rust_analyzer, &image.join("bin"), 0o755);
1441 let doc = image.join("share/doc/rust-analyzer");
1442 builder.install(&src.join("README.md"), &doc, 0o644);
1443 builder.install(&src.join("LICENSE-APACHE"), &doc, 0o644);
1444 builder.install(&src.join("LICENSE-MIT"), &doc, 0o644);
1446 // Prepare the overlay
1447 let overlay = tmp.join("rust-analyzer-overlay");
1448 drop(fs::remove_dir_all(&overlay));
1449 t!(fs::create_dir_all(&overlay));
1450 builder.install(&src.join("README.md"), &overlay, 0o644);
1451 builder.install(&src.join("LICENSE-APACHE"), &doc, 0o644);
1452 builder.install(&src.join("LICENSE-MIT"), &doc, 0o644);
1453 builder.create(&overlay.join("version"), &version);
1455 // Generate the installer tarball
1456 let mut cmd = rust_installer(builder);
1458 .arg("--product-name=Rust")
1459 .arg("--rel-manifest-dir=rustlib")
1460 .arg("--success-message=rust-analyzer-ready-to-serve.")
1464 .arg(&tmpdir(builder))
1465 .arg("--output-dir")
1466 .arg(&distdir(builder))
1467 .arg("--non-installed-overlay")
1469 .arg(format!("--package-name={}-{}", name, target.triple))
1470 .arg("--legacy-manifest-dirs=rustlib,cargo")
1471 .arg("--component-name=rust-analyzer-preview");
1473 builder.info(&format!("Dist rust-analyzer stage{} ({})", compiler.stage, target));
1474 let _time = timeit(builder);
1475 builder.run(&mut cmd);
1476 Some(distdir(builder).join(format!("{}-{}.tar.gz", name, target.triple)))
1480 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
1482 pub compiler: Compiler,
1483 pub target: TargetSelection,
1486 impl Step for Clippy {
1487 type Output = PathBuf;
1488 const ONLY_HOSTS: bool = true;
1490 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1494 fn make_run(run: RunConfig<'_>) {
1495 run.builder.ensure(Clippy {
1496 compiler: run.builder.compiler_for(
1497 run.builder.top_stage,
1498 run.builder.config.build,
1505 fn run(self, builder: &Builder<'_>) -> PathBuf {
1506 let compiler = self.compiler;
1507 let target = self.target;
1508 assert!(builder.config.extended);
1510 let src = builder.src.join("src/tools/clippy");
1511 let release_num = builder.release_num("clippy");
1512 let name = pkgname(builder, "clippy");
1513 let version = builder.clippy_info.version(builder, &release_num);
1515 let tmp = tmpdir(builder);
1516 let image = tmp.join("clippy-image");
1517 drop(fs::remove_dir_all(&image));
1518 builder.create_dir(&image);
1520 // Prepare the image directory
1521 // We expect clippy to build, because we've exited this step above if tool
1522 // state for clippy isn't testing.
1523 let clippy = builder
1524 .ensure(tool::Clippy { compiler, target, extra_features: Vec::new() })
1525 .expect("clippy expected to build - essential tool");
1526 let cargoclippy = builder
1527 .ensure(tool::CargoClippy { compiler, target, extra_features: Vec::new() })
1528 .expect("clippy expected to build - essential tool");
1530 builder.install(&clippy, &image.join("bin"), 0o755);
1531 builder.install(&cargoclippy, &image.join("bin"), 0o755);
1532 let doc = image.join("share/doc/clippy");
1533 builder.install(&src.join("README.md"), &doc, 0o644);
1534 builder.install(&src.join("LICENSE-APACHE"), &doc, 0o644);
1535 builder.install(&src.join("LICENSE-MIT"), &doc, 0o644);
1537 // Prepare the overlay
1538 let overlay = tmp.join("clippy-overlay");
1539 drop(fs::remove_dir_all(&overlay));
1540 t!(fs::create_dir_all(&overlay));
1541 builder.install(&src.join("README.md"), &overlay, 0o644);
1542 builder.install(&src.join("LICENSE-APACHE"), &doc, 0o644);
1543 builder.install(&src.join("LICENSE-MIT"), &doc, 0o644);
1544 builder.create(&overlay.join("version"), &version);
1546 // Generate the installer tarball
1547 let mut cmd = rust_installer(builder);
1549 .arg("--product-name=Rust")
1550 .arg("--rel-manifest-dir=rustlib")
1551 .arg("--success-message=clippy-ready-to-serve.")
1555 .arg(&tmpdir(builder))
1556 .arg("--output-dir")
1557 .arg(&distdir(builder))
1558 .arg("--non-installed-overlay")
1560 .arg(format!("--package-name={}-{}", name, target.triple))
1561 .arg("--legacy-manifest-dirs=rustlib,cargo")
1562 .arg("--component-name=clippy-preview");
1564 builder.info(&format!("Dist clippy stage{} ({})", compiler.stage, target));
1565 let _time = timeit(builder);
1566 builder.run(&mut cmd);
1567 distdir(builder).join(format!("{}-{}.tar.gz", name, target.triple))
1571 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
1573 pub compiler: Compiler,
1574 pub target: TargetSelection,
1577 impl Step for Miri {
1578 type Output = Option<PathBuf>;
1579 const ONLY_HOSTS: bool = true;
1581 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1585 fn make_run(run: RunConfig<'_>) {
1586 run.builder.ensure(Miri {
1587 compiler: run.builder.compiler_for(
1588 run.builder.top_stage,
1589 run.builder.config.build,
1596 fn run(self, builder: &Builder<'_>) -> Option<PathBuf> {
1597 let compiler = self.compiler;
1598 let target = self.target;
1599 assert!(builder.config.extended);
1601 let src = builder.src.join("src/tools/miri");
1602 let release_num = builder.release_num("miri");
1603 let name = pkgname(builder, "miri");
1604 let version = builder.miri_info.version(builder, &release_num);
1606 let tmp = tmpdir(builder);
1607 let image = tmp.join("miri-image");
1608 drop(fs::remove_dir_all(&image));
1609 builder.create_dir(&image);
1611 // Prepare the image directory
1612 // We expect miri to build, because we've exited this step above if tool
1613 // state for miri isn't testing.
1615 .ensure(tool::Miri { compiler, target, extra_features: Vec::new() })
1617 missing_tool("miri", builder.build.config.missing_tools);
1620 let cargomiri = builder
1621 .ensure(tool::CargoMiri { compiler, target, extra_features: Vec::new() })
1623 missing_tool("cargo miri", builder.build.config.missing_tools);
1627 builder.install(&miri, &image.join("bin"), 0o755);
1628 builder.install(&cargomiri, &image.join("bin"), 0o755);
1629 let doc = image.join("share/doc/miri");
1630 builder.install(&src.join("README.md"), &doc, 0o644);
1631 builder.install(&src.join("LICENSE-APACHE"), &doc, 0o644);
1632 builder.install(&src.join("LICENSE-MIT"), &doc, 0o644);
1634 // Prepare the overlay
1635 let overlay = tmp.join("miri-overlay");
1636 drop(fs::remove_dir_all(&overlay));
1637 t!(fs::create_dir_all(&overlay));
1638 builder.install(&src.join("README.md"), &overlay, 0o644);
1639 builder.install(&src.join("LICENSE-APACHE"), &doc, 0o644);
1640 builder.install(&src.join("LICENSE-MIT"), &doc, 0o644);
1641 builder.create(&overlay.join("version"), &version);
1643 // Generate the installer tarball
1644 let mut cmd = rust_installer(builder);
1646 .arg("--product-name=Rust")
1647 .arg("--rel-manifest-dir=rustlib")
1648 .arg("--success-message=miri-ready-to-serve.")
1652 .arg(&tmpdir(builder))
1653 .arg("--output-dir")
1654 .arg(&distdir(builder))
1655 .arg("--non-installed-overlay")
1657 .arg(format!("--package-name={}-{}", name, target.triple))
1658 .arg("--legacy-manifest-dirs=rustlib,cargo")
1659 .arg("--component-name=miri-preview");
1661 builder.info(&format!("Dist miri stage{} ({})", compiler.stage, target));
1662 let _time = timeit(builder);
1663 builder.run(&mut cmd);
1664 Some(distdir(builder).join(format!("{}-{}.tar.gz", name, target.triple)))
1668 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
1669 pub struct Rustfmt {
1670 pub compiler: Compiler,
1671 pub target: TargetSelection,
1674 impl Step for Rustfmt {
1675 type Output = Option<PathBuf>;
1676 const ONLY_HOSTS: bool = true;
1678 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1682 fn make_run(run: RunConfig<'_>) {
1683 run.builder.ensure(Rustfmt {
1684 compiler: run.builder.compiler_for(
1685 run.builder.top_stage,
1686 run.builder.config.build,
1693 fn run(self, builder: &Builder<'_>) -> Option<PathBuf> {
1694 let compiler = self.compiler;
1695 let target = self.target;
1697 let src = builder.src.join("src/tools/rustfmt");
1698 let release_num = builder.release_num("rustfmt");
1699 let name = pkgname(builder, "rustfmt");
1700 let version = builder.rustfmt_info.version(builder, &release_num);
1702 let tmp = tmpdir(builder);
1703 let image = tmp.join("rustfmt-image");
1704 drop(fs::remove_dir_all(&image));
1705 builder.create_dir(&image);
1707 // Prepare the image directory
1708 let rustfmt = builder
1709 .ensure(tool::Rustfmt { compiler, target, extra_features: Vec::new() })
1711 missing_tool("Rustfmt", builder.build.config.missing_tools);
1714 let cargofmt = builder
1715 .ensure(tool::Cargofmt { compiler, target, extra_features: Vec::new() })
1717 missing_tool("Cargofmt", builder.build.config.missing_tools);
1721 builder.install(&rustfmt, &image.join("bin"), 0o755);
1722 builder.install(&cargofmt, &image.join("bin"), 0o755);
1723 let doc = image.join("share/doc/rustfmt");
1724 builder.install(&src.join("README.md"), &doc, 0o644);
1725 builder.install(&src.join("LICENSE-MIT"), &doc, 0o644);
1726 builder.install(&src.join("LICENSE-APACHE"), &doc, 0o644);
1728 // Prepare the overlay
1729 let overlay = tmp.join("rustfmt-overlay");
1730 drop(fs::remove_dir_all(&overlay));
1731 builder.create_dir(&overlay);
1732 builder.install(&src.join("README.md"), &overlay, 0o644);
1733 builder.install(&src.join("LICENSE-MIT"), &overlay, 0o644);
1734 builder.install(&src.join("LICENSE-APACHE"), &overlay, 0o644);
1735 builder.create(&overlay.join("version"), &version);
1737 // Generate the installer tarball
1738 let mut cmd = rust_installer(builder);
1740 .arg("--product-name=Rust")
1741 .arg("--rel-manifest-dir=rustlib")
1742 .arg("--success-message=rustfmt-ready-to-fmt.")
1746 .arg(&tmpdir(builder))
1747 .arg("--output-dir")
1748 .arg(&distdir(builder))
1749 .arg("--non-installed-overlay")
1751 .arg(format!("--package-name={}-{}", name, target.triple))
1752 .arg("--legacy-manifest-dirs=rustlib,cargo")
1753 .arg("--component-name=rustfmt-preview");
1755 builder.info(&format!("Dist Rustfmt stage{} ({})", compiler.stage, target));
1756 let _time = timeit(builder);
1757 builder.run(&mut cmd);
1758 Some(distdir(builder).join(format!("{}-{}.tar.gz", name, target.triple)))
1762 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
1763 pub struct Extended {
1765 host: TargetSelection,
1766 target: TargetSelection,
1769 impl Step for Extended {
1771 const DEFAULT: bool = true;
1772 const ONLY_HOSTS: bool = true;
1774 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1775 let builder = run.builder;
1776 run.path("extended").default_condition(builder.config.extended)
1779 fn make_run(run: RunConfig<'_>) {
1780 run.builder.ensure(Extended {
1781 stage: run.builder.top_stage,
1782 host: run.builder.config.build,
1787 /// Creates a combined installer for the specified target in the provided stage.
1788 fn run(self, builder: &Builder<'_>) {
1789 let target = self.target;
1790 let stage = self.stage;
1791 let compiler = builder.compiler_for(self.stage, self.host, self.target);
1793 builder.info(&format!("Dist extended stage{} ({})", compiler.stage, target));
1795 let rustc_installer = builder.ensure(Rustc { compiler: builder.compiler(stage, target) });
1796 let cargo_installer = builder.ensure(Cargo { compiler, target });
1797 let rustfmt_installer = builder.ensure(Rustfmt { compiler, target });
1798 let rls_installer = builder.ensure(Rls { compiler, target });
1799 let rust_analyzer_installer = builder.ensure(RustAnalyzer { compiler, target });
1800 let llvm_tools_installer = builder.ensure(LlvmTools { target });
1801 let clippy_installer = builder.ensure(Clippy { compiler, target });
1802 let miri_installer = builder.ensure(Miri { compiler, target });
1803 let mingw_installer = builder.ensure(Mingw { host: target });
1804 let analysis_installer = builder.ensure(Analysis { compiler, target });
1806 let docs_installer = builder.ensure(Docs { host: target });
1808 builder.ensure(Std { compiler: builder.compiler(stage, target), target });
1810 let tmp = tmpdir(builder);
1811 let overlay = tmp.join("extended-overlay");
1812 let etc = builder.src.join("src/etc/installer");
1813 let work = tmp.join("work");
1815 let _ = fs::remove_dir_all(&overlay);
1816 builder.install(&builder.src.join("COPYRIGHT"), &overlay, 0o644);
1817 builder.install(&builder.src.join("LICENSE-APACHE"), &overlay, 0o644);
1818 builder.install(&builder.src.join("LICENSE-MIT"), &overlay, 0o644);
1819 let version = builder.rust_version();
1820 builder.create(&overlay.join("version"), &version);
1821 if let Some(sha) = builder.rust_sha() {
1822 builder.create(&overlay.join("git-commit-hash"), &sha);
1824 builder.install(&etc.join("README.md"), &overlay, 0o644);
1826 // When rust-std package split from rustc, we needed to ensure that during
1827 // upgrades rustc was upgraded before rust-std. To avoid rustc clobbering
1828 // the std files during uninstall. To do this ensure that rustc comes
1829 // before rust-std in the list below.
1830 let mut tarballs = Vec::new();
1831 tarballs.push(rustc_installer);
1832 tarballs.push(cargo_installer);
1833 tarballs.extend(rls_installer.clone());
1834 tarballs.extend(rust_analyzer_installer.clone());
1835 tarballs.push(clippy_installer);
1836 tarballs.extend(miri_installer.clone());
1837 tarballs.extend(rustfmt_installer.clone());
1838 tarballs.extend(llvm_tools_installer);
1839 tarballs.push(analysis_installer);
1840 tarballs.push(std_installer);
1841 if builder.config.docs {
1842 tarballs.push(docs_installer);
1844 if target.contains("pc-windows-gnu") {
1845 tarballs.push(mingw_installer.unwrap());
1847 let mut input_tarballs = tarballs[0].as_os_str().to_owned();
1848 for tarball in &tarballs[1..] {
1849 input_tarballs.push(",");
1850 input_tarballs.push(tarball);
1853 builder.info("building combined installer");
1854 let mut cmd = rust_installer(builder);
1856 .arg("--product-name=Rust")
1857 .arg("--rel-manifest-dir=rustlib")
1858 .arg("--success-message=Rust-is-ready-to-roll.")
1861 .arg("--output-dir")
1862 .arg(&distdir(builder))
1863 .arg(format!("--package-name={}-{}", pkgname(builder, "rust"), target.triple))
1864 .arg("--legacy-manifest-dirs=rustlib,cargo")
1865 .arg("--input-tarballs")
1866 .arg(input_tarballs)
1867 .arg("--non-installed-overlay")
1869 let time = timeit(&builder);
1870 builder.run(&mut cmd);
1873 let mut license = String::new();
1874 license += &builder.read(&builder.src.join("COPYRIGHT"));
1875 license += &builder.read(&builder.src.join("LICENSE-APACHE"));
1876 license += &builder.read(&builder.src.join("LICENSE-MIT"));
1877 license.push_str("\n");
1878 license.push_str("\n");
1880 let rtf = r"{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 Arial;}}\nowwrap\fs18";
1881 let mut rtf = rtf.to_string();
1883 for line in license.lines() {
1885 rtf.push_str("\\line ");
1889 fn filter(contents: &str, marker: &str) -> String {
1890 let start = format!("tool-{}-start", marker);
1891 let end = format!("tool-{}-end", marker);
1892 let mut lines = Vec::new();
1893 let mut omitted = false;
1894 for line in contents.lines() {
1895 if line.contains(&start) {
1897 } else if line.contains(&end) {
1899 } else if !omitted {
1907 let xform = |p: &Path| {
1908 let mut contents = t!(fs::read_to_string(p));
1909 if rls_installer.is_none() {
1910 contents = filter(&contents, "rls");
1912 if rust_analyzer_installer.is_none() {
1913 contents = filter(&contents, "rust-analyzer");
1915 if miri_installer.is_none() {
1916 contents = filter(&contents, "miri");
1918 if rustfmt_installer.is_none() {
1919 contents = filter(&contents, "rustfmt");
1921 let ret = tmp.join(p.file_name().unwrap());
1922 t!(fs::write(&ret, &contents));
1926 if target.contains("apple-darwin") {
1927 builder.info("building pkg installer");
1928 let pkg = tmp.join("pkg");
1929 let _ = fs::remove_dir_all(&pkg);
1931 let pkgbuild = |component: &str| {
1932 let mut cmd = Command::new("pkgbuild");
1933 cmd.arg("--identifier")
1934 .arg(format!("org.rust-lang.{}", component))
1936 .arg(pkg.join(component))
1938 .arg(pkg.join(component).with_extension("pkg"));
1939 builder.run(&mut cmd);
1942 let prepare = |name: &str| {
1943 builder.create_dir(&pkg.join(name));
1945 &work.join(&format!("{}-{}", pkgname(builder, name), target.triple)),
1948 builder.install(&etc.join("pkg/postinstall"), &pkg.join(name), 0o755);
1953 prepare("rust-docs");
1954 prepare("rust-std");
1955 prepare("rust-analysis");
1958 if rls_installer.is_some() {
1961 if rust_analyzer_installer.is_some() {
1962 prepare("rust-analyzer");
1964 if miri_installer.is_some() {
1968 // create an 'uninstall' package
1969 builder.install(&etc.join("pkg/postinstall"), &pkg.join("uninstall"), 0o755);
1970 pkgbuild("uninstall");
1972 builder.create_dir(&pkg.join("res"));
1973 builder.create(&pkg.join("res/LICENSE.txt"), &license);
1974 builder.install(&etc.join("gfx/rust-logo.png"), &pkg.join("res"), 0o644);
1975 let mut cmd = Command::new("productbuild");
1976 cmd.arg("--distribution")
1977 .arg(xform(&etc.join("pkg/Distribution.xml")))
1979 .arg(pkg.join("res"))
1980 .arg(distdir(builder).join(format!(
1982 pkgname(builder, "rust"),
1985 .arg("--package-path")
1987 let _time = timeit(builder);
1988 builder.run(&mut cmd);
1991 if target.contains("windows") {
1992 let exe = tmp.join("exe");
1993 let _ = fs::remove_dir_all(&exe);
1995 let prepare = |name: &str| {
1996 builder.create_dir(&exe.join(name));
1997 let dir = if name == "rust-std" || name == "rust-analysis" {
1998 format!("{}-{}", name, target.triple)
1999 } else if name == "rls" {
2000 "rls-preview".to_string()
2001 } else if name == "rust-analyzer" {
2002 "rust-analyzer-preview".to_string()
2003 } else if name == "clippy" {
2004 "clippy-preview".to_string()
2005 } else if name == "miri" {
2006 "miri-preview".to_string()
2011 &work.join(&format!("{}-{}", pkgname(builder, name), target.triple)).join(dir),
2014 builder.remove(&exe.join(name).join("manifest.in"));
2018 prepare("rust-analysis");
2019 prepare("rust-docs");
2020 prepare("rust-std");
2022 if rls_installer.is_some() {
2025 if rust_analyzer_installer.is_some() {
2026 prepare("rust-analyzer");
2028 if miri_installer.is_some() {
2031 if target.contains("windows-gnu") {
2032 prepare("rust-mingw");
2035 builder.install(&etc.join("gfx/rust-logo.ico"), &exe, 0o644);
2037 // Generate msi installer
2038 let wix = PathBuf::from(env::var_os("WIX").unwrap());
2039 let heat = wix.join("bin/heat.exe");
2040 let candle = wix.join("bin/candle.exe");
2041 let light = wix.join("bin/light.exe");
2043 let heat_flags = ["-nologo", "-gg", "-sfrag", "-srd", "-sreg"];
2055 .arg("var.RustcDir")
2057 .arg(exe.join("RustcGroup.wxs")),
2072 .arg(exe.join("DocsGroup.wxs"))
2074 .arg(etc.join("msi/squash-components.xsl")),
2087 .arg("var.CargoDir")
2089 .arg(exe.join("CargoGroup.wxs"))
2091 .arg(etc.join("msi/remove-duplicates.xsl")),
2106 .arg(exe.join("StdGroup.wxs")),
2108 if rls_installer.is_some() {
2122 .arg(exe.join("RlsGroup.wxs"))
2124 .arg(etc.join("msi/remove-duplicates.xsl")),
2127 if rust_analyzer_installer.is_some() {
2132 .arg("rust-analyzer")
2135 .arg("RustAnalyzerGroup")
2137 .arg("RustAnalyzer")
2139 .arg("var.RustAnalyzerDir")
2141 .arg(exe.join("RustAnalyzerGroup.wxs"))
2143 .arg(etc.join("msi/remove-duplicates.xsl")),
2157 .arg("var.ClippyDir")
2159 .arg(exe.join("ClippyGroup.wxs"))
2161 .arg(etc.join("msi/remove-duplicates.xsl")),
2163 if miri_installer.is_some() {
2177 .arg(exe.join("MiriGroup.wxs"))
2179 .arg(etc.join("msi/remove-duplicates.xsl")),
2186 .arg("rust-analysis")
2189 .arg("AnalysisGroup")
2193 .arg("var.AnalysisDir")
2195 .arg(exe.join("AnalysisGroup.wxs"))
2197 .arg(etc.join("msi/remove-duplicates.xsl")),
2199 if target.contains("windows-gnu") {
2213 .arg(exe.join("GccGroup.wxs")),
2217 let candle = |input: &Path| {
2218 let output = exe.join(input.file_stem().unwrap()).with_extension("wixobj");
2219 let arch = if target.contains("x86_64") { "x64" } else { "x86" };
2220 let mut cmd = Command::new(&candle);
2221 cmd.current_dir(&exe)
2223 .arg("-dRustcDir=rustc")
2224 .arg("-dDocsDir=rust-docs")
2225 .arg("-dCargoDir=cargo")
2226 .arg("-dStdDir=rust-std")
2227 .arg("-dAnalysisDir=rust-analysis")
2228 .arg("-dClippyDir=clippy")
2234 add_env(builder, &mut cmd, target);
2236 if rls_installer.is_some() {
2237 cmd.arg("-dRlsDir=rls");
2239 if rust_analyzer_installer.is_some() {
2240 cmd.arg("-dRustAnalyzerDir=rust-analyzer");
2242 if miri_installer.is_some() {
2243 cmd.arg("-dMiriDir=miri");
2245 if target.contains("windows-gnu") {
2246 cmd.arg("-dGccDir=rust-mingw");
2248 builder.run(&mut cmd);
2250 candle(&xform(&etc.join("msi/rust.wxs")));
2251 candle(&etc.join("msi/ui.wxs"));
2252 candle(&etc.join("msi/rustwelcomedlg.wxs"));
2253 candle("RustcGroup.wxs".as_ref());
2254 candle("DocsGroup.wxs".as_ref());
2255 candle("CargoGroup.wxs".as_ref());
2256 candle("StdGroup.wxs".as_ref());
2257 candle("ClippyGroup.wxs".as_ref());
2258 if rls_installer.is_some() {
2259 candle("RlsGroup.wxs".as_ref());
2261 if rust_analyzer_installer.is_some() {
2262 candle("RustAnalyzerGroup.wxs".as_ref());
2264 if miri_installer.is_some() {
2265 candle("MiriGroup.wxs".as_ref());
2267 candle("AnalysisGroup.wxs".as_ref());
2269 if target.contains("windows-gnu") {
2270 candle("GccGroup.wxs".as_ref());
2273 builder.create(&exe.join("LICENSE.rtf"), &rtf);
2274 builder.install(&etc.join("gfx/banner.bmp"), &exe, 0o644);
2275 builder.install(&etc.join("gfx/dialogbg.bmp"), &exe, 0o644);
2277 builder.info(&format!("building `msi` installer with {:?}", light));
2278 let filename = format!("{}-{}.msi", pkgname(builder, "rust"), target.triple);
2279 let mut cmd = Command::new(&light);
2282 .arg("WixUIExtension")
2284 .arg("WixUtilExtension")
2286 .arg(exe.join(&filename))
2289 .arg("rustwelcomedlg.wixobj")
2290 .arg("RustcGroup.wixobj")
2291 .arg("DocsGroup.wixobj")
2292 .arg("CargoGroup.wixobj")
2293 .arg("StdGroup.wixobj")
2294 .arg("AnalysisGroup.wixobj")
2295 .arg("ClippyGroup.wixobj")
2298 if rls_installer.is_some() {
2299 cmd.arg("RlsGroup.wixobj");
2301 if rust_analyzer_installer.is_some() {
2302 cmd.arg("RustAnalyzerGroup.wixobj");
2304 if miri_installer.is_some() {
2305 cmd.arg("MiriGroup.wixobj");
2308 if target.contains("windows-gnu") {
2309 cmd.arg("GccGroup.wixobj");
2311 // ICE57 wrongly complains about the shortcuts
2312 cmd.arg("-sice:ICE57");
2314 let _time = timeit(builder);
2315 builder.run(&mut cmd);
2317 if !builder.config.dry_run {
2318 t!(fs::rename(exe.join(&filename), distdir(builder).join(&filename)));
2324 fn add_env(builder: &Builder<'_>, cmd: &mut Command, target: TargetSelection) {
2325 let mut parts = builder.version.split('.');
2326 cmd.env("CFG_RELEASE_INFO", builder.rust_version())
2327 .env("CFG_RELEASE_NUM", &builder.version)
2328 .env("CFG_RELEASE", builder.rust_release())
2329 .env("CFG_VER_MAJOR", parts.next().unwrap())
2330 .env("CFG_VER_MINOR", parts.next().unwrap())
2331 .env("CFG_VER_PATCH", parts.next().unwrap())
2332 .env("CFG_VER_BUILD", "0") // just needed to build
2333 .env("CFG_PACKAGE_VERS", builder.rust_package_vers())
2334 .env("CFG_PACKAGE_NAME", pkgname(builder, "rust"))
2335 .env("CFG_BUILD", target.triple)
2336 .env("CFG_CHANNEL", &builder.config.channel);
2338 if target.contains("windows-gnu") {
2339 cmd.env("CFG_MINGW", "1").env("CFG_ABI", "GNU");
2341 cmd.env("CFG_MINGW", "0").env("CFG_ABI", "MSVC");
2344 if target.contains("x86_64") {
2345 cmd.env("CFG_PLATFORM", "x64");
2347 cmd.env("CFG_PLATFORM", "x86");
2351 /// Maybe add libLLVM.so to the given destination lib-dir. It will only have
2352 /// been built if LLVM tools are linked dynamically.
2354 /// Note: This function does not yet support Windows, but we also don't support
2355 /// linking LLVM tools dynamically on Windows yet.
2356 fn maybe_install_llvm(builder: &Builder<'_>, target: TargetSelection, dst_libdir: &Path) {
2357 if !builder.config.llvm_link_shared {
2358 // We do not need to copy LLVM files into the sysroot if it is not
2359 // dynamically linked; it is already included into librustc_llvm
2364 if let Some(config) = builder.config.target_config.get(&target) {
2365 if config.llvm_config.is_some() && !builder.config.llvm_from_ci {
2366 // If the LLVM was externally provided, then we don't currently copy
2367 // artifacts into the sysroot. This is not necessarily the right
2368 // choice (in particular, it will require the LLVM dylib to be in
2369 // the linker's load path at runtime), but the common use case for
2370 // external LLVMs is distribution provided LLVMs, and in that case
2371 // they're usually in the standard search path (e.g., /usr/lib) and
2372 // copying them here is going to cause problems as we may end up
2373 // with the wrong files and isn't what distributions want.
2375 // This behavior may be revisited in the future though.
2377 // If the LLVM is coming from ourselves (just from CI) though, we
2378 // still want to install it, as it otherwise won't be available.
2383 // On macOS, rustc (and LLVM tools) link to an unversioned libLLVM.dylib
2384 // instead of libLLVM-11-rust-....dylib, as on linux. It's not entirely
2385 // clear why this is the case, though. llvm-config will emit the versioned
2386 // paths and we don't want those in the sysroot (as we're expecting
2387 // unversioned paths).
2388 if target.contains("apple-darwin") {
2389 let src_libdir = builder.llvm_out(target).join("lib");
2390 let llvm_dylib_path = src_libdir.join("libLLVM.dylib");
2391 if llvm_dylib_path.exists() {
2392 builder.install(&llvm_dylib_path, dst_libdir, 0o644);
2394 } else if let Ok(llvm_config) = crate::native::prebuilt_llvm_config(builder, target) {
2395 let files = output(Command::new(llvm_config).arg("--libfiles"));
2396 for file in files.lines() {
2397 builder.install(Path::new(file), dst_libdir, 0o644);
2402 /// Maybe add libLLVM.so to the target lib-dir for linking.
2403 pub fn maybe_install_llvm_target(builder: &Builder<'_>, target: TargetSelection, sysroot: &Path) {
2404 let dst_libdir = sysroot.join("lib/rustlib").join(&*target.triple).join("lib");
2405 maybe_install_llvm(builder, target, &dst_libdir);
2408 /// Maybe add libLLVM.so to the runtime lib-dir for rustc itself.
2409 pub fn maybe_install_llvm_runtime(builder: &Builder<'_>, target: TargetSelection, sysroot: &Path) {
2411 sysroot.join(builder.sysroot_libdir_relative(Compiler { stage: 1, host: target }));
2412 maybe_install_llvm(builder, target, &dst_libdir);
2415 #[derive(Clone, Debug, Eq, Hash, PartialEq)]
2416 pub struct LlvmTools {
2417 pub target: TargetSelection,
2420 impl Step for LlvmTools {
2421 type Output = Option<PathBuf>;
2422 const ONLY_HOSTS: bool = true;
2424 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2425 run.path("llvm-tools")
2428 fn make_run(run: RunConfig<'_>) {
2429 run.builder.ensure(LlvmTools { target: run.target });
2432 fn run(self, builder: &Builder<'_>) -> Option<PathBuf> {
2433 let target = self.target;
2434 assert!(builder.config.extended);
2436 /* run only if llvm-config isn't used */
2437 if let Some(config) = builder.config.target_config.get(&target) {
2438 if let Some(ref _s) = config.llvm_config {
2439 builder.info(&format!("Skipping LlvmTools ({}): external LLVM", target));
2444 builder.info(&format!("Dist LlvmTools ({})", target));
2445 let _time = timeit(builder);
2446 let src = builder.src.join("src/llvm-project/llvm");
2447 let name = pkgname(builder, "llvm-tools");
2449 let tmp = tmpdir(builder);
2450 let image = tmp.join("llvm-tools-image");
2451 drop(fs::remove_dir_all(&image));
2453 // Prepare the image directory
2454 let src_bindir = builder.llvm_out(target).join("bin");
2455 let dst_bindir = image.join("lib/rustlib").join(&*target.triple).join("bin");
2456 t!(fs::create_dir_all(&dst_bindir));
2457 for tool in LLVM_TOOLS {
2458 let exe = src_bindir.join(exe(tool, target));
2459 builder.install(&exe, &dst_bindir, 0o755);
2462 // Copy libLLVM.so to the target lib dir as well, so the RPATH like
2463 // `$ORIGIN/../lib` can find it. It may also be used as a dependency
2464 // of `rustc-dev` to support the inherited `-lLLVM` when using the
2465 // compiler libraries.
2466 maybe_install_llvm_target(builder, target, &image);
2468 // Prepare the overlay
2469 let overlay = tmp.join("llvm-tools-overlay");
2470 drop(fs::remove_dir_all(&overlay));
2471 builder.create_dir(&overlay);
2472 builder.install(&src.join("README.txt"), &overlay, 0o644);
2473 builder.install(&src.join("LICENSE.TXT"), &overlay, 0o644);
2474 builder.create(&overlay.join("version"), &builder.llvm_tools_vers());
2476 // Generate the installer tarball
2477 let mut cmd = rust_installer(builder);
2479 .arg("--product-name=Rust")
2480 .arg("--rel-manifest-dir=rustlib")
2481 .arg("--success-message=llvm-tools-installed.")
2485 .arg(&tmpdir(builder))
2486 .arg("--output-dir")
2487 .arg(&distdir(builder))
2488 .arg("--non-installed-overlay")
2490 .arg(format!("--package-name={}-{}", name, target.triple))
2491 .arg("--legacy-manifest-dirs=rustlib,cargo")
2492 .arg("--component-name=llvm-tools-preview");
2494 builder.run(&mut cmd);
2495 Some(distdir(builder).join(format!("{}-{}.tar.gz", name, target.triple)))
2499 // Tarball intended for internal consumption to ease rustc/std development.
2501 // Should not be considered stable by end users.
2502 #[derive(Clone, Debug, Eq, Hash, PartialEq)]
2503 pub struct RustDev {
2504 pub target: TargetSelection,
2507 impl Step for RustDev {
2508 type Output = Option<PathBuf>;
2509 const DEFAULT: bool = true;
2510 const ONLY_HOSTS: bool = true;
2512 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2513 run.path("rust-dev")
2516 fn make_run(run: RunConfig<'_>) {
2517 run.builder.ensure(RustDev { target: run.target });
2520 fn run(self, builder: &Builder<'_>) -> Option<PathBuf> {
2521 let target = self.target;
2523 /* run only if llvm-config isn't used */
2524 if let Some(config) = builder.config.target_config.get(&target) {
2525 if let Some(ref _s) = config.llvm_config {
2526 builder.info(&format!("Skipping RustDev ({}): external LLVM", target));
2531 builder.info(&format!("Dist RustDev ({})", target));
2532 let _time = timeit(builder);
2533 let src = builder.src.join("src/llvm-project/llvm");
2534 let name = pkgname(builder, "rust-dev");
2536 let tmp = tmpdir(builder);
2537 let image = tmp.join("rust-dev-image");
2538 drop(fs::remove_dir_all(&image));
2540 // Prepare the image directory
2541 let dst_bindir = image.join("bin");
2542 t!(fs::create_dir_all(&dst_bindir));
2544 let src_bindir = builder.llvm_out(target).join("bin");
2546 |name| builder.install(&src_bindir.join(exe(name, target)), &dst_bindir, 0o755);
2547 install_bin("llvm-config");
2548 install_bin("llvm-ar");
2549 install_bin("llvm-objdump");
2550 install_bin("llvm-profdata");
2551 install_bin("llvm-bcanalyzer");
2552 install_bin("llvm-cov");
2553 builder.install(&builder.llvm_filecheck(target), &dst_bindir, 0o755);
2555 // Copy the include directory as well; needed mostly to build
2556 // librustc_llvm properly (e.g., llvm-config.h is in here). But also
2557 // just broadly useful to be able to link against the bundled LLVM.
2558 builder.cp_r(&builder.llvm_out(target).join("include"), &image.join("include"));
2560 // Copy libLLVM.so to the target lib dir as well, so the RPATH like
2561 // `$ORIGIN/../lib` can find it. It may also be used as a dependency
2562 // of `rustc-dev` to support the inherited `-lLLVM` when using the
2563 // compiler libraries.
2564 maybe_install_llvm(builder, target, &image.join("lib"));
2566 // Prepare the overlay
2567 let overlay = tmp.join("rust-dev-overlay");
2568 drop(fs::remove_dir_all(&overlay));
2569 builder.create_dir(&overlay);
2570 builder.install(&src.join("README.txt"), &overlay, 0o644);
2571 builder.install(&src.join("LICENSE.TXT"), &overlay, 0o644);
2572 builder.create(&overlay.join("version"), &builder.rust_version());
2574 // Generate the installer tarball
2575 let mut cmd = rust_installer(builder);
2577 .arg("--product-name=Rust")
2578 .arg("--rel-manifest-dir=rustlib")
2579 .arg("--success-message=rust-dev-installed.")
2583 .arg(&tmpdir(builder))
2584 .arg("--output-dir")
2585 .arg(&distdir(builder))
2586 .arg("--non-installed-overlay")
2588 .arg(format!("--package-name={}-{}", name, target.triple))
2589 .arg("--legacy-manifest-dirs=rustlib,cargo")
2590 .arg("--component-name=rust-dev");
2592 builder.run(&mut cmd);
2593 Some(distdir(builder).join(format!("{}-{}.tar.gz", name, target.triple)))
2597 /// Tarball containing a prebuilt version of the build-manifest tool, intented to be used by the
2598 /// release process to avoid cloning the monorepo and building stuff.
2600 /// Should not be considered stable by end users.
2601 #[derive(Clone, Debug, Eq, Hash, PartialEq)]
2602 pub struct BuildManifest {
2603 pub target: TargetSelection,
2606 impl Step for BuildManifest {
2607 type Output = PathBuf;
2608 const DEFAULT: bool = false;
2609 const ONLY_HOSTS: bool = true;
2611 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2612 run.path("src/tools/build-manifest")
2615 fn make_run(run: RunConfig<'_>) {
2616 run.builder.ensure(BuildManifest { target: run.target });
2619 fn run(self, builder: &Builder<'_>) -> PathBuf {
2620 let build_manifest = builder.tool_exe(Tool::BuildManifest);
2622 let name = pkgname(builder, "build-manifest");
2623 let tmp = tmpdir(builder);
2625 // Prepare the image.
2626 let image = tmp.join("build-manifest-image");
2627 let image_bin = image.join("bin");
2628 let _ = fs::remove_dir_all(&image);
2629 t!(fs::create_dir_all(&image_bin));
2630 builder.install(&build_manifest, &image_bin, 0o755);
2632 // Prepare the overlay.
2633 let overlay = tmp.join("build-manifest-overlay");
2634 let _ = fs::remove_dir_all(&overlay);
2635 builder.create_dir(&overlay);
2636 builder.create(&overlay.join("version"), &builder.rust_version());
2637 for file in &["COPYRIGHT", "LICENSE-APACHE", "LICENSE-MIT", "README.md"] {
2638 builder.install(&builder.src.join(file), &overlay, 0o644);
2641 // Create the final tarball.
2642 let mut cmd = rust_installer(builder);
2644 .arg("--product-name=Rust")
2645 .arg("--rel-manifest-dir=rustlib")
2646 .arg("--success-message=build-manifest installed.")
2650 .arg(&tmpdir(builder))
2651 .arg("--output-dir")
2652 .arg(&distdir(builder))
2653 .arg("--non-installed-overlay")
2655 .arg(format!("--package-name={}-{}", name, self.target.triple))
2656 .arg("--legacy-manifest-dirs=rustlib,cargo")
2657 .arg("--component-name=build-manifest");
2659 builder.run(&mut cmd);
2660 distdir(builder).join(format!("{}-{}.tar.gz", name, self.target.triple))