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};
21 use crate::config::TargetSelection;
22 use crate::tarball::{GeneratedTarball, OverlayKind, Tarball};
23 use crate::tool::{self, Tool};
24 use crate::util::{exe, is_dylib, output, t, timeit};
25 use crate::{Compiler, DependencyType, Mode, LLVM_TOOLS};
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 should_build_extended_tool(builder: &Builder<'_>, tool: &str) -> bool {
40 if !builder.config.extended {
43 builder.config.tools.as_ref().map_or(true, |tools| tools.contains(tool))
46 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
48 pub host: TargetSelection,
52 type Output = Option<GeneratedTarball>;
53 const DEFAULT: bool = true;
55 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
56 let default = run.builder.config.docs;
57 run.alias("rust-docs").default_condition(default)
60 fn make_run(run: RunConfig<'_>) {
61 run.builder.ensure(Docs { host: run.target });
64 /// Builds the `rust-docs` installer component.
65 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
67 builder.default_doc(&[]);
69 let dest = "share/doc/rust/html";
71 let mut tarball = Tarball::new(builder, "rust-docs", &host.triple);
72 tarball.set_product_name("Rust Documentation");
73 tarball.add_bulk_dir(&builder.doc_out(host), dest);
74 tarball.add_file(&builder.src.join("src/doc/robots.txt"), dest, 0o644);
75 Some(tarball.generate())
79 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
81 pub host: TargetSelection,
84 impl Step for JsonDocs {
85 type Output = Option<GeneratedTarball>;
86 const DEFAULT: bool = true;
88 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
89 let default = run.builder.config.docs;
90 run.alias("rust-docs-json").default_condition(default)
93 fn make_run(run: RunConfig<'_>) {
94 run.builder.ensure(JsonDocs { host: run.target });
97 /// Builds the `rust-docs-json` installer component.
98 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
100 builder.ensure(crate::doc::JsonStd { stage: builder.top_stage, target: host });
102 let dest = "share/doc/rust/json";
104 let mut tarball = Tarball::new(builder, "rust-docs-json", &host.triple);
105 tarball.set_product_name("Rust Documentation In JSON Format");
106 tarball.is_preview(true);
107 tarball.add_bulk_dir(&builder.json_doc_out(host), dest);
108 Some(tarball.generate())
112 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
113 pub struct RustcDocs {
114 pub host: TargetSelection,
117 impl Step for RustcDocs {
118 type Output = Option<GeneratedTarball>;
119 const DEFAULT: bool = true;
121 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
122 let builder = run.builder;
123 run.alias("rustc-docs").default_condition(builder.config.compiler_docs)
126 fn make_run(run: RunConfig<'_>) {
127 run.builder.ensure(RustcDocs { host: run.target });
130 /// Builds the `rustc-docs` installer component.
131 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
132 let host = self.host;
133 builder.default_doc(&[]);
135 let mut tarball = Tarball::new(builder, "rustc-docs", &host.triple);
136 tarball.set_product_name("Rustc Documentation");
137 tarball.add_bulk_dir(&builder.compiler_doc_out(host), "share/doc/rust/html/rustc");
138 Some(tarball.generate())
142 fn find_files(files: &[&str], path: &[PathBuf]) -> Vec<PathBuf> {
143 let mut found = Vec::with_capacity(files.len());
146 let file_path = path.iter().map(|dir| dir.join(file)).find(|p| p.exists());
148 if let Some(file_path) = file_path {
149 found.push(file_path);
151 panic!("Could not find '{}' in {:?}", file, path);
161 target: TargetSelection,
162 builder: &Builder<'_>,
164 //Ask gcc where it keeps its stuff
165 let mut cmd = Command::new(builder.cc(target));
166 cmd.arg("-print-search-dirs");
167 let gcc_out = output(&mut cmd);
169 let mut bin_path: Vec<_> = env::split_paths(&env::var_os("PATH").unwrap_or_default()).collect();
170 let mut lib_path = Vec::new();
172 for line in gcc_out.lines() {
173 let idx = line.find(':').unwrap();
174 let key = &line[..idx];
175 let trim_chars: &[_] = &[' ', '='];
176 let value = env::split_paths(line[(idx + 1)..].trim_start_matches(trim_chars));
178 if key == "programs" {
179 bin_path.extend(value);
180 } else if key == "libraries" {
181 lib_path.extend(value);
185 let compiler = if target == "i686-pc-windows-gnu" {
186 "i686-w64-mingw32-gcc.exe"
187 } else if target == "x86_64-pc-windows-gnu" {
188 "x86_64-w64-mingw32-gcc.exe"
192 let target_tools = [compiler, "ld.exe", "dlltool.exe", "libwinpthread-1.dll"];
193 let mut rustc_dlls = vec!["libwinpthread-1.dll"];
194 if target.starts_with("i686-") {
195 rustc_dlls.push("libgcc_s_dw2-1.dll");
197 rustc_dlls.push("libgcc_s_seh-1.dll");
212 //Windows import libs
235 "libsynchronization.a",
246 //Find mingw artifacts we want to bundle
247 let target_tools = find_files(&target_tools, &bin_path);
248 let rustc_dlls = find_files(&rustc_dlls, &bin_path);
249 let target_libs = find_files(&target_libs, &lib_path);
251 // Copy runtime dlls next to rustc.exe
252 let dist_bin_dir = rust_root.join("bin/");
253 fs::create_dir_all(&dist_bin_dir).expect("creating dist_bin_dir failed");
254 for src in rustc_dlls {
255 builder.copy_to_folder(&src, &dist_bin_dir);
258 //Copy platform tools to platform-specific bin directory
259 let target_bin_dir = plat_root
264 .join("self-contained");
265 fs::create_dir_all(&target_bin_dir).expect("creating target_bin_dir failed");
266 for src in target_tools {
267 builder.copy_to_folder(&src, &target_bin_dir);
270 // Warn windows-gnu users that the bundled GCC cannot compile C files
272 &target_bin_dir.join("GCC-WARNING.txt"),
273 "gcc.exe contained in this folder cannot be used for compiling C files - it is only \
274 used as a linker. In order to be able to compile projects containing C code use \
275 the GCC provided by MinGW or Cygwin.",
278 //Copy platform libs to platform-specific lib directory
279 let target_lib_dir = plat_root
284 .join("self-contained");
285 fs::create_dir_all(&target_lib_dir).expect("creating target_lib_dir failed");
286 for src in target_libs {
287 builder.copy_to_folder(&src, &target_lib_dir);
291 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
293 pub host: TargetSelection,
296 impl Step for Mingw {
297 type Output = Option<GeneratedTarball>;
298 const DEFAULT: bool = true;
300 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
301 run.alias("rust-mingw")
304 fn make_run(run: RunConfig<'_>) {
305 run.builder.ensure(Mingw { host: run.target });
308 /// Builds the `rust-mingw` installer component.
310 /// This contains all the bits and pieces to run the MinGW Windows targets
311 /// without any extra installed software (e.g., we bundle gcc, libraries, etc).
312 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
313 let host = self.host;
314 if !host.ends_with("pc-windows-gnu") {
318 let mut tarball = Tarball::new(builder, "rust-mingw", &host.triple);
319 tarball.set_product_name("Rust MinGW");
321 // The first argument is a "temporary directory" which is just
322 // thrown away (this contains the runtime DLLs included in the rustc package
323 // above) and the second argument is where to place all the MinGW components
324 // (which is what we want).
325 make_win_dist(&tmpdir(builder), tarball.image_dir(), host, &builder);
327 Some(tarball.generate())
331 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
333 pub compiler: Compiler,
336 impl Step for Rustc {
337 type Output = GeneratedTarball;
338 const DEFAULT: bool = true;
339 const ONLY_HOSTS: bool = true;
341 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
345 fn make_run(run: RunConfig<'_>) {
347 .ensure(Rustc { compiler: run.builder.compiler(run.builder.top_stage, run.target) });
350 /// Creates the `rustc` installer component.
351 fn run(self, builder: &Builder<'_>) -> GeneratedTarball {
352 let compiler = self.compiler;
353 let host = self.compiler.host;
355 let tarball = Tarball::new(builder, "rustc", &host.triple);
357 // Prepare the rustc "image", what will actually end up getting installed
358 prepare_image(builder, compiler, tarball.image_dir());
360 // On MinGW we've got a few runtime DLL dependencies that we need to
361 // include. The first argument to this script is where to put these DLLs
362 // (the image we're creating), and the second argument is a junk directory
363 // to ignore all other MinGW stuff the script creates.
365 // On 32-bit MinGW we're always including a DLL which needs some extra
366 // licenses to distribute. On 64-bit MinGW we don't actually distribute
367 // anything requiring us to distribute a license, but it's likely the
368 // install will *also* include the rust-mingw package, which also needs
369 // licenses, so to be safe we just include it here in all MinGW packages.
370 if host.ends_with("pc-windows-gnu") {
371 make_win_dist(tarball.image_dir(), &tmpdir(builder), host, builder);
372 tarball.add_dir(builder.src.join("src/etc/third-party"), "share/doc");
375 return tarball.generate();
377 fn prepare_image(builder: &Builder<'_>, compiler: Compiler, image: &Path) {
378 let host = compiler.host;
379 let src = builder.sysroot(compiler);
381 // Copy rustc/rustdoc binaries
382 t!(fs::create_dir_all(image.join("bin")));
383 builder.cp_r(&src.join("bin"), &image.join("bin"));
385 builder.install(&builder.rustdoc(compiler), &image.join("bin"), 0o755);
387 let ra_proc_macro_srv = builder
388 .ensure(tool::RustAnalyzerProcMacroSrv {
389 compiler: builder.compiler_for(
391 builder.config.build,
394 target: compiler.host,
396 .expect("rust-analyzer-proc-macro-server always builds");
397 builder.install(&ra_proc_macro_srv, &image.join("libexec"), 0o755);
399 let libdir_relative = builder.libdir_relative(compiler);
401 // Copy runtime DLLs needed by the compiler
402 if libdir_relative.to_str() != Some("bin") {
403 let libdir = builder.rustc_libdir(compiler);
404 for entry in builder.read_dir(&libdir) {
405 let name = entry.file_name();
406 if let Some(s) = name.to_str() {
408 // Don't use custom libdir here because ^lib/ will be resolved again
410 builder.install(&entry.path(), &image.join("lib"), 0o644);
416 // Copy over the codegen backends
417 let backends_src = builder.sysroot_codegen_backends(compiler);
418 let backends_rel = backends_src
421 .strip_prefix(builder.sysroot_libdir_relative(compiler))
423 // Don't use custom libdir here because ^lib/ will be resolved again with installer
424 let backends_dst = image.join("lib").join(&backends_rel);
426 t!(fs::create_dir_all(&backends_dst));
427 builder.cp_r(&backends_src, &backends_dst);
429 // Copy libLLVM.so to the lib dir as well, if needed. While not
430 // technically needed by rustc itself it's needed by lots of other
431 // components like the llvm tools and LLD. LLD is included below and
432 // tools/LLDB come later, so let's just throw it in the rustc
433 // component for now.
434 maybe_install_llvm_runtime(builder, host, image);
436 let dst_dir = image.join("lib/rustlib").join(&*host.triple).join("bin");
437 t!(fs::create_dir_all(&dst_dir));
439 // Copy over lld if it's there
440 if builder.config.lld_enabled {
441 let src_dir = builder.sysroot_libdir(compiler, host).parent().unwrap().join("bin");
442 let rust_lld = exe("rust-lld", compiler.host);
443 builder.copy(&src_dir.join(&rust_lld), &dst_dir.join(&rust_lld));
444 // for `-Z gcc-ld=lld`
445 let gcc_lld_src_dir = src_dir.join("gcc-ld");
446 let gcc_lld_dst_dir = dst_dir.join("gcc-ld");
447 t!(fs::create_dir(&gcc_lld_dst_dir));
448 for name in crate::LLD_FILE_NAMES {
449 let exe_name = exe(name, compiler.host);
451 .copy(&gcc_lld_src_dir.join(&exe_name), &gcc_lld_dst_dir.join(&exe_name));
456 t!(fs::create_dir_all(image.join("share/man/man1")));
457 let man_src = builder.src.join("src/doc/man");
458 let man_dst = image.join("share/man/man1");
460 // don't use our `bootstrap::util::{copy, cp_r}`, because those try
461 // to hardlink, and we don't want to edit the source templates
462 for file_entry in builder.read_dir(&man_src) {
463 let page_src = file_entry.path();
464 let page_dst = man_dst.join(file_entry.file_name());
465 let src_text = t!(std::fs::read_to_string(&page_src));
466 let new_text = src_text.replace("<INSERT VERSION HERE>", &builder.version);
467 t!(std::fs::write(&page_dst, &new_text));
468 t!(fs::copy(&page_src, &page_dst));
473 .ensure(DebuggerScripts { sysroot: INTERNER.intern_path(image.to_owned()), host });
476 let cp = |file: &str| {
477 builder.install(&builder.src.join(file), &image.join("share/doc/rust"), 0o644);
480 cp("LICENSE-APACHE");
487 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
488 pub struct DebuggerScripts {
489 pub sysroot: Interned<PathBuf>,
490 pub host: TargetSelection,
493 impl Step for DebuggerScripts {
496 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
500 /// Copies debugger scripts for `target` into the `sysroot` specified.
501 fn run(self, builder: &Builder<'_>) {
502 let host = self.host;
503 let sysroot = self.sysroot;
504 let dst = sysroot.join("lib/rustlib/etc");
505 t!(fs::create_dir_all(&dst));
506 let cp_debugger_script = |file: &str| {
507 builder.install(&builder.src.join("src/etc/").join(file), &dst, 0o644);
509 if host.contains("windows-msvc") {
510 // windbg debugger scripts
512 &builder.src.join("src/etc/rust-windbg.cmd"),
513 &sysroot.join("bin"),
517 cp_debugger_script("natvis/intrinsic.natvis");
518 cp_debugger_script("natvis/liballoc.natvis");
519 cp_debugger_script("natvis/libcore.natvis");
520 cp_debugger_script("natvis/libstd.natvis");
522 cp_debugger_script("rust_types.py");
524 // gdb debugger scripts
525 builder.install(&builder.src.join("src/etc/rust-gdb"), &sysroot.join("bin"), 0o755);
526 builder.install(&builder.src.join("src/etc/rust-gdbgui"), &sysroot.join("bin"), 0o755);
528 cp_debugger_script("gdb_load_rust_pretty_printers.py");
529 cp_debugger_script("gdb_lookup.py");
530 cp_debugger_script("gdb_providers.py");
532 // lldb debugger scripts
533 builder.install(&builder.src.join("src/etc/rust-lldb"), &sysroot.join("bin"), 0o755);
535 cp_debugger_script("lldb_lookup.py");
536 cp_debugger_script("lldb_providers.py");
537 cp_debugger_script("lldb_commands")
542 fn skip_host_target_lib(builder: &Builder<'_>, compiler: Compiler) -> bool {
543 // The only true set of target libraries came from the build triple, so
544 // let's reduce redundant work by only producing archives from that host.
545 if compiler.host != builder.config.build {
546 builder.info("\tskipping, not a build host");
553 /// Copy stamped files into an image's `target/lib` directory.
554 fn copy_target_libs(builder: &Builder<'_>, target: TargetSelection, image: &Path, stamp: &Path) {
555 let dst = image.join("lib/rustlib").join(target.triple).join("lib");
556 let self_contained_dst = dst.join("self-contained");
557 t!(fs::create_dir_all(&dst));
558 t!(fs::create_dir_all(&self_contained_dst));
559 for (path, dependency_type) in builder.read_stamp_file(stamp) {
560 if dependency_type == DependencyType::TargetSelfContained {
561 builder.copy(&path, &self_contained_dst.join(path.file_name().unwrap()));
562 } else if dependency_type == DependencyType::Target || builder.config.build == target {
563 builder.copy(&path, &dst.join(path.file_name().unwrap()));
568 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
570 pub compiler: Compiler,
571 pub target: TargetSelection,
575 type Output = Option<GeneratedTarball>;
576 const DEFAULT: bool = true;
578 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
579 run.alias("rust-std")
582 fn make_run(run: RunConfig<'_>) {
583 run.builder.ensure(Std {
584 compiler: run.builder.compiler_for(
585 run.builder.top_stage,
586 run.builder.config.build,
593 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
594 let compiler = self.compiler;
595 let target = self.target;
597 if skip_host_target_lib(builder, compiler) {
601 builder.ensure(compile::Std::new(compiler, target));
603 let mut tarball = Tarball::new(builder, "rust-std", &target.triple);
604 tarball.include_target_in_component_name(true);
606 let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target);
607 let stamp = compile::libstd_stamp(builder, compiler_to_use, target);
608 copy_target_libs(builder, target, &tarball.image_dir(), &stamp);
610 Some(tarball.generate())
614 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
615 pub struct RustcDev {
616 pub compiler: Compiler,
617 pub target: TargetSelection,
620 impl Step for RustcDev {
621 type Output = Option<GeneratedTarball>;
622 const DEFAULT: bool = true;
623 const ONLY_HOSTS: bool = true;
625 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
626 run.alias("rustc-dev")
629 fn make_run(run: RunConfig<'_>) {
630 run.builder.ensure(RustcDev {
631 compiler: run.builder.compiler_for(
632 run.builder.top_stage,
633 run.builder.config.build,
640 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
641 let compiler = self.compiler;
642 let target = self.target;
643 if skip_host_target_lib(builder, compiler) {
647 builder.ensure(compile::Rustc::new(compiler, target));
649 let tarball = Tarball::new(builder, "rustc-dev", &target.triple);
651 let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target);
652 let stamp = compile::librustc_stamp(builder, compiler_to_use, target);
653 copy_target_libs(builder, target, tarball.image_dir(), &stamp);
655 let src_files = &["Cargo.lock"];
656 // This is the reduced set of paths which will become the rustc-dev component
657 // (essentially the compiler crates and all of their path dependencies).
663 &tarball.image_dir().join("lib/rustlib/rustc-src/rust"),
665 for file in src_files {
666 tarball.add_file(builder.src.join(file), "lib/rustlib/rustc-src/rust", 0o644);
669 Some(tarball.generate())
673 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
674 pub struct Analysis {
675 pub compiler: Compiler,
676 pub target: TargetSelection,
679 impl Step for Analysis {
680 type Output = Option<GeneratedTarball>;
681 const DEFAULT: bool = true;
683 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
684 let default = should_build_extended_tool(&run.builder, "analysis");
685 run.alias("rust-analysis").default_condition(default)
688 fn make_run(run: RunConfig<'_>) {
689 run.builder.ensure(Analysis {
690 // Find the actual compiler (handling the full bootstrap option) which
691 // produced the save-analysis data because that data isn't copied
692 // through the sysroot uplifting.
693 compiler: run.builder.compiler_for(
694 run.builder.top_stage,
695 run.builder.config.build,
702 /// Creates a tarball of save-analysis metadata, if available.
703 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
704 let compiler = self.compiler;
705 let target = self.target;
706 if compiler.host != builder.config.build {
710 builder.ensure(compile::Std::new(compiler, target));
712 .stage_out(compiler, Mode::Std)
714 .join(builder.cargo_dir())
716 .join("save-analysis");
718 let mut tarball = Tarball::new(builder, "rust-analysis", &target.triple);
719 tarball.include_target_in_component_name(true);
720 tarball.add_dir(src, format!("lib/rustlib/{}/analysis", target.triple));
721 Some(tarball.generate())
725 /// Use the `builder` to make a filtered copy of `base`/X for X in (`src_dirs` - `exclude_dirs`) to
728 builder: &Builder<'_>,
731 exclude_dirs: &[&str],
734 fn filter_fn(exclude_dirs: &[&str], dir: &str, path: &Path) -> bool {
735 let spath = match path.to_str() {
737 None => return false,
739 if spath.ends_with('~') || spath.ends_with(".pyc") {
743 const LLVM_PROJECTS: &[&str] = &[
744 "llvm-project/clang",
745 "llvm-project\\clang",
746 "llvm-project/libunwind",
747 "llvm-project\\libunwind",
751 "llvm-project\\lldb",
753 "llvm-project\\llvm",
754 "llvm-project/compiler-rt",
755 "llvm-project\\compiler-rt",
756 "llvm-project/cmake",
757 "llvm-project\\cmake",
759 if spath.contains("llvm-project")
760 && !spath.ends_with("llvm-project")
761 && !LLVM_PROJECTS.iter().any(|path| spath.contains(path))
766 const LLVM_TEST: &[&str] = &["llvm-project/llvm/test", "llvm-project\\llvm\\test"];
767 if LLVM_TEST.iter().any(|path| spath.contains(path))
768 && (spath.ends_with(".ll") || spath.ends_with(".td") || spath.ends_with(".s"))
773 let full_path = Path::new(dir).join(path);
774 if exclude_dirs.iter().any(|excl| full_path == Path::new(excl)) {
801 !path.iter().map(|s| s.to_str().unwrap()).any(|s| excludes.contains(&s))
804 // Copy the directories using our filter
805 for item in src_dirs {
806 let dst = &dst_dir.join(item);
807 t!(fs::create_dir_all(dst));
808 builder.cp_filtered(&base.join(item), dst, &|path| filter_fn(exclude_dirs, item, path));
812 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
816 /// The output path of the src installer tarball
817 type Output = GeneratedTarball;
818 const DEFAULT: bool = true;
819 const ONLY_HOSTS: bool = true;
821 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
822 run.alias("rust-src")
825 fn make_run(run: RunConfig<'_>) {
826 run.builder.ensure(Src);
829 /// Creates the `rust-src` installer component
830 fn run(self, builder: &Builder<'_>) -> GeneratedTarball {
831 let tarball = Tarball::new_targetless(builder, "rust-src");
833 // A lot of tools expect the rust-src component to be entirely in this directory, so if you
834 // change that (e.g. by adding another directory `lib/rustlib/src/foo` or
835 // `lib/rustlib/src/rust/foo`), you will need to go around hunting for implicit assumptions
838 // NOTE: if you update the paths here, you also should update the "virtual" path
839 // translation code in `imported_source_files` in `src/librustc_metadata/rmeta/decoder.rs`
840 let dst_src = tarball.image_dir().join("lib/rustlib/src/rust");
842 let src_files = ["Cargo.lock"];
843 // This is the reduced set of paths which will become the rust-src component
844 // (essentially libstd and all of its path dependencies).
848 &["library", "src/llvm-project/libunwind"],
850 // not needed and contains symlinks which rustup currently
851 // chokes on when unpacking.
852 "library/backtrace/crates",
853 // these are 30MB combined and aren't necessary for building
854 // the standard library.
855 "library/stdarch/Cargo.toml",
856 "library/stdarch/crates/stdarch-verify",
857 "library/stdarch/crates/intrinsic-test",
861 for file in src_files.iter() {
862 builder.copy(&builder.src.join(file), &dst_src.join(file));
869 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
870 pub struct PlainSourceTarball;
872 impl Step for PlainSourceTarball {
873 /// Produces the location of the tarball generated
874 type Output = GeneratedTarball;
875 const DEFAULT: bool = true;
876 const ONLY_HOSTS: bool = true;
878 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
879 let builder = run.builder;
880 run.alias("rustc-src").default_condition(builder.config.rust_dist_src)
883 fn make_run(run: RunConfig<'_>) {
884 run.builder.ensure(PlainSourceTarball);
887 /// Creates the plain source tarball
888 fn run(self, builder: &Builder<'_>) -> GeneratedTarball {
889 // NOTE: This is a strange component in a lot of ways. It uses `src` as the target, which
890 // means neither rustup nor rustup-toolchain-install-master know how to download it.
891 // It also contains symbolic links, unlike other any other dist tarball.
892 // It's used for distros building rustc from source in a pre-vendored environment.
893 let mut tarball = Tarball::new(builder, "rustc", "src");
894 tarball.permit_symlinks(true);
895 let plain_dst_src = tarball.image_dir();
897 // This is the set of root paths which will become part of the source package
907 "config.toml.example",
911 let src_dirs = ["src", "compiler", "library"];
913 copy_src_dirs(builder, &builder.src, &src_dirs, &[], &plain_dst_src);
915 // Copy the files normally
916 for item in &src_files {
917 builder.copy(&builder.src.join(item), &plain_dst_src.join(item));
920 // Create the version file
921 builder.create(&plain_dst_src.join("version"), &builder.rust_version());
922 if let Some(info) = builder.rust_info.info() {
923 channel::write_commit_hash_file(&plain_dst_src, &info.sha);
924 channel::write_commit_info_file(&plain_dst_src, info);
927 // If we're building from git sources, we need to vendor a complete distribution.
928 if builder.rust_info.is_managed_git_subrepository() {
929 // Ensure we have the submodules checked out.
930 builder.update_submodule(Path::new("src/tools/rust-analyzer"));
932 // Vendor all Cargo dependencies
933 let mut cmd = Command::new(&builder.initial_cargo);
936 .arg(builder.src.join("./src/tools/rust-analyzer/Cargo.toml"))
938 .arg(builder.src.join("./compiler/rustc_codegen_cranelift/Cargo.toml"))
940 .arg(builder.src.join("./src/bootstrap/Cargo.toml"))
941 .current_dir(&plain_dst_src);
943 let config = if !builder.config.dry_run {
944 t!(String::from_utf8(t!(cmd.output()).stdout))
949 let cargo_config_dir = plain_dst_src.join(".cargo");
950 builder.create_dir(&cargo_config_dir);
951 builder.create(&cargo_config_dir.join("config.toml"), &config);
958 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
960 pub compiler: Compiler,
961 pub target: TargetSelection,
964 impl Step for Cargo {
965 type Output = Option<GeneratedTarball>;
966 const DEFAULT: bool = true;
967 const ONLY_HOSTS: bool = true;
969 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
970 let default = should_build_extended_tool(&run.builder, "cargo");
971 run.alias("cargo").default_condition(default)
974 fn make_run(run: RunConfig<'_>) {
975 run.builder.ensure(Cargo {
976 compiler: run.builder.compiler_for(
977 run.builder.top_stage,
978 run.builder.config.build,
985 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
986 let compiler = self.compiler;
987 let target = self.target;
989 let cargo = builder.ensure(tool::Cargo { compiler, target });
990 let src = builder.src.join("src/tools/cargo");
991 let etc = src.join("src/etc");
993 // Prepare the image directory
994 let mut tarball = Tarball::new(builder, "cargo", &target.triple);
995 tarball.set_overlay(OverlayKind::Cargo);
997 tarball.add_file(&cargo, "bin", 0o755);
998 tarball.add_file(etc.join("_cargo"), "share/zsh/site-functions", 0o644);
999 tarball.add_renamed_file(etc.join("cargo.bashcomp.sh"), "etc/bash_completion.d", "cargo");
1000 tarball.add_dir(etc.join("man"), "share/man/man1");
1001 tarball.add_legal_and_readme_to("share/doc/cargo");
1003 for dirent in fs::read_dir(cargo.parent().unwrap()).expect("read_dir") {
1004 let dirent = dirent.expect("read dir entry");
1005 if dirent.file_name().to_str().expect("utf8").starts_with("cargo-credential-") {
1006 tarball.add_file(&dirent.path(), "libexec", 0o755);
1010 Some(tarball.generate())
1014 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
1016 pub compiler: Compiler,
1017 pub target: TargetSelection,
1021 type Output = Option<GeneratedTarball>;
1022 const ONLY_HOSTS: bool = true;
1023 const DEFAULT: bool = true;
1025 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1026 let default = should_build_extended_tool(&run.builder, "rls");
1027 run.alias("rls").default_condition(default)
1030 fn make_run(run: RunConfig<'_>) {
1031 run.builder.ensure(Rls {
1032 compiler: run.builder.compiler_for(
1033 run.builder.top_stage,
1034 run.builder.config.build,
1041 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
1042 let compiler = self.compiler;
1043 let target = self.target;
1046 .ensure(tool::Rls { compiler, target, extra_features: Vec::new() })
1047 .expect("rls expected to build");
1049 let mut tarball = Tarball::new(builder, "rls", &target.triple);
1050 tarball.set_overlay(OverlayKind::RLS);
1051 tarball.is_preview(true);
1052 tarball.add_file(rls, "bin", 0o755);
1053 tarball.add_legal_and_readme_to("share/doc/rls");
1054 Some(tarball.generate())
1058 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
1059 pub struct RustAnalyzer {
1060 pub compiler: Compiler,
1061 pub target: TargetSelection,
1064 impl Step for RustAnalyzer {
1065 type Output = Option<GeneratedTarball>;
1066 const DEFAULT: bool = true;
1067 const ONLY_HOSTS: bool = true;
1069 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1070 let default = should_build_extended_tool(&run.builder, "rust-analyzer");
1071 run.alias("rust-analyzer").default_condition(default)
1074 fn make_run(run: RunConfig<'_>) {
1075 run.builder.ensure(RustAnalyzer {
1076 compiler: run.builder.compiler_for(
1077 run.builder.top_stage,
1078 run.builder.config.build,
1085 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
1086 let compiler = self.compiler;
1087 let target = self.target;
1089 if target.contains("riscv64") {
1090 // riscv64 currently has an LLVM bug that makes rust-analyzer unable
1091 // to build. See #74813 for details.
1095 let rust_analyzer = builder
1096 .ensure(tool::RustAnalyzer { compiler, target })
1097 .expect("rust-analyzer always builds");
1099 let mut tarball = Tarball::new(builder, "rust-analyzer", &target.triple);
1100 tarball.set_overlay(OverlayKind::RustAnalyzer);
1101 tarball.is_preview(true);
1102 tarball.add_file(rust_analyzer, "bin", 0o755);
1103 tarball.add_legal_and_readme_to("share/doc/rust-analyzer");
1104 Some(tarball.generate())
1108 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
1110 pub compiler: Compiler,
1111 pub target: TargetSelection,
1114 impl Step for Clippy {
1115 type Output = Option<GeneratedTarball>;
1116 const DEFAULT: bool = true;
1117 const ONLY_HOSTS: bool = true;
1119 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1120 let default = should_build_extended_tool(&run.builder, "clippy");
1121 run.alias("clippy").default_condition(default)
1124 fn make_run(run: RunConfig<'_>) {
1125 run.builder.ensure(Clippy {
1126 compiler: run.builder.compiler_for(
1127 run.builder.top_stage,
1128 run.builder.config.build,
1135 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
1136 let compiler = self.compiler;
1137 let target = self.target;
1139 // Prepare the image directory
1140 // We expect clippy to build, because we've exited this step above if tool
1141 // state for clippy isn't testing.
1142 let clippy = builder
1143 .ensure(tool::Clippy { compiler, target, extra_features: Vec::new() })
1144 .expect("clippy expected to build - essential tool");
1145 let cargoclippy = builder
1146 .ensure(tool::CargoClippy { compiler, target, extra_features: Vec::new() })
1147 .expect("clippy expected to build - essential tool");
1149 let mut tarball = Tarball::new(builder, "clippy", &target.triple);
1150 tarball.set_overlay(OverlayKind::Clippy);
1151 tarball.is_preview(true);
1152 tarball.add_file(clippy, "bin", 0o755);
1153 tarball.add_file(cargoclippy, "bin", 0o755);
1154 tarball.add_legal_and_readme_to("share/doc/clippy");
1155 Some(tarball.generate())
1159 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
1161 pub compiler: Compiler,
1162 pub target: TargetSelection,
1165 impl Step for Miri {
1166 type Output = Option<GeneratedTarball>;
1167 const DEFAULT: bool = true;
1168 const ONLY_HOSTS: bool = true;
1170 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1171 let default = should_build_extended_tool(&run.builder, "miri");
1172 run.alias("miri").default_condition(default)
1175 fn make_run(run: RunConfig<'_>) {
1176 run.builder.ensure(Miri {
1177 compiler: run.builder.compiler_for(
1178 run.builder.top_stage,
1179 run.builder.config.build,
1186 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
1187 // This prevents miri from being built for "dist" or "install"
1188 // on the stable/beta channels. It is a nightly-only tool and should
1190 if !builder.build.unstable_features() {
1193 let compiler = self.compiler;
1194 let target = self.target;
1196 let miri = builder.ensure(tool::Miri { compiler, target, extra_features: Vec::new() })?;
1198 builder.ensure(tool::CargoMiri { compiler, target, extra_features: Vec::new() })?;
1200 let mut tarball = Tarball::new(builder, "miri", &target.triple);
1201 tarball.set_overlay(OverlayKind::Miri);
1202 tarball.is_preview(true);
1203 tarball.add_file(miri, "bin", 0o755);
1204 tarball.add_file(cargomiri, "bin", 0o755);
1205 tarball.add_legal_and_readme_to("share/doc/miri");
1206 Some(tarball.generate())
1210 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
1211 pub struct Rustfmt {
1212 pub compiler: Compiler,
1213 pub target: TargetSelection,
1216 impl Step for Rustfmt {
1217 type Output = Option<GeneratedTarball>;
1218 const DEFAULT: bool = true;
1219 const ONLY_HOSTS: bool = true;
1221 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1222 let default = should_build_extended_tool(&run.builder, "rustfmt");
1223 run.alias("rustfmt").default_condition(default)
1226 fn make_run(run: RunConfig<'_>) {
1227 run.builder.ensure(Rustfmt {
1228 compiler: run.builder.compiler_for(
1229 run.builder.top_stage,
1230 run.builder.config.build,
1237 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
1238 let compiler = self.compiler;
1239 let target = self.target;
1241 let rustfmt = builder
1242 .ensure(tool::Rustfmt { compiler, target, extra_features: Vec::new() })
1243 .expect("rustfmt expected to build - essential tool");
1244 let cargofmt = builder
1245 .ensure(tool::Cargofmt { compiler, target, extra_features: Vec::new() })
1246 .expect("cargo fmt expected to build - essential tool");
1247 let mut tarball = Tarball::new(builder, "rustfmt", &target.triple);
1248 tarball.set_overlay(OverlayKind::Rustfmt);
1249 tarball.is_preview(true);
1250 tarball.add_file(rustfmt, "bin", 0o755);
1251 tarball.add_file(cargofmt, "bin", 0o755);
1252 tarball.add_legal_and_readme_to("share/doc/rustfmt");
1253 Some(tarball.generate())
1257 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
1258 pub struct RustDemangler {
1259 pub compiler: Compiler,
1260 pub target: TargetSelection,
1263 impl Step for RustDemangler {
1264 type Output = Option<GeneratedTarball>;
1265 const DEFAULT: bool = true;
1266 const ONLY_HOSTS: bool = true;
1268 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1269 // While other tools use `should_build_extended_tool` to decide whether to be run by
1270 // default or not, `rust-demangler` must be build when *either* it's enabled as a tool like
1271 // the other ones or if `profiler = true`. Because we don't know the target at this stage
1272 // we run the step by default when only `extended = true`, and decide whether to actually
1273 // run it or not later.
1274 let default = run.builder.config.extended;
1275 run.alias("rust-demangler").default_condition(default)
1278 fn make_run(run: RunConfig<'_>) {
1279 run.builder.ensure(RustDemangler {
1280 compiler: run.builder.compiler_for(
1281 run.builder.top_stage,
1282 run.builder.config.build,
1289 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
1290 let compiler = self.compiler;
1291 let target = self.target;
1293 // Only build this extended tool if explicitly included in `tools`, or if `profiler = true`
1294 let condition = should_build_extended_tool(builder, "rust-demangler")
1295 || builder.config.profiler_enabled(target);
1296 if builder.config.extended && !condition {
1300 let rust_demangler = builder
1301 .ensure(tool::RustDemangler { compiler, target, extra_features: Vec::new() })
1302 .expect("rust-demangler expected to build - in-tree tool");
1304 // Prepare the image directory
1305 let mut tarball = Tarball::new(builder, "rust-demangler", &target.triple);
1306 tarball.set_overlay(OverlayKind::RustDemangler);
1307 tarball.is_preview(true);
1308 tarball.add_file(&rust_demangler, "bin", 0o755);
1309 tarball.add_legal_and_readme_to("share/doc/rust-demangler");
1310 Some(tarball.generate())
1314 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
1315 pub struct Extended {
1317 host: TargetSelection,
1318 target: TargetSelection,
1321 impl Step for Extended {
1323 const DEFAULT: bool = true;
1324 const ONLY_HOSTS: bool = true;
1326 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1327 let builder = run.builder;
1328 run.alias("extended").default_condition(builder.config.extended)
1331 fn make_run(run: RunConfig<'_>) {
1332 run.builder.ensure(Extended {
1333 stage: run.builder.top_stage,
1334 host: run.builder.config.build,
1339 /// Creates a combined installer for the specified target in the provided stage.
1340 fn run(self, builder: &Builder<'_>) {
1341 let target = self.target;
1342 let stage = self.stage;
1343 let compiler = builder.compiler_for(self.stage, self.host, self.target);
1345 builder.info(&format!("Dist extended stage{} ({})", compiler.stage, target));
1347 let mut tarballs = Vec::new();
1348 let mut built_tools = HashSet::new();
1349 macro_rules! add_component {
1350 ($name:expr => $step:expr) => {
1351 if let Some(tarball) = builder.ensure_if_default($step, Kind::Dist) {
1352 tarballs.push(tarball);
1353 built_tools.insert($name);
1358 // When rust-std package split from rustc, we needed to ensure that during
1359 // upgrades rustc was upgraded before rust-std. To avoid rustc clobbering
1360 // the std files during uninstall. To do this ensure that rustc comes
1361 // before rust-std in the list below.
1362 tarballs.push(builder.ensure(Rustc { compiler: builder.compiler(stage, target) }));
1363 tarballs.push(builder.ensure(Std { compiler, target }).expect("missing std"));
1365 if target.ends_with("windows-gnu") {
1366 tarballs.push(builder.ensure(Mingw { host: target }).expect("missing mingw"));
1369 add_component!("rust-docs" => Docs { host: target });
1370 add_component!("rust-json-docs" => JsonDocs { host: target });
1371 add_component!("rust-demangler"=> RustDemangler { compiler, target });
1372 add_component!("cargo" => Cargo { compiler, target });
1373 add_component!("rustfmt" => Rustfmt { compiler, target });
1374 add_component!("rls" => Rls { compiler, target });
1375 add_component!("rust-analyzer" => RustAnalyzer { compiler, target });
1376 add_component!("llvm-components" => LlvmTools { target });
1377 add_component!("clippy" => Clippy { compiler, target });
1378 add_component!("miri" => Miri { compiler, target });
1379 add_component!("analysis" => Analysis { compiler, target });
1381 let etc = builder.src.join("src/etc/installer");
1383 // Avoid producing tarballs during a dry run.
1384 if builder.config.dry_run {
1388 let tarball = Tarball::new(builder, "rust", &target.triple);
1389 let generated = tarball.combine(&tarballs);
1391 let tmp = tmpdir(builder).join("combined-tarball");
1392 let work = generated.work_dir();
1394 let mut license = String::new();
1395 license += &builder.read(&builder.src.join("COPYRIGHT"));
1396 license += &builder.read(&builder.src.join("LICENSE-APACHE"));
1397 license += &builder.read(&builder.src.join("LICENSE-MIT"));
1401 let rtf = r"{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 Arial;}}\nowwrap\fs18";
1402 let mut rtf = rtf.to_string();
1404 for line in license.lines() {
1406 rtf.push_str("\\line ");
1410 fn filter(contents: &str, marker: &str) -> String {
1411 let start = format!("tool-{}-start", marker);
1412 let end = format!("tool-{}-end", marker);
1413 let mut lines = Vec::new();
1414 let mut omitted = false;
1415 for line in contents.lines() {
1416 if line.contains(&start) {
1418 } else if line.contains(&end) {
1420 } else if !omitted {
1428 let xform = |p: &Path| {
1429 let mut contents = t!(fs::read_to_string(p));
1430 for tool in &["rust-demangler"] {
1431 if !built_tools.contains(tool) {
1432 contents = filter(&contents, tool);
1435 let ret = tmp.join(p.file_name().unwrap());
1436 t!(fs::write(&ret, &contents));
1440 if target.contains("apple-darwin") {
1441 builder.info("building pkg installer");
1442 let pkg = tmp.join("pkg");
1443 let _ = fs::remove_dir_all(&pkg);
1445 let pkgbuild = |component: &str| {
1446 let mut cmd = Command::new("pkgbuild");
1447 cmd.arg("--identifier")
1448 .arg(format!("org.rust-lang.{}", component))
1450 .arg(pkg.join(component))
1452 .arg(pkg.join(component).with_extension("pkg"));
1453 builder.run(&mut cmd);
1456 let prepare = |name: &str| {
1457 builder.create_dir(&pkg.join(name));
1459 &work.join(&format!("{}-{}", pkgname(builder, name), target.triple)),
1462 builder.install(&etc.join("pkg/postinstall"), &pkg.join(name), 0o755);
1467 prepare("rust-std");
1468 prepare("rust-analysis");
1471 prepare("rust-analyzer");
1472 for tool in &["rust-docs", "rust-demangler"] {
1473 if built_tools.contains(tool) {
1477 // create an 'uninstall' package
1478 builder.install(&etc.join("pkg/postinstall"), &pkg.join("uninstall"), 0o755);
1479 pkgbuild("uninstall");
1481 builder.create_dir(&pkg.join("res"));
1482 builder.create(&pkg.join("res/LICENSE.txt"), &license);
1483 builder.install(&etc.join("gfx/rust-logo.png"), &pkg.join("res"), 0o644);
1484 let mut cmd = Command::new("productbuild");
1485 cmd.arg("--distribution")
1486 .arg(xform(&etc.join("pkg/Distribution.xml")))
1488 .arg(pkg.join("res"))
1489 .arg(distdir(builder).join(format!(
1491 pkgname(builder, "rust"),
1494 .arg("--package-path")
1496 let _time = timeit(builder);
1497 builder.run(&mut cmd);
1500 if target.contains("windows") {
1501 let exe = tmp.join("exe");
1502 let _ = fs::remove_dir_all(&exe);
1504 let prepare = |name: &str| {
1505 builder.create_dir(&exe.join(name));
1506 let dir = if name == "rust-std" || name == "rust-analysis" {
1507 format!("{}-{}", name, target.triple)
1508 } else if name == "rust-analyzer" {
1509 "rust-analyzer-preview".to_string()
1510 } else if name == "clippy" {
1511 "clippy-preview".to_string()
1512 } else if name == "rust-demangler" {
1513 "rust-demangler-preview".to_string()
1514 } else if name == "miri" {
1515 "miri-preview".to_string()
1520 &work.join(&format!("{}-{}", pkgname(builder, name), target.triple)).join(dir),
1523 builder.remove(&exe.join(name).join("manifest.in"));
1527 prepare("rust-analysis");
1528 prepare("rust-docs");
1529 prepare("rust-std");
1532 prepare("rust-analyzer");
1533 for tool in &["rust-demangler"] {
1534 if built_tools.contains(tool) {
1538 if target.ends_with("windows-gnu") {
1539 prepare("rust-mingw");
1542 builder.install(&etc.join("gfx/rust-logo.ico"), &exe, 0o644);
1544 // Generate msi installer
1545 let wix_path = env::var_os("WIX")
1546 .expect("`WIX` environment variable must be set for generating MSI installer(s).");
1547 let wix = PathBuf::from(wix_path);
1548 let heat = wix.join("bin/heat.exe");
1549 let candle = wix.join("bin/candle.exe");
1550 let light = wix.join("bin/light.exe");
1552 let heat_flags = ["-nologo", "-gg", "-sfrag", "-srd", "-sreg"];
1564 .arg("var.RustcDir")
1566 .arg(exe.join("RustcGroup.wxs")),
1581 .arg(exe.join("DocsGroup.wxs"))
1583 .arg(etc.join("msi/squash-components.xsl")),
1596 .arg("var.CargoDir")
1598 .arg(exe.join("CargoGroup.wxs"))
1600 .arg(etc.join("msi/remove-duplicates.xsl")),
1615 .arg(exe.join("StdGroup.wxs")),
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")),
1645 .arg("var.ClippyDir")
1647 .arg(exe.join("ClippyGroup.wxs"))
1649 .arg(etc.join("msi/remove-duplicates.xsl")),
1651 if built_tools.contains("rust-demangler") {
1656 .arg("rust-demangler")
1659 .arg("RustDemanglerGroup")
1661 .arg("RustDemangler")
1663 .arg("var.RustDemanglerDir")
1665 .arg(exe.join("RustDemanglerGroup.wxs"))
1667 .arg(etc.join("msi/remove-duplicates.xsl")),
1683 .arg(exe.join("MiriGroup.wxs"))
1685 .arg(etc.join("msi/remove-duplicates.xsl")),
1691 .arg("rust-analysis")
1694 .arg("AnalysisGroup")
1698 .arg("var.AnalysisDir")
1700 .arg(exe.join("AnalysisGroup.wxs"))
1702 .arg(etc.join("msi/remove-duplicates.xsl")),
1704 if target.ends_with("windows-gnu") {
1718 .arg(exe.join("GccGroup.wxs")),
1722 let candle = |input: &Path| {
1723 let output = exe.join(input.file_stem().unwrap()).with_extension("wixobj");
1724 let arch = if target.contains("x86_64") { "x64" } else { "x86" };
1725 let mut cmd = Command::new(&candle);
1726 cmd.current_dir(&exe)
1728 .arg("-dRustcDir=rustc")
1729 .arg("-dDocsDir=rust-docs")
1730 .arg("-dCargoDir=cargo")
1731 .arg("-dStdDir=rust-std")
1732 .arg("-dAnalysisDir=rust-analysis")
1733 .arg("-dClippyDir=clippy")
1734 .arg("-dMiriDir=miri")
1740 add_env(builder, &mut cmd, target);
1742 if built_tools.contains("rust-demangler") {
1743 cmd.arg("-dRustDemanglerDir=rust-demangler");
1745 if built_tools.contains("rust-analyzer") {
1746 cmd.arg("-dRustAnalyzerDir=rust-analyzer");
1748 if target.ends_with("windows-gnu") {
1749 cmd.arg("-dGccDir=rust-mingw");
1751 builder.run(&mut cmd);
1753 candle(&xform(&etc.join("msi/rust.wxs")));
1754 candle(&etc.join("msi/ui.wxs"));
1755 candle(&etc.join("msi/rustwelcomedlg.wxs"));
1756 candle("RustcGroup.wxs".as_ref());
1757 candle("DocsGroup.wxs".as_ref());
1758 candle("CargoGroup.wxs".as_ref());
1759 candle("StdGroup.wxs".as_ref());
1760 candle("ClippyGroup.wxs".as_ref());
1761 candle("MiriGroup.wxs".as_ref());
1762 if built_tools.contains("rust-demangler") {
1763 candle("RustDemanglerGroup.wxs".as_ref());
1765 if built_tools.contains("rust-analyzer") {
1766 candle("RustAnalyzerGroup.wxs".as_ref());
1768 candle("AnalysisGroup.wxs".as_ref());
1770 if target.ends_with("windows-gnu") {
1771 candle("GccGroup.wxs".as_ref());
1774 builder.create(&exe.join("LICENSE.rtf"), &rtf);
1775 builder.install(&etc.join("gfx/banner.bmp"), &exe, 0o644);
1776 builder.install(&etc.join("gfx/dialogbg.bmp"), &exe, 0o644);
1778 builder.info(&format!("building `msi` installer with {:?}", light));
1779 let filename = format!("{}-{}.msi", pkgname(builder, "rust"), target.triple);
1780 let mut cmd = Command::new(&light);
1783 .arg("WixUIExtension")
1785 .arg("WixUtilExtension")
1787 .arg(exe.join(&filename))
1790 .arg("rustwelcomedlg.wixobj")
1791 .arg("RustcGroup.wixobj")
1792 .arg("DocsGroup.wixobj")
1793 .arg("CargoGroup.wixobj")
1794 .arg("StdGroup.wixobj")
1795 .arg("AnalysisGroup.wixobj")
1796 .arg("ClippyGroup.wixobj")
1797 .arg("MiriGroup.wixobj")
1800 if built_tools.contains("rust-analyzer") {
1801 cmd.arg("RustAnalyzerGroup.wixobj");
1803 if built_tools.contains("rust-demangler") {
1804 cmd.arg("RustDemanglerGroup.wixobj");
1807 if target.ends_with("windows-gnu") {
1808 cmd.arg("GccGroup.wixobj");
1810 // ICE57 wrongly complains about the shortcuts
1811 cmd.arg("-sice:ICE57");
1813 let _time = timeit(builder);
1814 builder.run(&mut cmd);
1816 if !builder.config.dry_run {
1817 t!(fs::rename(exe.join(&filename), distdir(builder).join(&filename)));
1823 fn add_env(builder: &Builder<'_>, cmd: &mut Command, target: TargetSelection) {
1824 let mut parts = builder.version.split('.');
1825 cmd.env("CFG_RELEASE_INFO", builder.rust_version())
1826 .env("CFG_RELEASE_NUM", &builder.version)
1827 .env("CFG_RELEASE", builder.rust_release())
1828 .env("CFG_VER_MAJOR", parts.next().unwrap())
1829 .env("CFG_VER_MINOR", parts.next().unwrap())
1830 .env("CFG_VER_PATCH", parts.next().unwrap())
1831 .env("CFG_VER_BUILD", "0") // just needed to build
1832 .env("CFG_PACKAGE_VERS", builder.rust_package_vers())
1833 .env("CFG_PACKAGE_NAME", pkgname(builder, "rust"))
1834 .env("CFG_BUILD", target.triple)
1835 .env("CFG_CHANNEL", &builder.config.channel);
1837 if target.contains("windows-gnullvm") {
1838 cmd.env("CFG_MINGW", "1").env("CFG_ABI", "LLVM");
1839 } else if target.contains("windows-gnu") {
1840 cmd.env("CFG_MINGW", "1").env("CFG_ABI", "GNU");
1842 cmd.env("CFG_MINGW", "0").env("CFG_ABI", "MSVC");
1846 /// Maybe add LLVM object files to the given destination lib-dir. Allows either static or dynamic linking.
1848 /// Returns whether the files were actually copied.
1849 fn maybe_install_llvm(builder: &Builder<'_>, target: TargetSelection, dst_libdir: &Path) -> bool {
1850 if let Some(config) = builder.config.target_config.get(&target) {
1851 if config.llvm_config.is_some() && !builder.config.llvm_from_ci {
1852 // If the LLVM was externally provided, then we don't currently copy
1853 // artifacts into the sysroot. This is not necessarily the right
1854 // choice (in particular, it will require the LLVM dylib to be in
1855 // the linker's load path at runtime), but the common use case for
1856 // external LLVMs is distribution provided LLVMs, and in that case
1857 // they're usually in the standard search path (e.g., /usr/lib) and
1858 // copying them here is going to cause problems as we may end up
1859 // with the wrong files and isn't what distributions want.
1861 // This behavior may be revisited in the future though.
1863 // If the LLVM is coming from ourselves (just from CI) though, we
1864 // still want to install it, as it otherwise won't be available.
1869 // On macOS, rustc (and LLVM tools) link to an unversioned libLLVM.dylib
1870 // instead of libLLVM-11-rust-....dylib, as on linux. It's not entirely
1871 // clear why this is the case, though. llvm-config will emit the versioned
1872 // paths and we don't want those in the sysroot (as we're expecting
1873 // unversioned paths).
1874 if target.contains("apple-darwin") && builder.llvm_link_shared() {
1875 let src_libdir = builder.llvm_out(target).join("lib");
1876 let llvm_dylib_path = src_libdir.join("libLLVM.dylib");
1877 if llvm_dylib_path.exists() {
1878 builder.install(&llvm_dylib_path, dst_libdir, 0o644);
1880 !builder.config.dry_run
1881 } else if let Ok(llvm_config) = crate::native::prebuilt_llvm_config(builder, target) {
1882 let mut cmd = Command::new(llvm_config);
1883 cmd.arg("--libfiles");
1884 builder.verbose(&format!("running {:?}", cmd));
1885 let files = if builder.config.dry_run { "".into() } else { output(&mut cmd) };
1886 let build_llvm_out = &builder.llvm_out(builder.config.build);
1887 let target_llvm_out = &builder.llvm_out(target);
1888 for file in files.trim_end().split(' ') {
1889 // If we're not using a custom LLVM, make sure we package for the target.
1890 let file = if let Ok(relative_path) = Path::new(file).strip_prefix(build_llvm_out) {
1891 target_llvm_out.join(relative_path)
1895 builder.install(&file, dst_libdir, 0o644);
1897 !builder.config.dry_run
1903 /// Maybe add libLLVM.so to the target lib-dir for linking.
1904 pub fn maybe_install_llvm_target(builder: &Builder<'_>, target: TargetSelection, sysroot: &Path) {
1905 let dst_libdir = sysroot.join("lib/rustlib").join(&*target.triple).join("lib");
1906 // We do not need to copy LLVM files into the sysroot if it is not
1907 // dynamically linked; it is already included into librustc_llvm
1909 if builder.llvm_link_shared() {
1910 maybe_install_llvm(builder, target, &dst_libdir);
1914 /// Maybe add libLLVM.so to the runtime lib-dir for rustc itself.
1915 pub fn maybe_install_llvm_runtime(builder: &Builder<'_>, target: TargetSelection, sysroot: &Path) {
1917 sysroot.join(builder.sysroot_libdir_relative(Compiler { stage: 1, host: target }));
1918 // We do not need to copy LLVM files into the sysroot if it is not
1919 // dynamically linked; it is already included into librustc_llvm
1921 if builder.llvm_link_shared() {
1922 maybe_install_llvm(builder, target, &dst_libdir);
1926 #[derive(Clone, Debug, Eq, Hash, PartialEq)]
1927 pub struct LlvmTools {
1928 pub target: TargetSelection,
1931 impl Step for LlvmTools {
1932 type Output = Option<GeneratedTarball>;
1933 const ONLY_HOSTS: bool = true;
1934 const DEFAULT: bool = true;
1936 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1937 let default = should_build_extended_tool(&run.builder, "llvm-tools");
1938 // FIXME: allow using the names of the tools themselves?
1939 run.alias("llvm-tools").default_condition(default)
1942 fn make_run(run: RunConfig<'_>) {
1943 run.builder.ensure(LlvmTools { target: run.target });
1946 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
1947 let target = self.target;
1949 /* run only if llvm-config isn't used */
1950 if let Some(config) = builder.config.target_config.get(&target) {
1951 if let Some(ref _s) = config.llvm_config {
1952 builder.info(&format!("Skipping LlvmTools ({}): external LLVM", target));
1957 builder.ensure(crate::native::Llvm { target });
1959 let mut tarball = Tarball::new(builder, "llvm-tools", &target.triple);
1960 tarball.set_overlay(OverlayKind::LLVM);
1961 tarball.is_preview(true);
1963 // Prepare the image directory
1964 let src_bindir = builder.llvm_out(target).join("bin");
1965 let dst_bindir = format!("lib/rustlib/{}/bin", target.triple);
1966 for tool in LLVM_TOOLS {
1967 let exe = src_bindir.join(exe(tool, target));
1968 tarball.add_file(&exe, &dst_bindir, 0o755);
1971 // Copy libLLVM.so to the target lib dir as well, so the RPATH like
1972 // `$ORIGIN/../lib` can find it. It may also be used as a dependency
1973 // of `rustc-dev` to support the inherited `-lLLVM` when using the
1974 // compiler libraries.
1975 maybe_install_llvm_target(builder, target, tarball.image_dir());
1977 Some(tarball.generate())
1981 // Tarball intended for internal consumption to ease rustc/std development.
1983 // Should not be considered stable by end users.
1984 #[derive(Clone, Debug, Eq, Hash, PartialEq)]
1985 pub struct RustDev {
1986 pub target: TargetSelection,
1989 impl Step for RustDev {
1990 type Output = Option<GeneratedTarball>;
1991 const DEFAULT: bool = true;
1992 const ONLY_HOSTS: bool = true;
1994 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1995 run.alias("rust-dev")
1998 fn make_run(run: RunConfig<'_>) {
1999 run.builder.ensure(RustDev { target: run.target });
2002 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
2003 let target = self.target;
2005 /* run only if llvm-config isn't used */
2006 if let Some(config) = builder.config.target_config.get(&target) {
2007 if let Some(ref _s) = config.llvm_config {
2008 builder.info(&format!("Skipping RustDev ({}): external LLVM", target));
2013 let mut tarball = Tarball::new(builder, "rust-dev", &target.triple);
2014 tarball.set_overlay(OverlayKind::LLVM);
2016 builder.ensure(crate::native::Llvm { target });
2018 let src_bindir = builder.llvm_out(target).join("bin");
2019 // If updating this list, you likely want to change
2020 // src/bootstrap/download-ci-llvm-stamp as well, otherwise local users
2021 // will not pick up the extra file until LLVM gets bumped.
2035 tarball.add_file(src_bindir.join(exe(bin, target)), "bin", 0o755);
2038 // We don't build LLD on some platforms, so only add it if it exists
2039 let lld_path = builder.lld_out(target).join("bin").join(exe("lld", target));
2040 if lld_path.exists() {
2041 tarball.add_file(lld_path, "bin", 0o755);
2044 tarball.add_file(&builder.llvm_filecheck(target), "bin", 0o755);
2046 // Copy the include directory as well; needed mostly to build
2047 // librustc_llvm properly (e.g., llvm-config.h is in here). But also
2048 // just broadly useful to be able to link against the bundled LLVM.
2049 tarball.add_dir(&builder.llvm_out(target).join("include"), "include");
2051 // Copy libLLVM.so to the target lib dir as well, so the RPATH like
2052 // `$ORIGIN/../lib` can find it. It may also be used as a dependency
2053 // of `rustc-dev` to support the inherited `-lLLVM` when using the
2054 // compiler libraries.
2055 let dst_libdir = tarball.image_dir().join("lib");
2056 maybe_install_llvm(builder, target, &dst_libdir);
2057 let link_type = if builder.llvm_link_shared() { "dynamic" } else { "static" };
2058 t!(std::fs::write(tarball.image_dir().join("link-type.txt"), link_type), dst_libdir);
2060 Some(tarball.generate())
2064 // Tarball intended for internal consumption to ease rustc/std development.
2066 // Should not be considered stable by end users.
2067 #[derive(Clone, Debug, Eq, Hash, PartialEq)]
2068 pub struct Bootstrap {
2069 pub target: TargetSelection,
2072 impl Step for Bootstrap {
2073 type Output = Option<GeneratedTarball>;
2074 const DEFAULT: bool = false;
2075 const ONLY_HOSTS: bool = true;
2077 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2078 run.alias("bootstrap")
2081 fn make_run(run: RunConfig<'_>) {
2082 run.builder.ensure(Bootstrap { target: run.target });
2085 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
2086 let target = self.target;
2088 let tarball = Tarball::new(builder, "bootstrap", &target.triple);
2090 let bootstrap_outdir = &builder.bootstrap_out;
2091 for file in &["bootstrap", "llvm-config-wrapper", "rustc", "rustdoc", "sccache-plus-cl"] {
2092 tarball.add_file(bootstrap_outdir.join(exe(file, target)), "bootstrap/bin", 0o755);
2095 Some(tarball.generate())
2099 /// Tarball containing a prebuilt version of the build-manifest tool, intended to be used by the
2100 /// release process to avoid cloning the monorepo and building stuff.
2102 /// Should not be considered stable by end users.
2103 #[derive(Clone, Debug, Eq, Hash, PartialEq)]
2104 pub struct BuildManifest {
2105 pub target: TargetSelection,
2108 impl Step for BuildManifest {
2109 type Output = GeneratedTarball;
2110 const DEFAULT: bool = false;
2111 const ONLY_HOSTS: bool = true;
2113 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2114 run.alias("build-manifest")
2117 fn make_run(run: RunConfig<'_>) {
2118 run.builder.ensure(BuildManifest { target: run.target });
2121 fn run(self, builder: &Builder<'_>) -> GeneratedTarball {
2122 let build_manifest = builder.tool_exe(Tool::BuildManifest);
2124 let tarball = Tarball::new(builder, "build-manifest", &self.target.triple);
2125 tarball.add_file(&build_manifest, "bin", 0o755);
2130 /// Tarball containing artifacts necessary to reproduce the build of rustc.
2132 /// Currently this is the PGO profile data.
2134 /// Should not be considered stable by end users.
2135 #[derive(Clone, Debug, Eq, Hash, PartialEq)]
2136 pub struct ReproducibleArtifacts {
2137 pub target: TargetSelection,
2140 impl Step for ReproducibleArtifacts {
2141 type Output = Option<GeneratedTarball>;
2142 const DEFAULT: bool = true;
2143 const ONLY_HOSTS: bool = true;
2145 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2146 run.alias("reproducible-artifacts")
2149 fn make_run(run: RunConfig<'_>) {
2150 run.builder.ensure(ReproducibleArtifacts { target: run.target });
2153 fn run(self, builder: &Builder<'_>) -> Self::Output {
2154 let mut added_anything = false;
2155 let tarball = Tarball::new(builder, "reproducible-artifacts", &self.target.triple);
2156 if let Some(path) = builder.config.rust_profile_use.as_ref() {
2157 tarball.add_file(path, ".", 0o644);
2158 added_anything = true;
2160 if let Some(path) = builder.config.llvm_profile_use.as_ref() {
2161 tarball.add_file(path, ".", 0o644);
2162 added_anything = true;
2164 if let Some(path) = builder.config.llvm_bolt_profile_use.as_ref() {
2165 tarball.add_file(path, ".", 0o644);
2166 added_anything = true;
2168 if added_anything { Some(tarball.generate()) } else { None }