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`!
11 use std::collections::HashSet;
14 use std::path::{Path, PathBuf};
15 use std::process::Command;
17 use crate::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
18 use crate::cache::{Interned, INTERNER};
20 use crate::config::TargetSelection;
21 use crate::tarball::{GeneratedTarball, OverlayKind, Tarball};
22 use crate::tool::{self, Tool};
23 use crate::util::{exe, is_dylib, output, t, timeit};
24 use crate::{Compiler, DependencyType, Mode, LLVM_TOOLS};
26 pub fn pkgname(builder: &Builder<'_>, component: &str) -> String {
27 format!("{}-{}", component, builder.rust_package_vers())
30 pub(crate) fn distdir(builder: &Builder<'_>) -> PathBuf {
31 builder.out.join("dist")
34 pub fn tmpdir(builder: &Builder<'_>) -> PathBuf {
35 builder.out.join("tmp/dist")
38 fn missing_tool(tool_name: &str, skip: bool) {
40 println!("Unable to build {}, skipping dist", tool_name)
42 let help = "note: not all tools are available on all nightlies\nhelp: see https://forge.rust-lang.org/infra/toolstate.html for more information";
44 "Unable to build submodule tool {} (use `missing-tools = true` to ignore this failure)\n{}",
50 fn should_build_extended_tool(builder: &Builder<'_>, tool: &str) -> bool {
51 if !builder.config.extended {
54 builder.config.tools.as_ref().map_or(true, |tools| tools.contains(tool))
57 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
59 pub host: TargetSelection,
63 type Output = Option<GeneratedTarball>;
64 const DEFAULT: bool = true;
66 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
67 let default = run.builder.config.docs;
68 run.alias("rust-docs").default_condition(default)
71 fn make_run(run: RunConfig<'_>) {
72 run.builder.ensure(Docs { host: run.target });
75 /// Builds the `rust-docs` installer component.
76 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
78 builder.default_doc(&[]);
80 let dest = "share/doc/rust/html";
82 let mut tarball = Tarball::new(builder, "rust-docs", &host.triple);
83 tarball.set_product_name("Rust Documentation");
84 tarball.add_bulk_dir(&builder.doc_out(host), dest);
85 tarball.add_file(&builder.src.join("src/doc/robots.txt"), dest, 0o644);
86 Some(tarball.generate())
90 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
91 pub struct RustcDocs {
92 pub host: TargetSelection,
95 impl Step for RustcDocs {
96 type Output = Option<GeneratedTarball>;
97 const DEFAULT: bool = true;
99 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
100 let builder = run.builder;
101 run.alias("rustc-docs").default_condition(builder.config.compiler_docs)
104 fn make_run(run: RunConfig<'_>) {
105 run.builder.ensure(RustcDocs { host: run.target });
108 /// Builds the `rustc-docs` installer component.
109 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
110 let host = self.host;
111 builder.default_doc(&[]);
113 let mut tarball = Tarball::new(builder, "rustc-docs", &host.triple);
114 tarball.set_product_name("Rustc Documentation");
115 tarball.add_bulk_dir(&builder.compiler_doc_out(host), "share/doc/rust/html/rustc");
116 Some(tarball.generate())
120 fn find_files(files: &[&str], path: &[PathBuf]) -> Vec<PathBuf> {
121 let mut found = Vec::with_capacity(files.len());
124 let file_path = path.iter().map(|dir| dir.join(file)).find(|p| p.exists());
126 if let Some(file_path) = file_path {
127 found.push(file_path);
129 panic!("Could not find '{}' in {:?}", file, path);
139 target: TargetSelection,
140 builder: &Builder<'_>,
142 //Ask gcc where it keeps its stuff
143 let mut cmd = Command::new(builder.cc(target));
144 cmd.arg("-print-search-dirs");
145 let gcc_out = output(&mut cmd);
147 let mut bin_path: Vec<_> = env::split_paths(&env::var_os("PATH").unwrap_or_default()).collect();
148 let mut lib_path = Vec::new();
150 for line in gcc_out.lines() {
151 let idx = line.find(':').unwrap();
152 let key = &line[..idx];
153 let trim_chars: &[_] = &[' ', '='];
154 let value = env::split_paths(line[(idx + 1)..].trim_start_matches(trim_chars));
156 if key == "programs" {
157 bin_path.extend(value);
158 } else if key == "libraries" {
159 lib_path.extend(value);
163 let compiler = if target == "i686-pc-windows-gnu" {
164 "i686-w64-mingw32-gcc.exe"
165 } else if target == "x86_64-pc-windows-gnu" {
166 "x86_64-w64-mingw32-gcc.exe"
170 let target_tools = [compiler, "ld.exe", "dlltool.exe", "libwinpthread-1.dll"];
171 let mut rustc_dlls = vec!["libwinpthread-1.dll"];
172 if target.starts_with("i686-") {
173 rustc_dlls.push("libgcc_s_dw2-1.dll");
175 rustc_dlls.push("libgcc_s_seh-1.dll");
190 //Windows import libs
213 "libsynchronization.a",
224 //Find mingw artifacts we want to bundle
225 let target_tools = find_files(&target_tools, &bin_path);
226 let rustc_dlls = find_files(&rustc_dlls, &bin_path);
227 let target_libs = find_files(&target_libs, &lib_path);
229 // Copy runtime dlls next to rustc.exe
230 let dist_bin_dir = rust_root.join("bin/");
231 fs::create_dir_all(&dist_bin_dir).expect("creating dist_bin_dir failed");
232 for src in rustc_dlls {
233 builder.copy_to_folder(&src, &dist_bin_dir);
236 //Copy platform tools to platform-specific bin directory
237 let target_bin_dir = plat_root
242 .join("self-contained");
243 fs::create_dir_all(&target_bin_dir).expect("creating target_bin_dir failed");
244 for src in target_tools {
245 builder.copy_to_folder(&src, &target_bin_dir);
248 // Warn windows-gnu users that the bundled GCC cannot compile C files
250 &target_bin_dir.join("GCC-WARNING.txt"),
251 "gcc.exe contained in this folder cannot be used for compiling C files - it is only \
252 used as a linker. In order to be able to compile projects containing C code use \
253 the GCC provided by MinGW or Cygwin.",
256 //Copy platform libs to platform-specific lib directory
257 let target_lib_dir = plat_root
262 .join("self-contained");
263 fs::create_dir_all(&target_lib_dir).expect("creating target_lib_dir failed");
264 for src in target_libs {
265 builder.copy_to_folder(&src, &target_lib_dir);
269 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
271 pub host: TargetSelection,
274 impl Step for Mingw {
275 type Output = Option<GeneratedTarball>;
276 const DEFAULT: bool = true;
278 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
279 run.alias("rust-mingw")
282 fn make_run(run: RunConfig<'_>) {
283 run.builder.ensure(Mingw { host: run.target });
286 /// Builds the `rust-mingw` installer component.
288 /// This contains all the bits and pieces to run the MinGW Windows targets
289 /// without any extra installed software (e.g., we bundle gcc, libraries, etc).
290 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
291 let host = self.host;
292 if !host.ends_with("pc-windows-gnu") {
296 let mut tarball = Tarball::new(builder, "rust-mingw", &host.triple);
297 tarball.set_product_name("Rust MinGW");
299 // The first argument is a "temporary directory" which is just
300 // thrown away (this contains the runtime DLLs included in the rustc package
301 // above) and the second argument is where to place all the MinGW components
302 // (which is what we want).
303 make_win_dist(&tmpdir(builder), tarball.image_dir(), host, &builder);
305 Some(tarball.generate())
309 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
311 pub compiler: Compiler,
314 impl Step for Rustc {
315 type Output = GeneratedTarball;
316 const DEFAULT: bool = true;
317 const ONLY_HOSTS: bool = true;
319 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
323 fn make_run(run: RunConfig<'_>) {
325 .ensure(Rustc { compiler: run.builder.compiler(run.builder.top_stage, run.target) });
328 /// Creates the `rustc` installer component.
329 fn run(self, builder: &Builder<'_>) -> GeneratedTarball {
330 let compiler = self.compiler;
331 let host = self.compiler.host;
333 let tarball = Tarball::new(builder, "rustc", &host.triple);
335 // Prepare the rustc "image", what will actually end up getting installed
336 prepare_image(builder, compiler, tarball.image_dir());
338 // On MinGW we've got a few runtime DLL dependencies that we need to
339 // include. The first argument to this script is where to put these DLLs
340 // (the image we're creating), and the second argument is a junk directory
341 // to ignore all other MinGW stuff the script creates.
343 // On 32-bit MinGW we're always including a DLL which needs some extra
344 // licenses to distribute. On 64-bit MinGW we don't actually distribute
345 // anything requiring us to distribute a license, but it's likely the
346 // install will *also* include the rust-mingw package, which also needs
347 // licenses, so to be safe we just include it here in all MinGW packages.
348 if host.ends_with("pc-windows-gnu") {
349 make_win_dist(tarball.image_dir(), &tmpdir(builder), host, builder);
350 tarball.add_dir(builder.src.join("src/etc/third-party"), "share/doc");
353 return tarball.generate();
355 fn prepare_image(builder: &Builder<'_>, compiler: Compiler, image: &Path) {
356 let host = compiler.host;
357 let src = builder.sysroot(compiler);
359 // Copy rustc/rustdoc binaries
360 t!(fs::create_dir_all(image.join("bin")));
361 builder.cp_r(&src.join("bin"), &image.join("bin"));
363 builder.install(&builder.rustdoc(compiler), &image.join("bin"), 0o755);
365 let ra_proc_macro_srv = builder
366 .ensure(tool::RustAnalyzerProcMacroSrv {
367 compiler: builder.compiler_for(
369 builder.config.build,
372 target: compiler.host,
374 .expect("rust-analyzer-proc-macro-server always builds");
375 builder.install(&ra_proc_macro_srv, &image.join("libexec"), 0o755);
377 let libdir_relative = builder.libdir_relative(compiler);
379 // Copy runtime DLLs needed by the compiler
380 if libdir_relative.to_str() != Some("bin") {
381 let libdir = builder.rustc_libdir(compiler);
382 for entry in builder.read_dir(&libdir) {
383 let name = entry.file_name();
384 if let Some(s) = name.to_str() {
386 // Don't use custom libdir here because ^lib/ will be resolved again
388 builder.install(&entry.path(), &image.join("lib"), 0o644);
394 // Copy over the codegen backends
395 let backends_src = builder.sysroot_codegen_backends(compiler);
396 let backends_rel = backends_src
399 .strip_prefix(builder.sysroot_libdir_relative(compiler))
401 // Don't use custom libdir here because ^lib/ will be resolved again with installer
402 let backends_dst = image.join("lib").join(&backends_rel);
404 t!(fs::create_dir_all(&backends_dst));
405 builder.cp_r(&backends_src, &backends_dst);
407 // Copy libLLVM.so to the lib dir as well, if needed. While not
408 // technically needed by rustc itself it's needed by lots of other
409 // components like the llvm tools and LLD. LLD is included below and
410 // tools/LLDB come later, so let's just throw it in the rustc
411 // component for now.
412 maybe_install_llvm_runtime(builder, host, image);
414 let dst_dir = image.join("lib/rustlib").join(&*host.triple).join("bin");
415 t!(fs::create_dir_all(&dst_dir));
417 // Copy over lld if it's there
418 if builder.config.lld_enabled {
419 let src_dir = builder.sysroot_libdir(compiler, host).parent().unwrap().join("bin");
420 let rust_lld = exe("rust-lld", compiler.host);
421 builder.copy(&src_dir.join(&rust_lld), &dst_dir.join(&rust_lld));
422 // for `-Z gcc-ld=lld`
423 let gcc_lld_src_dir = src_dir.join("gcc-ld");
424 let gcc_lld_dst_dir = dst_dir.join("gcc-ld");
425 t!(fs::create_dir(&gcc_lld_dst_dir));
426 let exe_name = exe("ld", compiler.host);
427 builder.copy(&gcc_lld_src_dir.join(&exe_name), &gcc_lld_dst_dir.join(&exe_name));
431 t!(fs::create_dir_all(image.join("share/man/man1")));
432 let man_src = builder.src.join("src/doc/man");
433 let man_dst = image.join("share/man/man1");
435 // don't use our `bootstrap::util::{copy, cp_r}`, because those try
436 // to hardlink, and we don't want to edit the source templates
437 for file_entry in builder.read_dir(&man_src) {
438 let page_src = file_entry.path();
439 let page_dst = man_dst.join(file_entry.file_name());
440 let src_text = t!(std::fs::read_to_string(&page_src));
441 let new_text = src_text.replace("<INSERT VERSION HERE>", &builder.version);
442 t!(std::fs::write(&page_dst, &new_text));
443 t!(fs::copy(&page_src, &page_dst));
448 .ensure(DebuggerScripts { sysroot: INTERNER.intern_path(image.to_owned()), host });
451 let cp = |file: &str| {
452 builder.install(&builder.src.join(file), &image.join("share/doc/rust"), 0o644);
455 cp("LICENSE-APACHE");
462 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
463 pub struct DebuggerScripts {
464 pub sysroot: Interned<PathBuf>,
465 pub host: TargetSelection,
468 impl Step for DebuggerScripts {
471 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
475 /// Copies debugger scripts for `target` into the `sysroot` specified.
476 fn run(self, builder: &Builder<'_>) {
477 let host = self.host;
478 let sysroot = self.sysroot;
479 let dst = sysroot.join("lib/rustlib/etc");
480 t!(fs::create_dir_all(&dst));
481 let cp_debugger_script = |file: &str| {
482 builder.install(&builder.src.join("src/etc/").join(file), &dst, 0o644);
484 if host.contains("windows-msvc") {
485 // windbg debugger scripts
487 &builder.src.join("src/etc/rust-windbg.cmd"),
488 &sysroot.join("bin"),
492 cp_debugger_script("natvis/intrinsic.natvis");
493 cp_debugger_script("natvis/liballoc.natvis");
494 cp_debugger_script("natvis/libcore.natvis");
495 cp_debugger_script("natvis/libstd.natvis");
497 cp_debugger_script("rust_types.py");
499 // gdb debugger scripts
500 builder.install(&builder.src.join("src/etc/rust-gdb"), &sysroot.join("bin"), 0o755);
501 builder.install(&builder.src.join("src/etc/rust-gdbgui"), &sysroot.join("bin"), 0o755);
503 cp_debugger_script("gdb_load_rust_pretty_printers.py");
504 cp_debugger_script("gdb_lookup.py");
505 cp_debugger_script("gdb_providers.py");
507 // lldb debugger scripts
508 builder.install(&builder.src.join("src/etc/rust-lldb"), &sysroot.join("bin"), 0o755);
510 cp_debugger_script("lldb_lookup.py");
511 cp_debugger_script("lldb_providers.py");
512 cp_debugger_script("lldb_commands")
517 fn skip_host_target_lib(builder: &Builder<'_>, compiler: Compiler) -> bool {
518 // The only true set of target libraries came from the build triple, so
519 // let's reduce redundant work by only producing archives from that host.
520 if compiler.host != builder.config.build {
521 builder.info("\tskipping, not a build host");
528 /// Copy stamped files into an image's `target/lib` directory.
529 fn copy_target_libs(builder: &Builder<'_>, target: TargetSelection, image: &Path, stamp: &Path) {
530 let dst = image.join("lib/rustlib").join(target.triple).join("lib");
531 let self_contained_dst = dst.join("self-contained");
532 t!(fs::create_dir_all(&dst));
533 t!(fs::create_dir_all(&self_contained_dst));
534 for (path, dependency_type) in builder.read_stamp_file(stamp) {
535 if dependency_type == DependencyType::TargetSelfContained {
536 builder.copy(&path, &self_contained_dst.join(path.file_name().unwrap()));
537 } else if dependency_type == DependencyType::Target || builder.config.build == target {
538 builder.copy(&path, &dst.join(path.file_name().unwrap()));
543 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
545 pub compiler: Compiler,
546 pub target: TargetSelection,
550 type Output = Option<GeneratedTarball>;
551 const DEFAULT: bool = true;
553 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
554 run.alias("rust-std")
557 fn make_run(run: RunConfig<'_>) {
558 run.builder.ensure(Std {
559 compiler: run.builder.compiler_for(
560 run.builder.top_stage,
561 run.builder.config.build,
568 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
569 let compiler = self.compiler;
570 let target = self.target;
572 if skip_host_target_lib(builder, compiler) {
576 builder.ensure(compile::Std::new(compiler, target));
578 let mut tarball = Tarball::new(builder, "rust-std", &target.triple);
579 tarball.include_target_in_component_name(true);
581 let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target);
582 let stamp = compile::libstd_stamp(builder, compiler_to_use, target);
583 copy_target_libs(builder, target, &tarball.image_dir(), &stamp);
585 Some(tarball.generate())
589 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
590 pub struct RustcDev {
591 pub compiler: Compiler,
592 pub target: TargetSelection,
595 impl Step for RustcDev {
596 type Output = Option<GeneratedTarball>;
597 const DEFAULT: bool = true;
598 const ONLY_HOSTS: bool = true;
600 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
601 run.alias("rustc-dev")
604 fn make_run(run: RunConfig<'_>) {
605 run.builder.ensure(RustcDev {
606 compiler: run.builder.compiler_for(
607 run.builder.top_stage,
608 run.builder.config.build,
615 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
616 let compiler = self.compiler;
617 let target = self.target;
618 if skip_host_target_lib(builder, compiler) {
622 builder.ensure(compile::Rustc::new(compiler, target));
624 let tarball = Tarball::new(builder, "rustc-dev", &target.triple);
626 let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target);
627 let stamp = compile::librustc_stamp(builder, compiler_to_use, target);
628 copy_target_libs(builder, target, tarball.image_dir(), &stamp);
630 let src_files = &["Cargo.lock"];
631 // This is the reduced set of paths which will become the rustc-dev component
632 // (essentially the compiler crates and all of their path dependencies).
638 &tarball.image_dir().join("lib/rustlib/rustc-src/rust"),
640 for file in src_files {
641 tarball.add_file(builder.src.join(file), "lib/rustlib/rustc-src/rust", 0o644);
644 Some(tarball.generate())
648 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
649 pub struct Analysis {
650 pub compiler: Compiler,
651 pub target: TargetSelection,
654 impl Step for Analysis {
655 type Output = Option<GeneratedTarball>;
656 const DEFAULT: bool = true;
658 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
659 let default = should_build_extended_tool(&run.builder, "analysis");
660 run.alias("rust-analysis").default_condition(default)
663 fn make_run(run: RunConfig<'_>) {
664 run.builder.ensure(Analysis {
665 // Find the actual compiler (handling the full bootstrap option) which
666 // produced the save-analysis data because that data isn't copied
667 // through the sysroot uplifting.
668 compiler: run.builder.compiler_for(
669 run.builder.top_stage,
670 run.builder.config.build,
677 /// Creates a tarball of save-analysis metadata, if available.
678 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
679 let compiler = self.compiler;
680 let target = self.target;
681 if compiler.host != builder.config.build {
685 builder.ensure(compile::Std::new(compiler, target));
687 .stage_out(compiler, Mode::Std)
689 .join(builder.cargo_dir())
691 .join("save-analysis");
693 let mut tarball = Tarball::new(builder, "rust-analysis", &target.triple);
694 tarball.include_target_in_component_name(true);
695 tarball.add_dir(src, format!("lib/rustlib/{}/analysis", target.triple));
696 Some(tarball.generate())
700 /// Use the `builder` to make a filtered copy of `base`/X for X in (`src_dirs` - `exclude_dirs`) to
703 builder: &Builder<'_>,
706 exclude_dirs: &[&str],
709 fn filter_fn(exclude_dirs: &[&str], dir: &str, path: &Path) -> bool {
710 let spath = match path.to_str() {
712 None => return false,
714 if spath.ends_with('~') || spath.ends_with(".pyc") {
718 const LLVM_PROJECTS: &[&str] = &[
719 "llvm-project/clang",
720 "llvm-project\\clang",
721 "llvm-project/libunwind",
722 "llvm-project\\libunwind",
726 "llvm-project\\lldb",
728 "llvm-project\\llvm",
729 "llvm-project/compiler-rt",
730 "llvm-project\\compiler-rt",
731 "llvm-project/cmake",
732 "llvm-project\\cmake",
734 if spath.contains("llvm-project")
735 && !spath.ends_with("llvm-project")
736 && !LLVM_PROJECTS.iter().any(|path| spath.contains(path))
741 const LLVM_TEST: &[&str] = &["llvm-project/llvm/test", "llvm-project\\llvm\\test"];
742 if LLVM_TEST.iter().any(|path| spath.contains(path))
743 && (spath.ends_with(".ll") || spath.ends_with(".td") || spath.ends_with(".s"))
748 let full_path = Path::new(dir).join(path);
749 if exclude_dirs.iter().any(|excl| full_path == Path::new(excl)) {
776 !path.iter().map(|s| s.to_str().unwrap()).any(|s| excludes.contains(&s))
779 // Copy the directories using our filter
780 for item in src_dirs {
781 let dst = &dst_dir.join(item);
782 t!(fs::create_dir_all(dst));
783 builder.cp_filtered(&base.join(item), dst, &|path| filter_fn(exclude_dirs, item, path));
787 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
791 /// The output path of the src installer tarball
792 type Output = GeneratedTarball;
793 const DEFAULT: bool = true;
794 const ONLY_HOSTS: bool = true;
796 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
797 run.alias("rust-src")
800 fn make_run(run: RunConfig<'_>) {
801 run.builder.ensure(Src);
804 /// Creates the `rust-src` installer component
805 fn run(self, builder: &Builder<'_>) -> GeneratedTarball {
806 let tarball = Tarball::new_targetless(builder, "rust-src");
808 // A lot of tools expect the rust-src component to be entirely in this directory, so if you
809 // change that (e.g. by adding another directory `lib/rustlib/src/foo` or
810 // `lib/rustlib/src/rust/foo`), you will need to go around hunting for implicit assumptions
813 // NOTE: if you update the paths here, you also should update the "virtual" path
814 // translation code in `imported_source_files` in `src/librustc_metadata/rmeta/decoder.rs`
815 let dst_src = tarball.image_dir().join("lib/rustlib/src/rust");
817 let src_files = ["Cargo.lock"];
818 // This is the reduced set of paths which will become the rust-src component
819 // (essentially libstd and all of its path dependencies).
823 &["library", "src/llvm-project/libunwind"],
825 // not needed and contains symlinks which rustup currently
826 // chokes on when unpacking.
827 "library/backtrace/crates",
828 // these are 30MB combined and aren't necessary for building
829 // the standard library.
830 "library/stdarch/Cargo.toml",
831 "library/stdarch/crates/stdarch-verify",
832 "library/stdarch/crates/intrinsic-test",
836 for file in src_files.iter() {
837 builder.copy(&builder.src.join(file), &dst_src.join(file));
844 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
845 pub struct PlainSourceTarball;
847 impl Step for PlainSourceTarball {
848 /// Produces the location of the tarball generated
849 type Output = GeneratedTarball;
850 const DEFAULT: bool = true;
851 const ONLY_HOSTS: bool = true;
853 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
854 let builder = run.builder;
855 run.alias("rustc-src").default_condition(builder.config.rust_dist_src)
858 fn make_run(run: RunConfig<'_>) {
859 run.builder.ensure(PlainSourceTarball);
862 /// Creates the plain source tarball
863 fn run(self, builder: &Builder<'_>) -> GeneratedTarball {
864 // NOTE: This is a strange component in a lot of ways. It uses `src` as the target, which
865 // means neither rustup nor rustup-toolchain-install-master know how to download it.
866 // It also contains symbolic links, unlike other any other dist tarball.
867 // It's used for distros building rustc from source in a pre-vendored environment.
868 let mut tarball = Tarball::new(builder, "rustc", "src");
869 tarball.permit_symlinks(true);
870 let plain_dst_src = tarball.image_dir();
872 // This is the set of root paths which will become part of the source package
882 "config.toml.example",
886 let src_dirs = ["src", "compiler", "library"];
888 copy_src_dirs(builder, &builder.src, &src_dirs, &[], &plain_dst_src);
890 // Copy the files normally
891 for item in &src_files {
892 builder.copy(&builder.src.join(item), &plain_dst_src.join(item));
895 // Create the version file
896 builder.create(&plain_dst_src.join("version"), &builder.rust_version());
897 if let Some(sha) = builder.rust_sha() {
898 builder.create(&plain_dst_src.join("git-commit-hash"), &sha);
901 // If we're building from git sources, we need to vendor a complete distribution.
902 if builder.rust_info.is_git() {
903 // Ensure we have the submodules checked out.
904 builder.update_submodule(Path::new("src/tools/rust-analyzer"));
906 // Vendor all Cargo dependencies
907 let mut cmd = Command::new(&builder.initial_cargo);
910 .arg(builder.src.join("./src/tools/rust-analyzer/Cargo.toml"))
912 .arg(builder.src.join("./compiler/rustc_codegen_cranelift/Cargo.toml"))
914 .arg(builder.src.join("./src/bootstrap/Cargo.toml"))
915 .current_dir(&plain_dst_src);
917 let config = if !builder.config.dry_run {
918 t!(String::from_utf8(t!(cmd.output()).stdout))
923 let cargo_config_dir = plain_dst_src.join(".cargo");
924 builder.create_dir(&cargo_config_dir);
925 builder.create(&cargo_config_dir.join("config.toml"), &config);
932 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
934 pub compiler: Compiler,
935 pub target: TargetSelection,
938 impl Step for Cargo {
939 type Output = Option<GeneratedTarball>;
940 const DEFAULT: bool = true;
941 const ONLY_HOSTS: bool = true;
943 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
944 let default = should_build_extended_tool(&run.builder, "cargo");
945 run.alias("cargo").default_condition(default)
948 fn make_run(run: RunConfig<'_>) {
949 run.builder.ensure(Cargo {
950 compiler: run.builder.compiler_for(
951 run.builder.top_stage,
952 run.builder.config.build,
959 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
960 let compiler = self.compiler;
961 let target = self.target;
963 let cargo = builder.ensure(tool::Cargo { compiler, target });
964 let src = builder.src.join("src/tools/cargo");
965 let etc = src.join("src/etc");
967 // Prepare the image directory
968 let mut tarball = Tarball::new(builder, "cargo", &target.triple);
969 tarball.set_overlay(OverlayKind::Cargo);
971 tarball.add_file(&cargo, "bin", 0o755);
972 tarball.add_file(etc.join("_cargo"), "share/zsh/site-functions", 0o644);
973 tarball.add_renamed_file(etc.join("cargo.bashcomp.sh"), "etc/bash_completion.d", "cargo");
974 tarball.add_dir(etc.join("man"), "share/man/man1");
975 tarball.add_legal_and_readme_to("share/doc/cargo");
977 for dirent in fs::read_dir(cargo.parent().unwrap()).expect("read_dir") {
978 let dirent = dirent.expect("read dir entry");
979 if dirent.file_name().to_str().expect("utf8").starts_with("cargo-credential-") {
980 tarball.add_file(&dirent.path(), "libexec", 0o755);
984 Some(tarball.generate())
988 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
990 pub compiler: Compiler,
991 pub target: TargetSelection,
995 type Output = Option<GeneratedTarball>;
996 const ONLY_HOSTS: bool = true;
997 const DEFAULT: bool = true;
999 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1000 let default = should_build_extended_tool(&run.builder, "rls");
1001 run.alias("rls").default_condition(default)
1004 fn make_run(run: RunConfig<'_>) {
1005 run.builder.ensure(Rls {
1006 compiler: run.builder.compiler_for(
1007 run.builder.top_stage,
1008 run.builder.config.build,
1015 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
1016 let compiler = self.compiler;
1017 let target = self.target;
1020 .ensure(tool::Rls { compiler, target, extra_features: Vec::new() })
1021 .expect("rls expected to build");
1023 let mut tarball = Tarball::new(builder, "rls", &target.triple);
1024 tarball.set_overlay(OverlayKind::RLS);
1025 tarball.is_preview(true);
1026 tarball.add_file(rls, "bin", 0o755);
1027 tarball.add_legal_and_readme_to("share/doc/rls");
1028 Some(tarball.generate())
1032 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
1033 pub struct RustAnalyzer {
1034 pub compiler: Compiler,
1035 pub target: TargetSelection,
1038 impl Step for RustAnalyzer {
1039 type Output = Option<GeneratedTarball>;
1040 const DEFAULT: bool = true;
1041 const ONLY_HOSTS: bool = true;
1043 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1044 let default = should_build_extended_tool(&run.builder, "rust-analyzer");
1045 run.alias("rust-analyzer").default_condition(default)
1048 fn make_run(run: RunConfig<'_>) {
1049 run.builder.ensure(RustAnalyzer {
1050 compiler: run.builder.compiler_for(
1051 run.builder.top_stage,
1052 run.builder.config.build,
1059 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
1060 let compiler = self.compiler;
1061 let target = self.target;
1063 if target.contains("riscv64") {
1064 // riscv64 currently has an LLVM bug that makes rust-analyzer unable
1065 // to build. See #74813 for details.
1069 let rust_analyzer = builder
1070 .ensure(tool::RustAnalyzer { compiler, target })
1071 .expect("rust-analyzer always builds");
1073 let mut tarball = Tarball::new(builder, "rust-analyzer", &target.triple);
1074 tarball.set_overlay(OverlayKind::RustAnalyzer);
1075 tarball.is_preview(true);
1076 tarball.add_file(rust_analyzer, "bin", 0o755);
1077 tarball.add_legal_and_readme_to("share/doc/rust-analyzer");
1078 Some(tarball.generate())
1082 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
1084 pub compiler: Compiler,
1085 pub target: TargetSelection,
1088 impl Step for Clippy {
1089 type Output = Option<GeneratedTarball>;
1090 const DEFAULT: bool = true;
1091 const ONLY_HOSTS: bool = true;
1093 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1094 let default = should_build_extended_tool(&run.builder, "clippy");
1095 run.alias("clippy").default_condition(default)
1098 fn make_run(run: RunConfig<'_>) {
1099 run.builder.ensure(Clippy {
1100 compiler: run.builder.compiler_for(
1101 run.builder.top_stage,
1102 run.builder.config.build,
1109 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
1110 let compiler = self.compiler;
1111 let target = self.target;
1113 // Prepare the image directory
1114 // We expect clippy to build, because we've exited this step above if tool
1115 // state for clippy isn't testing.
1116 let clippy = builder
1117 .ensure(tool::Clippy { compiler, target, extra_features: Vec::new() })
1118 .expect("clippy expected to build - essential tool");
1119 let cargoclippy = builder
1120 .ensure(tool::CargoClippy { compiler, target, extra_features: Vec::new() })
1121 .expect("clippy expected to build - essential tool");
1123 let mut tarball = Tarball::new(builder, "clippy", &target.triple);
1124 tarball.set_overlay(OverlayKind::Clippy);
1125 tarball.is_preview(true);
1126 tarball.add_file(clippy, "bin", 0o755);
1127 tarball.add_file(cargoclippy, "bin", 0o755);
1128 tarball.add_legal_and_readme_to("share/doc/clippy");
1129 Some(tarball.generate())
1133 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
1135 pub compiler: Compiler,
1136 pub target: TargetSelection,
1139 impl Step for Miri {
1140 type Output = Option<GeneratedTarball>;
1141 const DEFAULT: bool = true;
1142 const ONLY_HOSTS: bool = true;
1144 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1145 let default = should_build_extended_tool(&run.builder, "miri");
1146 run.alias("miri").default_condition(default)
1149 fn make_run(run: RunConfig<'_>) {
1150 run.builder.ensure(Miri {
1151 compiler: run.builder.compiler_for(
1152 run.builder.top_stage,
1153 run.builder.config.build,
1160 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
1161 // This prevents miri from being built for "dist" or "install"
1162 // on the stable/beta channels. It is a nightly-only tool and should
1164 if !builder.build.unstable_features() {
1167 let compiler = self.compiler;
1168 let target = self.target;
1171 .ensure(tool::Miri { compiler, target, extra_features: Vec::new() })
1173 missing_tool("miri", builder.build.config.missing_tools);
1176 let cargomiri = builder
1177 .ensure(tool::CargoMiri { compiler, target, extra_features: Vec::new() })
1179 missing_tool("cargo miri", builder.build.config.missing_tools);
1183 let mut tarball = Tarball::new(builder, "miri", &target.triple);
1184 tarball.set_overlay(OverlayKind::Miri);
1185 tarball.is_preview(true);
1186 tarball.add_file(miri, "bin", 0o755);
1187 tarball.add_file(cargomiri, "bin", 0o755);
1188 tarball.add_legal_and_readme_to("share/doc/miri");
1189 Some(tarball.generate())
1193 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
1194 pub struct Rustfmt {
1195 pub compiler: Compiler,
1196 pub target: TargetSelection,
1199 impl Step for Rustfmt {
1200 type Output = Option<GeneratedTarball>;
1201 const DEFAULT: bool = true;
1202 const ONLY_HOSTS: bool = true;
1204 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1205 let default = should_build_extended_tool(&run.builder, "rustfmt");
1206 run.alias("rustfmt").default_condition(default)
1209 fn make_run(run: RunConfig<'_>) {
1210 run.builder.ensure(Rustfmt {
1211 compiler: run.builder.compiler_for(
1212 run.builder.top_stage,
1213 run.builder.config.build,
1220 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
1221 let compiler = self.compiler;
1222 let target = self.target;
1224 let rustfmt = builder
1225 .ensure(tool::Rustfmt { compiler, target, extra_features: Vec::new() })
1226 .expect("rustfmt expected to build - essential tool");
1227 let cargofmt = builder
1228 .ensure(tool::Cargofmt { compiler, target, extra_features: Vec::new() })
1229 .expect("cargo fmt expected to build - essential tool");
1230 let mut tarball = Tarball::new(builder, "rustfmt", &target.triple);
1231 tarball.set_overlay(OverlayKind::Rustfmt);
1232 tarball.is_preview(true);
1233 tarball.add_file(rustfmt, "bin", 0o755);
1234 tarball.add_file(cargofmt, "bin", 0o755);
1235 tarball.add_legal_and_readme_to("share/doc/rustfmt");
1236 Some(tarball.generate())
1240 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
1241 pub struct RustDemangler {
1242 pub compiler: Compiler,
1243 pub target: TargetSelection,
1246 impl Step for RustDemangler {
1247 type Output = Option<GeneratedTarball>;
1248 const DEFAULT: bool = true;
1249 const ONLY_HOSTS: bool = true;
1251 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1252 // While other tools use `should_build_extended_tool` to decide whether to be run by
1253 // default or not, `rust-demangler` must be build when *either* it's enabled as a tool like
1254 // the other ones or if `profiler = true`. Because we don't know the target at this stage
1255 // we run the step by default when only `extended = true`, and decide whether to actually
1256 // run it or not later.
1257 let default = run.builder.config.extended;
1258 run.alias("rust-demangler").default_condition(default)
1261 fn make_run(run: RunConfig<'_>) {
1262 run.builder.ensure(RustDemangler {
1263 compiler: run.builder.compiler_for(
1264 run.builder.top_stage,
1265 run.builder.config.build,
1272 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
1273 let compiler = self.compiler;
1274 let target = self.target;
1276 // Only build this extended tool if explicitly included in `tools`, or if `profiler = true`
1277 let condition = should_build_extended_tool(builder, "rust-demangler")
1278 || builder.config.profiler_enabled(target);
1279 if builder.config.extended && !condition {
1283 let rust_demangler = builder
1284 .ensure(tool::RustDemangler { compiler, target, extra_features: Vec::new() })
1285 .expect("rust-demangler expected to build - in-tree tool");
1287 // Prepare the image directory
1288 let mut tarball = Tarball::new(builder, "rust-demangler", &target.triple);
1289 tarball.set_overlay(OverlayKind::RustDemangler);
1290 tarball.is_preview(true);
1291 tarball.add_file(&rust_demangler, "bin", 0o755);
1292 tarball.add_legal_and_readme_to("share/doc/rust-demangler");
1293 Some(tarball.generate())
1297 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
1298 pub struct Extended {
1300 host: TargetSelection,
1301 target: TargetSelection,
1304 impl Step for Extended {
1306 const DEFAULT: bool = true;
1307 const ONLY_HOSTS: bool = true;
1309 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1310 let builder = run.builder;
1311 run.alias("extended").default_condition(builder.config.extended)
1314 fn make_run(run: RunConfig<'_>) {
1315 run.builder.ensure(Extended {
1316 stage: run.builder.top_stage,
1317 host: run.builder.config.build,
1322 /// Creates a combined installer for the specified target in the provided stage.
1323 fn run(self, builder: &Builder<'_>) {
1324 let target = self.target;
1325 let stage = self.stage;
1326 let compiler = builder.compiler_for(self.stage, self.host, self.target);
1328 builder.info(&format!("Dist extended stage{} ({})", compiler.stage, target));
1330 let mut tarballs = Vec::new();
1331 let mut built_tools = HashSet::new();
1332 macro_rules! add_component {
1333 ($name:expr => $step:expr) => {
1334 if let Some(tarball) = builder.ensure_if_default($step, Kind::Dist) {
1335 tarballs.push(tarball);
1336 built_tools.insert($name);
1341 // When rust-std package split from rustc, we needed to ensure that during
1342 // upgrades rustc was upgraded before rust-std. To avoid rustc clobbering
1343 // the std files during uninstall. To do this ensure that rustc comes
1344 // before rust-std in the list below.
1345 tarballs.push(builder.ensure(Rustc { compiler: builder.compiler(stage, target) }));
1346 tarballs.push(builder.ensure(Std { compiler, target }).expect("missing std"));
1348 if target.ends_with("windows-gnu") {
1349 tarballs.push(builder.ensure(Mingw { host: target }).expect("missing mingw"));
1352 add_component!("rust-docs" => Docs { host: target });
1353 add_component!("rust-demangler"=> RustDemangler { compiler, target });
1354 add_component!("cargo" => Cargo { compiler, target });
1355 add_component!("rustfmt" => Rustfmt { compiler, target });
1356 add_component!("rls" => Rls { compiler, target });
1357 add_component!("rust-analyzer" => RustAnalyzer { compiler, target });
1358 add_component!("llvm-components" => LlvmTools { target });
1359 add_component!("clippy" => Clippy { compiler, target });
1360 add_component!("miri" => Miri { compiler, target });
1361 add_component!("analysis" => Analysis { compiler, target });
1363 let etc = builder.src.join("src/etc/installer");
1365 // Avoid producing tarballs during a dry run.
1366 if builder.config.dry_run {
1370 let tarball = Tarball::new(builder, "rust", &target.triple);
1371 let generated = tarball.combine(&tarballs);
1373 let tmp = tmpdir(builder).join("combined-tarball");
1374 let work = generated.work_dir();
1376 let mut license = String::new();
1377 license += &builder.read(&builder.src.join("COPYRIGHT"));
1378 license += &builder.read(&builder.src.join("LICENSE-APACHE"));
1379 license += &builder.read(&builder.src.join("LICENSE-MIT"));
1383 let rtf = r"{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 Arial;}}\nowwrap\fs18";
1384 let mut rtf = rtf.to_string();
1386 for line in license.lines() {
1388 rtf.push_str("\\line ");
1392 fn filter(contents: &str, marker: &str) -> String {
1393 let start = format!("tool-{}-start", marker);
1394 let end = format!("tool-{}-end", marker);
1395 let mut lines = Vec::new();
1396 let mut omitted = false;
1397 for line in contents.lines() {
1398 if line.contains(&start) {
1400 } else if line.contains(&end) {
1402 } else if !omitted {
1410 let xform = |p: &Path| {
1411 let mut contents = t!(fs::read_to_string(p));
1412 for tool in &["rust-demangler", "rls", "rust-analyzer", "miri", "rustfmt"] {
1413 if !built_tools.contains(tool) {
1414 contents = filter(&contents, tool);
1417 let ret = tmp.join(p.file_name().unwrap());
1418 t!(fs::write(&ret, &contents));
1422 if target.contains("apple-darwin") {
1423 builder.info("building pkg installer");
1424 let pkg = tmp.join("pkg");
1425 let _ = fs::remove_dir_all(&pkg);
1427 let pkgbuild = |component: &str| {
1428 let mut cmd = Command::new("pkgbuild");
1429 cmd.arg("--identifier")
1430 .arg(format!("org.rust-lang.{}", component))
1432 .arg(pkg.join(component))
1434 .arg(pkg.join(component).with_extension("pkg"));
1435 builder.run(&mut cmd);
1438 let prepare = |name: &str| {
1439 builder.create_dir(&pkg.join(name));
1441 &work.join(&format!("{}-{}", pkgname(builder, name), target.triple)),
1444 builder.install(&etc.join("pkg/postinstall"), &pkg.join(name), 0o755);
1449 prepare("rust-std");
1450 prepare("rust-analysis");
1452 for tool in &["rust-docs", "rust-demangler", "rls", "rust-analyzer", "miri"] {
1453 if built_tools.contains(tool) {
1457 // create an 'uninstall' package
1458 builder.install(&etc.join("pkg/postinstall"), &pkg.join("uninstall"), 0o755);
1459 pkgbuild("uninstall");
1461 builder.create_dir(&pkg.join("res"));
1462 builder.create(&pkg.join("res/LICENSE.txt"), &license);
1463 builder.install(&etc.join("gfx/rust-logo.png"), &pkg.join("res"), 0o644);
1464 let mut cmd = Command::new("productbuild");
1465 cmd.arg("--distribution")
1466 .arg(xform(&etc.join("pkg/Distribution.xml")))
1468 .arg(pkg.join("res"))
1469 .arg(distdir(builder).join(format!(
1471 pkgname(builder, "rust"),
1474 .arg("--package-path")
1476 let _time = timeit(builder);
1477 builder.run(&mut cmd);
1480 if target.contains("windows") {
1481 let exe = tmp.join("exe");
1482 let _ = fs::remove_dir_all(&exe);
1484 let prepare = |name: &str| {
1485 builder.create_dir(&exe.join(name));
1486 let dir = if name == "rust-std" || name == "rust-analysis" {
1487 format!("{}-{}", name, target.triple)
1488 } else if name == "rls" {
1489 "rls-preview".to_string()
1490 } else if name == "rust-analyzer" {
1491 "rust-analyzer-preview".to_string()
1492 } else if name == "clippy" {
1493 "clippy-preview".to_string()
1494 } else if name == "rust-demangler" {
1495 "rust-demangler-preview".to_string()
1496 } else if name == "miri" {
1497 "miri-preview".to_string()
1502 &work.join(&format!("{}-{}", pkgname(builder, name), target.triple)).join(dir),
1505 builder.remove(&exe.join(name).join("manifest.in"));
1509 prepare("rust-analysis");
1510 prepare("rust-docs");
1511 prepare("rust-std");
1513 for tool in &["rust-demangler", "rls", "rust-analyzer", "miri"] {
1514 if built_tools.contains(tool) {
1518 if target.ends_with("windows-gnu") {
1519 prepare("rust-mingw");
1522 builder.install(&etc.join("gfx/rust-logo.ico"), &exe, 0o644);
1524 // Generate msi installer
1525 let wix_path = env::var_os("WIX")
1526 .expect("`WIX` environment variable must be set for generating MSI installer(s).");
1527 let wix = PathBuf::from(wix_path);
1528 let heat = wix.join("bin/heat.exe");
1529 let candle = wix.join("bin/candle.exe");
1530 let light = wix.join("bin/light.exe");
1532 let heat_flags = ["-nologo", "-gg", "-sfrag", "-srd", "-sreg"];
1544 .arg("var.RustcDir")
1546 .arg(exe.join("RustcGroup.wxs")),
1561 .arg(exe.join("DocsGroup.wxs"))
1563 .arg(etc.join("msi/squash-components.xsl")),
1576 .arg("var.CargoDir")
1578 .arg(exe.join("CargoGroup.wxs"))
1580 .arg(etc.join("msi/remove-duplicates.xsl")),
1595 .arg(exe.join("StdGroup.wxs")),
1597 if built_tools.contains("rls") {
1611 .arg(exe.join("RlsGroup.wxs"))
1613 .arg(etc.join("msi/remove-duplicates.xsl")),
1616 if built_tools.contains("rust-analyzer") {
1621 .arg("rust-analyzer")
1624 .arg("RustAnalyzerGroup")
1626 .arg("RustAnalyzer")
1628 .arg("var.RustAnalyzerDir")
1630 .arg(exe.join("RustAnalyzerGroup.wxs"))
1632 .arg(etc.join("msi/remove-duplicates.xsl")),
1646 .arg("var.ClippyDir")
1648 .arg(exe.join("ClippyGroup.wxs"))
1650 .arg(etc.join("msi/remove-duplicates.xsl")),
1652 if built_tools.contains("rust-demangler") {
1657 .arg("rust-demangler")
1660 .arg("RustDemanglerGroup")
1662 .arg("RustDemangler")
1664 .arg("var.RustDemanglerDir")
1666 .arg(exe.join("RustDemanglerGroup.wxs"))
1668 .arg(etc.join("msi/remove-duplicates.xsl")),
1671 if built_tools.contains("miri") {
1685 .arg(exe.join("MiriGroup.wxs"))
1687 .arg(etc.join("msi/remove-duplicates.xsl")),
1694 .arg("rust-analysis")
1697 .arg("AnalysisGroup")
1701 .arg("var.AnalysisDir")
1703 .arg(exe.join("AnalysisGroup.wxs"))
1705 .arg(etc.join("msi/remove-duplicates.xsl")),
1707 if target.ends_with("windows-gnu") {
1721 .arg(exe.join("GccGroup.wxs")),
1725 let candle = |input: &Path| {
1726 let output = exe.join(input.file_stem().unwrap()).with_extension("wixobj");
1727 let arch = if target.contains("x86_64") { "x64" } else { "x86" };
1728 let mut cmd = Command::new(&candle);
1729 cmd.current_dir(&exe)
1731 .arg("-dRustcDir=rustc")
1732 .arg("-dDocsDir=rust-docs")
1733 .arg("-dCargoDir=cargo")
1734 .arg("-dStdDir=rust-std")
1735 .arg("-dAnalysisDir=rust-analysis")
1736 .arg("-dClippyDir=clippy")
1742 add_env(builder, &mut cmd, target);
1744 if built_tools.contains("rust-demangler") {
1745 cmd.arg("-dRustDemanglerDir=rust-demangler");
1747 if built_tools.contains("rls") {
1748 cmd.arg("-dRlsDir=rls");
1750 if built_tools.contains("rust-analyzer") {
1751 cmd.arg("-dRustAnalyzerDir=rust-analyzer");
1753 if built_tools.contains("miri") {
1754 cmd.arg("-dMiriDir=miri");
1756 if target.ends_with("windows-gnu") {
1757 cmd.arg("-dGccDir=rust-mingw");
1759 builder.run(&mut cmd);
1761 candle(&xform(&etc.join("msi/rust.wxs")));
1762 candle(&etc.join("msi/ui.wxs"));
1763 candle(&etc.join("msi/rustwelcomedlg.wxs"));
1764 candle("RustcGroup.wxs".as_ref());
1765 candle("DocsGroup.wxs".as_ref());
1766 candle("CargoGroup.wxs".as_ref());
1767 candle("StdGroup.wxs".as_ref());
1768 candle("ClippyGroup.wxs".as_ref());
1769 if built_tools.contains("rust-demangler") {
1770 candle("RustDemanglerGroup.wxs".as_ref());
1772 if built_tools.contains("rls") {
1773 candle("RlsGroup.wxs".as_ref());
1775 if built_tools.contains("rust-analyzer") {
1776 candle("RustAnalyzerGroup.wxs".as_ref());
1778 if built_tools.contains("miri") {
1779 candle("MiriGroup.wxs".as_ref());
1781 candle("AnalysisGroup.wxs".as_ref());
1783 if target.ends_with("windows-gnu") {
1784 candle("GccGroup.wxs".as_ref());
1787 builder.create(&exe.join("LICENSE.rtf"), &rtf);
1788 builder.install(&etc.join("gfx/banner.bmp"), &exe, 0o644);
1789 builder.install(&etc.join("gfx/dialogbg.bmp"), &exe, 0o644);
1791 builder.info(&format!("building `msi` installer with {:?}", light));
1792 let filename = format!("{}-{}.msi", pkgname(builder, "rust"), target.triple);
1793 let mut cmd = Command::new(&light);
1796 .arg("WixUIExtension")
1798 .arg("WixUtilExtension")
1800 .arg(exe.join(&filename))
1803 .arg("rustwelcomedlg.wixobj")
1804 .arg("RustcGroup.wixobj")
1805 .arg("DocsGroup.wixobj")
1806 .arg("CargoGroup.wixobj")
1807 .arg("StdGroup.wixobj")
1808 .arg("AnalysisGroup.wixobj")
1809 .arg("ClippyGroup.wixobj")
1812 if built_tools.contains("rls") {
1813 cmd.arg("RlsGroup.wixobj");
1815 if built_tools.contains("rust-analyzer") {
1816 cmd.arg("RustAnalyzerGroup.wixobj");
1818 if built_tools.contains("rust-demangler") {
1819 cmd.arg("RustDemanglerGroup.wixobj");
1821 if built_tools.contains("miri") {
1822 cmd.arg("MiriGroup.wixobj");
1825 if target.ends_with("windows-gnu") {
1826 cmd.arg("GccGroup.wixobj");
1828 // ICE57 wrongly complains about the shortcuts
1829 cmd.arg("-sice:ICE57");
1831 let _time = timeit(builder);
1832 builder.run(&mut cmd);
1834 if !builder.config.dry_run {
1835 t!(fs::rename(exe.join(&filename), distdir(builder).join(&filename)));
1841 fn add_env(builder: &Builder<'_>, cmd: &mut Command, target: TargetSelection) {
1842 let mut parts = builder.version.split('.');
1843 cmd.env("CFG_RELEASE_INFO", builder.rust_version())
1844 .env("CFG_RELEASE_NUM", &builder.version)
1845 .env("CFG_RELEASE", builder.rust_release())
1846 .env("CFG_VER_MAJOR", parts.next().unwrap())
1847 .env("CFG_VER_MINOR", parts.next().unwrap())
1848 .env("CFG_VER_PATCH", parts.next().unwrap())
1849 .env("CFG_VER_BUILD", "0") // just needed to build
1850 .env("CFG_PACKAGE_VERS", builder.rust_package_vers())
1851 .env("CFG_PACKAGE_NAME", pkgname(builder, "rust"))
1852 .env("CFG_BUILD", target.triple)
1853 .env("CFG_CHANNEL", &builder.config.channel);
1855 if target.contains("windows-gnullvm") {
1856 cmd.env("CFG_MINGW", "1").env("CFG_ABI", "LLVM");
1857 } else if target.contains("windows-gnu") {
1858 cmd.env("CFG_MINGW", "1").env("CFG_ABI", "GNU");
1860 cmd.env("CFG_MINGW", "0").env("CFG_ABI", "MSVC");
1864 /// Maybe add LLVM object files to the given destination lib-dir. Allows either static or dynamic linking.
1866 /// Returns whether the files were actually copied.
1867 fn maybe_install_llvm(builder: &Builder<'_>, target: TargetSelection, dst_libdir: &Path) -> bool {
1868 if let Some(config) = builder.config.target_config.get(&target) {
1869 if config.llvm_config.is_some() && !builder.config.llvm_from_ci {
1870 // If the LLVM was externally provided, then we don't currently copy
1871 // artifacts into the sysroot. This is not necessarily the right
1872 // choice (in particular, it will require the LLVM dylib to be in
1873 // the linker's load path at runtime), but the common use case for
1874 // external LLVMs is distribution provided LLVMs, and in that case
1875 // they're usually in the standard search path (e.g., /usr/lib) and
1876 // copying them here is going to cause problems as we may end up
1877 // with the wrong files and isn't what distributions want.
1879 // This behavior may be revisited in the future though.
1881 // If the LLVM is coming from ourselves (just from CI) though, we
1882 // still want to install it, as it otherwise won't be available.
1887 // On macOS, rustc (and LLVM tools) link to an unversioned libLLVM.dylib
1888 // instead of libLLVM-11-rust-....dylib, as on linux. It's not entirely
1889 // clear why this is the case, though. llvm-config will emit the versioned
1890 // paths and we don't want those in the sysroot (as we're expecting
1891 // unversioned paths).
1892 if target.contains("apple-darwin") && builder.llvm_link_shared() {
1893 let src_libdir = builder.llvm_out(target).join("lib");
1894 let llvm_dylib_path = src_libdir.join("libLLVM.dylib");
1895 if llvm_dylib_path.exists() {
1896 builder.install(&llvm_dylib_path, dst_libdir, 0o644);
1898 !builder.config.dry_run
1899 } else if let Ok(llvm_config) = crate::native::prebuilt_llvm_config(builder, target) {
1900 let mut cmd = Command::new(llvm_config);
1901 cmd.arg("--libfiles");
1902 builder.verbose(&format!("running {:?}", cmd));
1903 let files = output(&mut cmd);
1904 let build_llvm_out = &builder.llvm_out(builder.config.build);
1905 let target_llvm_out = &builder.llvm_out(target);
1906 for file in files.trim_end().split(' ') {
1907 // If we're not using a custom LLVM, make sure we package for the target.
1908 let file = if let Ok(relative_path) = Path::new(file).strip_prefix(build_llvm_out) {
1909 target_llvm_out.join(relative_path)
1913 builder.install(&file, dst_libdir, 0o644);
1915 !builder.config.dry_run
1921 /// Maybe add libLLVM.so to the target lib-dir for linking.
1922 pub fn maybe_install_llvm_target(builder: &Builder<'_>, target: TargetSelection, sysroot: &Path) {
1923 let dst_libdir = sysroot.join("lib/rustlib").join(&*target.triple).join("lib");
1924 // We do not need to copy LLVM files into the sysroot if it is not
1925 // dynamically linked; it is already included into librustc_llvm
1927 if builder.llvm_link_shared() {
1928 maybe_install_llvm(builder, target, &dst_libdir);
1932 /// Maybe add libLLVM.so to the runtime lib-dir for rustc itself.
1933 pub fn maybe_install_llvm_runtime(builder: &Builder<'_>, target: TargetSelection, sysroot: &Path) {
1935 sysroot.join(builder.sysroot_libdir_relative(Compiler { stage: 1, host: target }));
1936 // We do not need to copy LLVM files into the sysroot if it is not
1937 // dynamically linked; it is already included into librustc_llvm
1939 if builder.llvm_link_shared() {
1940 maybe_install_llvm(builder, target, &dst_libdir);
1944 #[derive(Clone, Debug, Eq, Hash, PartialEq)]
1945 pub struct LlvmTools {
1946 pub target: TargetSelection,
1949 impl Step for LlvmTools {
1950 type Output = Option<GeneratedTarball>;
1951 const ONLY_HOSTS: bool = true;
1952 const DEFAULT: bool = true;
1954 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1955 let default = should_build_extended_tool(&run.builder, "llvm-tools");
1956 // FIXME: allow using the names of the tools themselves?
1957 run.alias("llvm-tools").default_condition(default)
1960 fn make_run(run: RunConfig<'_>) {
1961 run.builder.ensure(LlvmTools { target: run.target });
1964 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
1965 let target = self.target;
1967 /* run only if llvm-config isn't used */
1968 if let Some(config) = builder.config.target_config.get(&target) {
1969 if let Some(ref _s) = config.llvm_config {
1970 builder.info(&format!("Skipping LlvmTools ({}): external LLVM", target));
1975 builder.ensure(crate::native::Llvm { target });
1977 let mut tarball = Tarball::new(builder, "llvm-tools", &target.triple);
1978 tarball.set_overlay(OverlayKind::LLVM);
1979 tarball.is_preview(true);
1981 // Prepare the image directory
1982 let src_bindir = builder.llvm_out(target).join("bin");
1983 let dst_bindir = format!("lib/rustlib/{}/bin", target.triple);
1984 for tool in LLVM_TOOLS {
1985 let exe = src_bindir.join(exe(tool, target));
1986 tarball.add_file(&exe, &dst_bindir, 0o755);
1989 // Copy libLLVM.so to the target lib dir as well, so the RPATH like
1990 // `$ORIGIN/../lib` can find it. It may also be used as a dependency
1991 // of `rustc-dev` to support the inherited `-lLLVM` when using the
1992 // compiler libraries.
1993 maybe_install_llvm_target(builder, target, tarball.image_dir());
1995 Some(tarball.generate())
1999 // Tarball intended for internal consumption to ease rustc/std development.
2001 // Should not be considered stable by end users.
2002 #[derive(Clone, Debug, Eq, Hash, PartialEq)]
2003 pub struct RustDev {
2004 pub target: TargetSelection,
2007 impl Step for RustDev {
2008 type Output = Option<GeneratedTarball>;
2009 const DEFAULT: bool = true;
2010 const ONLY_HOSTS: bool = true;
2012 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2013 run.alias("rust-dev")
2016 fn make_run(run: RunConfig<'_>) {
2017 run.builder.ensure(RustDev { target: run.target });
2020 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
2021 let target = self.target;
2023 /* run only if llvm-config isn't used */
2024 if let Some(config) = builder.config.target_config.get(&target) {
2025 if let Some(ref _s) = config.llvm_config {
2026 builder.info(&format!("Skipping RustDev ({}): external LLVM", target));
2031 let mut tarball = Tarball::new(builder, "rust-dev", &target.triple);
2032 tarball.set_overlay(OverlayKind::LLVM);
2034 builder.ensure(crate::native::Llvm { target });
2036 let src_bindir = builder.llvm_out(target).join("bin");
2037 // If updating this list, you likely want to change
2038 // src/bootstrap/download-ci-llvm-stamp as well, otherwise local users
2039 // will not pick up the extra file until LLVM gets bumped.
2051 tarball.add_file(src_bindir.join(exe(bin, target)), "bin", 0o755);
2054 // We don't build LLD on some platforms, so only add it if it exists
2055 let lld_path = builder.lld_out(target).join("bin").join(exe("lld", target));
2056 if lld_path.exists() {
2057 tarball.add_file(lld_path, "bin", 0o755);
2060 tarball.add_file(&builder.llvm_filecheck(target), "bin", 0o755);
2062 // Copy the include directory as well; needed mostly to build
2063 // librustc_llvm properly (e.g., llvm-config.h is in here). But also
2064 // just broadly useful to be able to link against the bundled LLVM.
2065 tarball.add_dir(&builder.llvm_out(target).join("include"), "include");
2067 // Copy libLLVM.so to the target lib dir as well, so the RPATH like
2068 // `$ORIGIN/../lib` can find it. It may also be used as a dependency
2069 // of `rustc-dev` to support the inherited `-lLLVM` when using the
2070 // compiler libraries.
2071 let dst_libdir = tarball.image_dir().join("lib");
2072 maybe_install_llvm(builder, target, &dst_libdir);
2073 let link_type = if builder.llvm_link_shared() { "dynamic" } else { "static" };
2074 t!(std::fs::write(tarball.image_dir().join("link-type.txt"), link_type), dst_libdir);
2076 Some(tarball.generate())
2080 /// Tarball containing a prebuilt version of the build-manifest tool, intended to be used by the
2081 /// release process to avoid cloning the monorepo and building stuff.
2083 /// Should not be considered stable by end users.
2084 #[derive(Clone, Debug, Eq, Hash, PartialEq)]
2085 pub struct BuildManifest {
2086 pub target: TargetSelection,
2089 impl Step for BuildManifest {
2090 type Output = GeneratedTarball;
2091 const DEFAULT: bool = false;
2092 const ONLY_HOSTS: bool = true;
2094 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2095 run.alias("build-manifest")
2098 fn make_run(run: RunConfig<'_>) {
2099 run.builder.ensure(BuildManifest { target: run.target });
2102 fn run(self, builder: &Builder<'_>) -> GeneratedTarball {
2103 let build_manifest = builder.tool_exe(Tool::BuildManifest);
2105 let tarball = Tarball::new(builder, "build-manifest", &self.target.triple);
2106 tarball.add_file(&build_manifest, "bin", 0o755);
2111 /// Tarball containing artifacts necessary to reproduce the build of rustc.
2113 /// Currently this is the PGO profile data.
2115 /// Should not be considered stable by end users.
2116 #[derive(Clone, Debug, Eq, Hash, PartialEq)]
2117 pub struct ReproducibleArtifacts {
2118 pub target: TargetSelection,
2121 impl Step for ReproducibleArtifacts {
2122 type Output = Option<GeneratedTarball>;
2123 const DEFAULT: bool = true;
2124 const ONLY_HOSTS: bool = true;
2126 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2127 run.alias("reproducible-artifacts")
2130 fn make_run(run: RunConfig<'_>) {
2131 run.builder.ensure(ReproducibleArtifacts { target: run.target });
2134 fn run(self, builder: &Builder<'_>) -> Self::Output {
2135 let mut added_anything = false;
2136 let tarball = Tarball::new(builder, "reproducible-artifacts", &self.target.triple);
2137 if let Some(path) = builder.config.rust_profile_use.as_ref() {
2138 tarball.add_file(path, ".", 0o644);
2139 added_anything = true;
2141 if let Some(path) = builder.config.llvm_profile_use.as_ref() {
2142 tarball.add_file(path, ".", 0o644);
2143 added_anything = true;
2145 if added_anything { Some(tarball.generate()) } else { None }