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 build_helper::{output, t};
19 use crate::builder::{Builder, RunConfig, ShouldRun, Step};
20 use crate::cache::{Interned, INTERNER};
22 use crate::config::TargetSelection;
23 use crate::tarball::{GeneratedTarball, OverlayKind, Tarball};
24 use crate::tool::{self, Tool};
25 use crate::util::{exe, is_dylib, timeit};
26 use crate::{Compiler, DependencyType, Mode, LLVM_TOOLS};
27 use time::{self, Timespec};
29 pub fn pkgname(builder: &Builder<'_>, component: &str) -> String {
30 format!("{}-{}", component, builder.rust_package_vers())
33 pub(crate) fn distdir(builder: &Builder<'_>) -> PathBuf {
34 builder.out.join("dist")
37 pub fn tmpdir(builder: &Builder<'_>) -> PathBuf {
38 builder.out.join("tmp/dist")
41 fn missing_tool(tool_name: &str, skip: bool) {
43 println!("Unable to build {}, skipping dist", tool_name)
45 panic!("Unable to build {}", tool_name)
49 fn should_build_extended_tool(builder: &Builder<'_>, tool: &str) -> bool {
50 if !builder.config.extended {
53 builder.config.tools.as_ref().map_or(true, |tools| tools.contains(tool))
56 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
58 pub host: TargetSelection,
62 type Output = GeneratedTarball;
63 const DEFAULT: bool = true;
65 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
66 let default = run.builder.config.docs;
67 run.path("src/doc").default_condition(default)
70 fn make_run(run: RunConfig<'_>) {
71 run.builder.ensure(Docs { host: run.target });
74 /// Builds the `rust-docs` installer component.
75 fn run(self, builder: &Builder<'_>) -> GeneratedTarball {
77 builder.default_doc(&[]);
79 let dest = "share/doc/rust/html";
81 let mut tarball = Tarball::new(builder, "rust-docs", &host.triple);
82 tarball.set_product_name("Rust Documentation");
83 tarball.add_bulk_dir(&builder.doc_out(host), dest);
84 tarball.add_file(&builder.src.join("src/doc/robots.txt"), dest, 0o644);
89 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
90 pub struct RustcDocs {
91 pub host: TargetSelection,
94 impl Step for RustcDocs {
95 type Output = Option<GeneratedTarball>;
96 const DEFAULT: bool = true;
98 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
99 run.path("src/librustc")
102 fn make_run(run: RunConfig<'_>) {
103 run.builder.ensure(RustcDocs { host: run.target });
106 /// Builds the `rustc-docs` installer component.
107 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
108 let host = self.host;
109 if !builder.config.compiler_docs {
112 builder.default_doc(&[]);
114 let mut tarball = Tarball::new(builder, "rustc-docs", &host.triple);
115 tarball.set_product_name("Rustc Documentation");
116 tarball.add_bulk_dir(&builder.compiler_doc_out(host), "share/doc/rust/html/rustc");
117 Some(tarball.generate())
121 fn find_files(files: &[&str], path: &[PathBuf]) -> Vec<PathBuf> {
122 let mut found = Vec::with_capacity(files.len());
125 let file_path = path.iter().map(|dir| dir.join(file)).find(|p| p.exists());
127 if let Some(file_path) = file_path {
128 found.push(file_path);
130 panic!("Could not find '{}' in {:?}", file, path);
140 target: TargetSelection,
141 builder: &Builder<'_>,
143 //Ask gcc where it keeps its stuff
144 let mut cmd = Command::new(builder.cc(target));
145 cmd.arg("-print-search-dirs");
146 let gcc_out = output(&mut cmd);
148 let mut bin_path: Vec<_> = env::split_paths(&env::var_os("PATH").unwrap_or_default()).collect();
149 let mut lib_path = Vec::new();
151 for line in gcc_out.lines() {
152 let idx = line.find(':').unwrap();
153 let key = &line[..idx];
154 let trim_chars: &[_] = &[' ', '='];
155 let value = env::split_paths(line[(idx + 1)..].trim_start_matches(trim_chars));
157 if key == "programs" {
158 bin_path.extend(value);
159 } else if key == "libraries" {
160 lib_path.extend(value);
164 let compiler = if target == "i686-pc-windows-gnu" {
165 "i686-w64-mingw32-gcc.exe"
166 } else if target == "x86_64-pc-windows-gnu" {
167 "x86_64-w64-mingw32-gcc.exe"
171 let target_tools = [compiler, "ld.exe", "dlltool.exe", "libwinpthread-1.dll"];
172 let mut rustc_dlls = vec!["libwinpthread-1.dll"];
173 if target.starts_with("i686-") {
174 rustc_dlls.push("libgcc_s_dw2-1.dll");
176 rustc_dlls.push("libgcc_s_seh-1.dll");
191 //Windows import libs
214 "libsynchronization.a",
225 //Find mingw artifacts we want to bundle
226 let target_tools = find_files(&target_tools, &bin_path);
227 let rustc_dlls = find_files(&rustc_dlls, &bin_path);
228 let target_libs = find_files(&target_libs, &lib_path);
230 // Copy runtime dlls next to rustc.exe
231 let dist_bin_dir = rust_root.join("bin/");
232 fs::create_dir_all(&dist_bin_dir).expect("creating dist_bin_dir failed");
233 for src in rustc_dlls {
234 builder.copy_to_folder(&src, &dist_bin_dir);
237 //Copy platform tools to platform-specific bin directory
238 let target_bin_dir = plat_root
243 .join("self-contained");
244 fs::create_dir_all(&target_bin_dir).expect("creating target_bin_dir failed");
245 for src in target_tools {
246 builder.copy_to_folder(&src, &target_bin_dir);
249 // Warn windows-gnu users that the bundled GCC cannot compile C files
251 &target_bin_dir.join("GCC-WARNING.txt"),
252 "gcc.exe contained in this folder cannot be used for compiling C files - it is only \
253 used as a linker. In order to be able to compile projects containing C code use \
254 the GCC provided by MinGW or Cygwin.",
257 //Copy platform libs to platform-specific lib directory
258 let target_lib_dir = plat_root
263 .join("self-contained");
264 fs::create_dir_all(&target_lib_dir).expect("creating target_lib_dir failed");
265 for src in target_libs {
266 builder.copy_to_folder(&src, &target_lib_dir);
270 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
272 pub host: TargetSelection,
275 impl Step for Mingw {
276 type Output = Option<GeneratedTarball>;
277 const DEFAULT: bool = true;
279 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
283 fn make_run(run: RunConfig<'_>) {
284 run.builder.ensure(Mingw { host: run.target });
287 /// Builds the `rust-mingw` installer component.
289 /// This contains all the bits and pieces to run the MinGW Windows targets
290 /// without any extra installed software (e.g., we bundle gcc, libraries, etc).
291 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
292 let host = self.host;
293 if !host.contains("pc-windows-gnu") {
297 let mut tarball = Tarball::new(builder, "rust-mingw", &host.triple);
298 tarball.set_product_name("Rust MinGW");
300 // The first argument is a "temporary directory" which is just
301 // thrown away (this contains the runtime DLLs included in the rustc package
302 // above) and the second argument is where to place all the MinGW components
303 // (which is what we want).
304 make_win_dist(&tmpdir(builder), tarball.image_dir(), host, &builder);
306 Some(tarball.generate())
310 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
312 pub compiler: Compiler,
315 impl Step for Rustc {
316 type Output = GeneratedTarball;
317 const DEFAULT: bool = true;
318 const ONLY_HOSTS: bool = true;
320 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
321 run.path("src/librustc")
324 fn make_run(run: RunConfig<'_>) {
326 .ensure(Rustc { compiler: run.builder.compiler(run.builder.top_stage, run.target) });
329 /// Creates the `rustc` installer component.
330 fn run(self, builder: &Builder<'_>) -> GeneratedTarball {
331 let compiler = self.compiler;
332 let host = self.compiler.host;
334 let tarball = Tarball::new(builder, "rustc", &host.triple);
336 // Prepare the rustc "image", what will actually end up getting installed
337 prepare_image(builder, compiler, tarball.image_dir());
339 // On MinGW we've got a few runtime DLL dependencies that we need to
340 // include. The first argument to this script is where to put these DLLs
341 // (the image we're creating), and the second argument is a junk directory
342 // to ignore all other MinGW stuff the script creates.
344 // On 32-bit MinGW we're always including a DLL which needs some extra
345 // licenses to distribute. On 64-bit MinGW we don't actually distribute
346 // anything requiring us to distribute a license, but it's likely the
347 // install will *also* include the rust-mingw package, which also needs
348 // licenses, so to be safe we just include it here in all MinGW packages.
349 if host.contains("pc-windows-gnu") {
350 make_win_dist(tarball.image_dir(), &tmpdir(builder), host, builder);
351 tarball.add_dir(builder.src.join("src/etc/third-party"), "share/doc");
354 return tarball.generate();
356 fn prepare_image(builder: &Builder<'_>, compiler: Compiler, image: &Path) {
357 let host = compiler.host;
358 let src = builder.sysroot(compiler);
360 // Copy rustc/rustdoc binaries
361 t!(fs::create_dir_all(image.join("bin")));
362 builder.cp_r(&src.join("bin"), &image.join("bin"));
364 builder.install(&builder.rustdoc(compiler), &image.join("bin"), 0o755);
366 let libdir_relative = builder.libdir_relative(compiler);
368 // Copy runtime DLLs needed by the compiler
369 if libdir_relative.to_str() != Some("bin") {
370 let libdir = builder.rustc_libdir(compiler);
371 for entry in builder.read_dir(&libdir) {
372 let name = entry.file_name();
373 if let Some(s) = name.to_str() {
375 // Don't use custom libdir here because ^lib/ will be resolved again
377 builder.install(&entry.path(), &image.join("lib"), 0o644);
383 // Copy over the codegen backends
384 let backends_src = builder.sysroot_codegen_backends(compiler);
385 let backends_rel = backends_src
388 .strip_prefix(builder.sysroot_libdir_relative(compiler))
390 // Don't use custom libdir here because ^lib/ will be resolved again with installer
391 let backends_dst = image.join("lib").join(&backends_rel);
393 t!(fs::create_dir_all(&backends_dst));
394 builder.cp_r(&backends_src, &backends_dst);
396 // Copy libLLVM.so to the lib dir as well, if needed. While not
397 // technically needed by rustc itself it's needed by lots of other
398 // components like the llvm tools and LLD. LLD is included below and
399 // tools/LLDB come later, so let's just throw it in the rustc
400 // component for now.
401 maybe_install_llvm_runtime(builder, host, image);
403 let src_dir = builder.sysroot_libdir(compiler, host).parent().unwrap().join("bin");
404 let dst_dir = image.join("lib/rustlib").join(&*host.triple).join("bin");
405 t!(fs::create_dir_all(&dst_dir));
407 // Copy over lld if it's there
408 if builder.config.lld_enabled {
409 let rust_lld = exe("rust-lld", compiler.host);
410 builder.copy(&src_dir.join(&rust_lld), &dst_dir.join(&rust_lld));
411 // for `-Z gcc-ld=lld`
412 let gcc_lld_dir = dst_dir.join("gcc-ld");
413 t!(fs::create_dir(&gcc_lld_dir));
414 builder.copy(&src_dir.join(&rust_lld), &gcc_lld_dir.join(exe("ld", compiler.host)));
417 // Copy over llvm-dwp if it's there
418 let exe = exe("rust-llvm-dwp", compiler.host);
419 builder.copy(&src_dir.join(&exe), &dst_dir.join(&exe));
422 t!(fs::create_dir_all(image.join("share/man/man1")));
423 let man_src = builder.src.join("src/doc/man");
424 let man_dst = image.join("share/man/man1");
426 // Reproducible builds: If SOURCE_DATE_EPOCH is set, use that as the time.
427 let time = env::var("SOURCE_DATE_EPOCH")
429 let epoch = timestamp
431 .map_err(|err| format!("could not parse SOURCE_DATE_EPOCH: {}", err))
434 time::at(Timespec::new(epoch, 0))
436 .unwrap_or_else(|_| time::now());
438 let month_year = t!(time::strftime("%B %Y", &time));
439 // don't use our `bootstrap::util::{copy, cp_r}`, because those try
440 // to hardlink, and we don't want to edit the source templates
441 for file_entry in builder.read_dir(&man_src) {
442 let page_src = file_entry.path();
443 let page_dst = man_dst.join(file_entry.file_name());
444 t!(fs::copy(&page_src, &page_dst));
445 // template in month/year and version number
446 builder.replace_in_file(
449 ("<INSERT DATE HERE>", &month_year),
450 ("<INSERT VERSION HERE>", &builder.version),
457 .ensure(DebuggerScripts { sysroot: INTERNER.intern_path(image.to_owned()), host });
460 let cp = |file: &str| {
461 builder.install(&builder.src.join(file), &image.join("share/doc/rust"), 0o644);
464 cp("LICENSE-APACHE");
471 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
472 pub struct DebuggerScripts {
473 pub sysroot: Interned<PathBuf>,
474 pub host: TargetSelection,
477 impl Step for DebuggerScripts {
480 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
481 run.path("src/lldb_batchmode.py")
484 fn make_run(run: RunConfig<'_>) {
485 run.builder.ensure(DebuggerScripts {
488 .sysroot(run.builder.compiler(run.builder.top_stage, run.build_triple())),
493 /// Copies debugger scripts for `target` into the `sysroot` specified.
494 fn run(self, builder: &Builder<'_>) {
495 let host = self.host;
496 let sysroot = self.sysroot;
497 let dst = sysroot.join("lib/rustlib/etc");
498 t!(fs::create_dir_all(&dst));
499 let cp_debugger_script = |file: &str| {
500 builder.install(&builder.src.join("src/etc/").join(file), &dst, 0o644);
502 if host.contains("windows-msvc") {
503 // windbg debugger scripts
505 &builder.src.join("src/etc/rust-windbg.cmd"),
506 &sysroot.join("bin"),
510 cp_debugger_script("natvis/intrinsic.natvis");
511 cp_debugger_script("natvis/liballoc.natvis");
512 cp_debugger_script("natvis/libcore.natvis");
513 cp_debugger_script("natvis/libstd.natvis");
515 cp_debugger_script("rust_types.py");
517 // gdb debugger scripts
518 builder.install(&builder.src.join("src/etc/rust-gdb"), &sysroot.join("bin"), 0o755);
519 builder.install(&builder.src.join("src/etc/rust-gdbgui"), &sysroot.join("bin"), 0o755);
521 cp_debugger_script("gdb_load_rust_pretty_printers.py");
522 cp_debugger_script("gdb_lookup.py");
523 cp_debugger_script("gdb_providers.py");
525 // lldb debugger scripts
526 builder.install(&builder.src.join("src/etc/rust-lldb"), &sysroot.join("bin"), 0o755);
528 cp_debugger_script("lldb_lookup.py");
529 cp_debugger_script("lldb_providers.py");
530 cp_debugger_script("lldb_commands")
535 fn skip_host_target_lib(builder: &Builder<'_>, compiler: Compiler) -> bool {
536 // The only true set of target libraries came from the build triple, so
537 // let's reduce redundant work by only producing archives from that host.
538 if compiler.host != builder.config.build {
539 builder.info("\tskipping, not a build host");
546 /// Copy stamped files into an image's `target/lib` directory.
547 fn copy_target_libs(builder: &Builder<'_>, target: TargetSelection, image: &Path, stamp: &Path) {
548 let dst = image.join("lib/rustlib").join(target.triple).join("lib");
549 let self_contained_dst = dst.join("self-contained");
550 t!(fs::create_dir_all(&dst));
551 t!(fs::create_dir_all(&self_contained_dst));
552 for (path, dependency_type) in builder.read_stamp_file(stamp) {
553 if dependency_type == DependencyType::TargetSelfContained {
554 builder.copy(&path, &self_contained_dst.join(path.file_name().unwrap()));
555 } else if dependency_type == DependencyType::Target || builder.config.build == target {
556 builder.copy(&path, &dst.join(path.file_name().unwrap()));
561 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
563 pub compiler: Compiler,
564 pub target: TargetSelection,
568 type Output = Option<GeneratedTarball>;
569 const DEFAULT: bool = true;
571 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
572 run.path("library/std")
575 fn make_run(run: RunConfig<'_>) {
576 run.builder.ensure(Std {
577 compiler: run.builder.compiler_for(
578 run.builder.top_stage,
579 run.builder.config.build,
586 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
587 let compiler = self.compiler;
588 let target = self.target;
590 if skip_host_target_lib(builder, compiler) {
594 builder.ensure(compile::Std { compiler, target });
596 let mut tarball = Tarball::new(builder, "rust-std", &target.triple);
597 tarball.include_target_in_component_name(true);
599 let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target);
600 let stamp = compile::libstd_stamp(builder, compiler_to_use, target);
601 copy_target_libs(builder, target, &tarball.image_dir(), &stamp);
603 Some(tarball.generate())
607 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
608 pub struct RustcDev {
609 pub compiler: Compiler,
610 pub target: TargetSelection,
613 impl Step for RustcDev {
614 type Output = Option<GeneratedTarball>;
615 const DEFAULT: bool = true;
616 const ONLY_HOSTS: bool = true;
618 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
619 run.path("rustc-dev")
622 fn make_run(run: RunConfig<'_>) {
623 run.builder.ensure(RustcDev {
624 compiler: run.builder.compiler_for(
625 run.builder.top_stage,
626 run.builder.config.build,
633 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
634 let compiler = self.compiler;
635 let target = self.target;
636 if skip_host_target_lib(builder, compiler) {
640 builder.ensure(compile::Rustc { compiler, target });
642 let tarball = Tarball::new(builder, "rustc-dev", &target.triple);
644 let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target);
645 let stamp = compile::librustc_stamp(builder, compiler_to_use, target);
646 copy_target_libs(builder, target, tarball.image_dir(), &stamp);
648 let src_files = &["Cargo.lock"];
649 // This is the reduced set of paths which will become the rustc-dev component
650 // (essentially the compiler crates and all of their path dependencies).
656 &tarball.image_dir().join("lib/rustlib/rustc-src/rust"),
658 // This particular crate is used as a build dependency of the above.
662 &["src/build_helper"],
664 &tarball.image_dir().join("lib/rustlib/rustc-src/rust"),
666 for file in src_files {
667 tarball.add_file(builder.src.join(file), "lib/rustlib/rustc-src/rust", 0o644);
670 Some(tarball.generate())
674 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
675 pub struct Analysis {
676 pub compiler: Compiler,
677 pub target: TargetSelection,
680 impl Step for Analysis {
681 type Output = Option<GeneratedTarball>;
683 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
684 let default = should_build_extended_tool(&run.builder, "analysis");
685 run.path("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 { 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",
757 if spath.contains("llvm-project")
758 && !spath.ends_with("llvm-project")
759 && !LLVM_PROJECTS.iter().any(|path| spath.contains(path))
764 const LLVM_TEST: &[&str] = &["llvm-project/llvm/test", "llvm-project\\llvm\\test"];
765 if LLVM_TEST.iter().any(|path| spath.contains(path))
766 && (spath.ends_with(".ll") || spath.ends_with(".td") || spath.ends_with(".s"))
771 let full_path = Path::new(dir).join(path);
772 if exclude_dirs.iter().any(|excl| full_path == Path::new(excl)) {
799 !path.iter().map(|s| s.to_str().unwrap()).any(|s| excludes.contains(&s))
802 // Copy the directories using our filter
803 for item in src_dirs {
804 let dst = &dst_dir.join(item);
805 t!(fs::create_dir_all(dst));
806 builder.cp_filtered(&base.join(item), dst, &|path| filter_fn(exclude_dirs, item, path));
810 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
814 /// The output path of the src installer tarball
815 type Output = GeneratedTarball;
816 const DEFAULT: bool = true;
817 const ONLY_HOSTS: bool = true;
819 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
823 fn make_run(run: RunConfig<'_>) {
824 run.builder.ensure(Src);
827 /// Creates the `rust-src` installer component
828 fn run(self, builder: &Builder<'_>) -> GeneratedTarball {
829 let tarball = Tarball::new_targetless(builder, "rust-src");
831 // A lot of tools expect the rust-src component to be entirely in this directory, so if you
832 // change that (e.g. by adding another directory `lib/rustlib/src/foo` or
833 // `lib/rustlib/src/rust/foo`), you will need to go around hunting for implicit assumptions
836 // NOTE: if you update the paths here, you also should update the "virtual" path
837 // translation code in `imported_source_files` in `src/librustc_metadata/rmeta/decoder.rs`
838 let dst_src = tarball.image_dir().join("lib/rustlib/src/rust");
840 let src_files = ["Cargo.lock"];
841 // This is the reduced set of paths which will become the rust-src component
842 // (essentially libstd and all of its path dependencies).
846 &["library", "src/llvm-project/libunwind"],
848 // not needed and contains symlinks which rustup currently
849 // chokes on when unpacking.
850 "library/backtrace/crates",
854 for file in src_files.iter() {
855 builder.copy(&builder.src.join(file), &dst_src.join(file));
862 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
863 pub struct PlainSourceTarball;
865 impl Step for PlainSourceTarball {
866 /// Produces the location of the tarball generated
867 type Output = GeneratedTarball;
868 const DEFAULT: bool = true;
869 const ONLY_HOSTS: bool = true;
871 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
872 let builder = run.builder;
873 run.path("src").default_condition(builder.config.rust_dist_src)
876 fn make_run(run: RunConfig<'_>) {
877 run.builder.ensure(PlainSourceTarball);
880 /// Creates the plain source tarball
881 fn run(self, builder: &Builder<'_>) -> GeneratedTarball {
882 let tarball = Tarball::new(builder, "rustc", "src");
883 let plain_dst_src = tarball.image_dir();
885 // This is the set of root paths which will become part of the source package
895 "config.toml.example",
899 let src_dirs = ["src", "compiler", "library"];
901 copy_src_dirs(builder, &builder.src, &src_dirs, &[], &plain_dst_src);
903 // Copy the files normally
904 for item in &src_files {
905 builder.copy(&builder.src.join(item), &plain_dst_src.join(item));
908 // Create the version file
909 builder.create(&plain_dst_src.join("version"), &builder.rust_version());
910 if let Some(sha) = builder.rust_sha() {
911 builder.create(&plain_dst_src.join("git-commit-hash"), &sha);
914 // If we're building from git sources, we need to vendor a complete distribution.
915 if builder.rust_info.is_git() {
916 // Vendor all Cargo dependencies
917 let mut cmd = Command::new(&builder.initial_cargo);
920 .arg(builder.src.join("./src/tools/rust-analyzer/Cargo.toml"))
921 .arg(builder.src.join("./compiler/rustc_codegen_cranelift/Cargo.toml"))
922 .current_dir(&plain_dst_src);
923 builder.run(&mut cmd);
930 // We have to run a few shell scripts, which choke quite a bit on both `\`
931 // characters and on `C:\` paths, so normalize both of them away.
932 pub fn sanitize_sh(path: &Path) -> String {
933 let path = path.to_str().unwrap().replace("\\", "/");
934 return change_drive(unc_to_lfs(&path)).unwrap_or(path);
936 fn unc_to_lfs(s: &str) -> &str {
937 s.strip_prefix("//?/").unwrap_or(s)
940 fn change_drive(s: &str) -> Option<String> {
941 let mut ch = s.chars();
942 let drive = ch.next().unwrap_or('C');
943 if ch.next() != Some(':') {
946 if ch.next() != Some('/') {
949 Some(format!("/{}/{}", drive, &s[drive.len_utf8() + 2..]))
953 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
955 pub compiler: Compiler,
956 pub target: TargetSelection,
959 impl Step for Cargo {
960 type Output = Option<GeneratedTarball>;
961 const ONLY_HOSTS: bool = true;
963 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
964 let default = should_build_extended_tool(&run.builder, "cargo");
965 run.path("cargo").default_condition(default)
968 fn make_run(run: RunConfig<'_>) {
969 run.builder.ensure(Cargo {
970 compiler: run.builder.compiler_for(
971 run.builder.top_stage,
972 run.builder.config.build,
979 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
980 let compiler = self.compiler;
981 let target = self.target;
983 let cargo = builder.ensure(tool::Cargo { compiler, target });
984 let src = builder.src.join("src/tools/cargo");
985 let etc = src.join("src/etc");
987 // Prepare the image directory
988 let mut tarball = Tarball::new(builder, "cargo", &target.triple);
989 tarball.set_overlay(OverlayKind::Cargo);
991 tarball.add_file(&cargo, "bin", 0o755);
992 tarball.add_file(etc.join("_cargo"), "share/zsh/site-functions", 0o644);
993 tarball.add_renamed_file(etc.join("cargo.bashcomp.sh"), "etc/bash_completion.d", "cargo");
994 tarball.add_dir(etc.join("man"), "share/man/man1");
995 tarball.add_legal_and_readme_to("share/doc/cargo");
997 for dirent in fs::read_dir(cargo.parent().unwrap()).expect("read_dir") {
998 let dirent = dirent.expect("read dir entry");
999 if dirent.file_name().to_str().expect("utf8").starts_with("cargo-credential-") {
1000 tarball.add_file(&dirent.path(), "libexec", 0o755);
1004 Some(tarball.generate())
1008 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
1010 pub compiler: Compiler,
1011 pub target: TargetSelection,
1015 type Output = Option<GeneratedTarball>;
1016 const ONLY_HOSTS: bool = true;
1018 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1019 let default = should_build_extended_tool(&run.builder, "rls");
1020 run.path("rls").default_condition(default)
1023 fn make_run(run: RunConfig<'_>) {
1024 run.builder.ensure(Rls {
1025 compiler: run.builder.compiler_for(
1026 run.builder.top_stage,
1027 run.builder.config.build,
1034 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
1035 let compiler = self.compiler;
1036 let target = self.target;
1039 .ensure(tool::Rls { compiler, target, extra_features: Vec::new() })
1041 missing_tool("RLS", builder.build.config.missing_tools);
1045 let mut tarball = Tarball::new(builder, "rls", &target.triple);
1046 tarball.set_overlay(OverlayKind::RLS);
1047 tarball.is_preview(true);
1048 tarball.add_file(rls, "bin", 0o755);
1049 tarball.add_legal_and_readme_to("share/doc/rls");
1050 Some(tarball.generate())
1054 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
1055 pub struct RustAnalyzer {
1056 pub compiler: Compiler,
1057 pub target: TargetSelection,
1060 impl Step for RustAnalyzer {
1061 type Output = Option<GeneratedTarball>;
1062 const ONLY_HOSTS: bool = true;
1064 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1065 let default = should_build_extended_tool(&run.builder, "rust-analyzer");
1066 run.path("rust-analyzer").default_condition(default)
1069 fn make_run(run: RunConfig<'_>) {
1070 run.builder.ensure(RustAnalyzer {
1071 compiler: run.builder.compiler_for(
1072 run.builder.top_stage,
1073 run.builder.config.build,
1080 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
1081 // This prevents rust-analyzer from being built for "dist" or "install"
1082 // on the stable/beta channels. It is a nightly-only tool and should
1084 if !builder.build.unstable_features() {
1087 let compiler = self.compiler;
1088 let target = self.target;
1090 if target.contains("riscv64") {
1091 // riscv64 currently has an LLVM bug that makes rust-analyzer unable
1092 // to build. See #74813 for details.
1096 let rust_analyzer = builder
1097 .ensure(tool::RustAnalyzer { compiler, target, extra_features: Vec::new() })
1098 .expect("rust-analyzer always builds");
1100 let mut tarball = Tarball::new(builder, "rust-analyzer", &target.triple);
1101 tarball.set_overlay(OverlayKind::RustAnalyzer);
1102 tarball.is_preview(true);
1103 tarball.add_file(rust_analyzer, "bin", 0o755);
1104 tarball.add_legal_and_readme_to("share/doc/rust-analyzer");
1105 Some(tarball.generate())
1109 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
1111 pub compiler: Compiler,
1112 pub target: TargetSelection,
1115 impl Step for Clippy {
1116 type Output = Option<GeneratedTarball>;
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.path("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 ONLY_HOSTS: bool = true;
1169 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1170 let default = should_build_extended_tool(&run.builder, "miri");
1171 run.path("miri").default_condition(default)
1174 fn make_run(run: RunConfig<'_>) {
1175 run.builder.ensure(Miri {
1176 compiler: run.builder.compiler_for(
1177 run.builder.top_stage,
1178 run.builder.config.build,
1185 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
1186 // This prevents miri from being built for "dist" or "install"
1187 // on the stable/beta channels. It is a nightly-only tool and should
1189 if !builder.build.unstable_features() {
1192 let compiler = self.compiler;
1193 let target = self.target;
1196 .ensure(tool::Miri { compiler, target, extra_features: Vec::new() })
1198 missing_tool("miri", builder.build.config.missing_tools);
1201 let cargomiri = builder
1202 .ensure(tool::CargoMiri { compiler, target, extra_features: Vec::new() })
1204 missing_tool("cargo miri", builder.build.config.missing_tools);
1208 let mut tarball = Tarball::new(builder, "miri", &target.triple);
1209 tarball.set_overlay(OverlayKind::Miri);
1210 tarball.is_preview(true);
1211 tarball.add_file(miri, "bin", 0o755);
1212 tarball.add_file(cargomiri, "bin", 0o755);
1213 tarball.add_legal_and_readme_to("share/doc/miri");
1214 Some(tarball.generate())
1218 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
1219 pub struct Rustfmt {
1220 pub compiler: Compiler,
1221 pub target: TargetSelection,
1224 impl Step for Rustfmt {
1225 type Output = Option<GeneratedTarball>;
1226 const ONLY_HOSTS: bool = true;
1228 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1229 let default = should_build_extended_tool(&run.builder, "rustfmt");
1230 run.path("rustfmt").default_condition(default)
1233 fn make_run(run: RunConfig<'_>) {
1234 run.builder.ensure(Rustfmt {
1235 compiler: run.builder.compiler_for(
1236 run.builder.top_stage,
1237 run.builder.config.build,
1244 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
1245 let compiler = self.compiler;
1246 let target = self.target;
1248 let rustfmt = builder
1249 .ensure(tool::Rustfmt { compiler, target, extra_features: Vec::new() })
1251 missing_tool("Rustfmt", builder.build.config.missing_tools);
1254 let cargofmt = builder
1255 .ensure(tool::Cargofmt { compiler, target, extra_features: Vec::new() })
1257 missing_tool("Cargofmt", builder.build.config.missing_tools);
1261 let mut tarball = Tarball::new(builder, "rustfmt", &target.triple);
1262 tarball.set_overlay(OverlayKind::Rustfmt);
1263 tarball.is_preview(true);
1264 tarball.add_file(rustfmt, "bin", 0o755);
1265 tarball.add_file(cargofmt, "bin", 0o755);
1266 tarball.add_legal_and_readme_to("share/doc/rustfmt");
1267 Some(tarball.generate())
1271 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
1272 pub struct RustDemangler {
1273 pub compiler: Compiler,
1274 pub target: TargetSelection,
1277 impl Step for RustDemangler {
1278 type Output = Option<GeneratedTarball>;
1279 const ONLY_HOSTS: bool = true;
1281 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1282 // While other tools use `should_build_extended_tool` to decide whether to be run by
1283 // default or not, `rust-demangler` must be build when *either* it's enabled as a tool like
1284 // the other ones or if `profiler = true`. Because we don't know the target at this stage
1285 // we run the step by default when only `extended = true`, and decide whether to actually
1286 // run it or not later.
1287 let default = run.builder.config.extended;
1288 run.path("rust-demangler").default_condition(default)
1291 fn make_run(run: RunConfig<'_>) {
1292 run.builder.ensure(RustDemangler {
1293 compiler: run.builder.compiler_for(
1294 run.builder.top_stage,
1295 run.builder.config.build,
1302 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
1303 let compiler = self.compiler;
1304 let target = self.target;
1306 // Only build this extended tool if explicitly included in `tools`, or if `profiler = true`
1307 let condition = should_build_extended_tool(builder, "rust-demangler")
1308 || builder.config.profiler_enabled(target);
1309 if builder.config.extended && !condition {
1313 let rust_demangler = builder
1314 .ensure(tool::RustDemangler { compiler, target, extra_features: Vec::new() })
1315 .expect("rust-demangler expected to build - in-tree tool");
1317 // Prepare the image directory
1318 let mut tarball = Tarball::new(builder, "rust-demangler", &target.triple);
1319 tarball.set_overlay(OverlayKind::RustDemangler);
1320 tarball.is_preview(true);
1321 tarball.add_file(&rust_demangler, "bin", 0o755);
1322 tarball.add_legal_and_readme_to("share/doc/rust-demangler");
1323 Some(tarball.generate())
1327 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
1328 pub struct Extended {
1330 host: TargetSelection,
1331 target: TargetSelection,
1334 impl Step for Extended {
1336 const DEFAULT: bool = true;
1337 const ONLY_HOSTS: bool = true;
1339 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1340 let builder = run.builder;
1341 run.path("extended").default_condition(builder.config.extended)
1344 fn make_run(run: RunConfig<'_>) {
1345 run.builder.ensure(Extended {
1346 stage: run.builder.top_stage,
1347 host: run.builder.config.build,
1352 /// Creates a combined installer for the specified target in the provided stage.
1353 fn run(self, builder: &Builder<'_>) {
1354 let target = self.target;
1355 let stage = self.stage;
1356 let compiler = builder.compiler_for(self.stage, self.host, self.target);
1358 builder.info(&format!("Dist extended stage{} ({})", compiler.stage, target));
1360 let mut tarballs = Vec::new();
1361 let mut built_tools = HashSet::new();
1362 macro_rules! add_tool {
1363 ($name:expr => $step:expr) => {
1364 if should_build_extended_tool(builder, $name) {
1365 if let Some(tarball) = builder.ensure($step) {
1366 tarballs.push(tarball);
1367 built_tools.insert($name);
1373 // When rust-std package split from rustc, we needed to ensure that during
1374 // upgrades rustc was upgraded before rust-std. To avoid rustc clobbering
1375 // the std files during uninstall. To do this ensure that rustc comes
1376 // before rust-std in the list below.
1377 tarballs.push(builder.ensure(Rustc { compiler: builder.compiler(stage, target) }));
1378 tarballs.push(builder.ensure(Std { compiler, target }).expect("missing std"));
1380 if builder.config.docs {
1381 tarballs.push(builder.ensure(Docs { host: target }));
1384 if target.contains("windows-gnu") {
1385 tarballs.push(builder.ensure(Mingw { host: target }).expect("missing mingw"));
1388 if builder.config.profiler_enabled(target)
1389 || should_build_extended_tool(builder, "rust-demangler")
1391 if let Some(tarball) = builder.ensure(RustDemangler { compiler, target }) {
1392 tarballs.push(tarball);
1393 built_tools.insert("rust-demangler");
1397 add_tool!("cargo" => Cargo { compiler, target });
1398 add_tool!("rustfmt" => Rustfmt { compiler, target });
1399 add_tool!("rls" => Rls { compiler, target });
1400 add_tool!("rust-analyzer" => RustAnalyzer { compiler, target });
1401 add_tool!("llvm-tools" => LlvmTools { target });
1402 add_tool!("clippy" => Clippy { compiler, target });
1403 add_tool!("miri" => Miri { compiler, target });
1404 add_tool!("analysis" => Analysis { compiler, target });
1406 let etc = builder.src.join("src/etc/installer");
1408 // Avoid producing tarballs during a dry run.
1409 if builder.config.dry_run {
1413 let tarball = Tarball::new(builder, "rust", &target.triple);
1414 let generated = tarball.combine(&tarballs);
1416 let tmp = tmpdir(builder).join("combined-tarball");
1417 let work = generated.work_dir();
1419 let mut license = String::new();
1420 license += &builder.read(&builder.src.join("COPYRIGHT"));
1421 license += &builder.read(&builder.src.join("LICENSE-APACHE"));
1422 license += &builder.read(&builder.src.join("LICENSE-MIT"));
1426 let rtf = r"{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 Arial;}}\nowwrap\fs18";
1427 let mut rtf = rtf.to_string();
1429 for line in license.lines() {
1431 rtf.push_str("\\line ");
1435 fn filter(contents: &str, marker: &str) -> String {
1436 let start = format!("tool-{}-start", marker);
1437 let end = format!("tool-{}-end", marker);
1438 let mut lines = Vec::new();
1439 let mut omitted = false;
1440 for line in contents.lines() {
1441 if line.contains(&start) {
1443 } else if line.contains(&end) {
1445 } else if !omitted {
1453 let xform = |p: &Path| {
1454 let mut contents = t!(fs::read_to_string(p));
1455 for tool in &["rust-demangler", "rls", "rust-analyzer", "miri", "rustfmt"] {
1456 if !built_tools.contains(tool) {
1457 contents = filter(&contents, tool);
1460 let ret = tmp.join(p.file_name().unwrap());
1461 t!(fs::write(&ret, &contents));
1465 if target.contains("apple-darwin") {
1466 builder.info("building pkg installer");
1467 let pkg = tmp.join("pkg");
1468 let _ = fs::remove_dir_all(&pkg);
1470 let pkgbuild = |component: &str| {
1471 let mut cmd = Command::new("pkgbuild");
1472 cmd.arg("--identifier")
1473 .arg(format!("org.rust-lang.{}", component))
1475 .arg(pkg.join(component))
1477 .arg(pkg.join(component).with_extension("pkg"));
1478 builder.run(&mut cmd);
1481 let prepare = |name: &str| {
1482 builder.create_dir(&pkg.join(name));
1484 &work.join(&format!("{}-{}", pkgname(builder, name), target.triple)),
1487 builder.install(&etc.join("pkg/postinstall"), &pkg.join(name), 0o755);
1492 prepare("rust-docs");
1493 prepare("rust-std");
1494 prepare("rust-analysis");
1496 for tool in &["rust-demangler", "rls", "rust-analyzer", "miri"] {
1497 if built_tools.contains(tool) {
1501 // create an 'uninstall' package
1502 builder.install(&etc.join("pkg/postinstall"), &pkg.join("uninstall"), 0o755);
1503 pkgbuild("uninstall");
1505 builder.create_dir(&pkg.join("res"));
1506 builder.create(&pkg.join("res/LICENSE.txt"), &license);
1507 builder.install(&etc.join("gfx/rust-logo.png"), &pkg.join("res"), 0o644);
1508 let mut cmd = Command::new("productbuild");
1509 cmd.arg("--distribution")
1510 .arg(xform(&etc.join("pkg/Distribution.xml")))
1512 .arg(pkg.join("res"))
1513 .arg(distdir(builder).join(format!(
1515 pkgname(builder, "rust"),
1518 .arg("--package-path")
1520 let _time = timeit(builder);
1521 builder.run(&mut cmd);
1524 if target.contains("windows") {
1525 let exe = tmp.join("exe");
1526 let _ = fs::remove_dir_all(&exe);
1528 let prepare = |name: &str| {
1529 builder.create_dir(&exe.join(name));
1530 let dir = if name == "rust-std" || name == "rust-analysis" {
1531 format!("{}-{}", name, target.triple)
1532 } else if name == "rls" {
1533 "rls-preview".to_string()
1534 } else if name == "rust-analyzer" {
1535 "rust-analyzer-preview".to_string()
1536 } else if name == "clippy" {
1537 "clippy-preview".to_string()
1538 } else if name == "rust-demangler" {
1539 "rust-demangler-preview".to_string()
1540 } else if name == "miri" {
1541 "miri-preview".to_string()
1546 &work.join(&format!("{}-{}", pkgname(builder, name), target.triple)).join(dir),
1549 builder.remove(&exe.join(name).join("manifest.in"));
1553 prepare("rust-analysis");
1554 prepare("rust-docs");
1555 prepare("rust-std");
1557 for tool in &["rust-demangler", "rls", "rust-analyzer", "miri"] {
1558 if built_tools.contains(tool) {
1562 if target.contains("windows-gnu") {
1563 prepare("rust-mingw");
1566 builder.install(&etc.join("gfx/rust-logo.ico"), &exe, 0o644);
1568 // Generate msi installer
1569 let wix = PathBuf::from(env::var_os("WIX").unwrap());
1570 let heat = wix.join("bin/heat.exe");
1571 let candle = wix.join("bin/candle.exe");
1572 let light = wix.join("bin/light.exe");
1574 let heat_flags = ["-nologo", "-gg", "-sfrag", "-srd", "-sreg"];
1586 .arg("var.RustcDir")
1588 .arg(exe.join("RustcGroup.wxs")),
1603 .arg(exe.join("DocsGroup.wxs"))
1605 .arg(etc.join("msi/squash-components.xsl")),
1618 .arg("var.CargoDir")
1620 .arg(exe.join("CargoGroup.wxs"))
1622 .arg(etc.join("msi/remove-duplicates.xsl")),
1637 .arg(exe.join("StdGroup.wxs")),
1639 if built_tools.contains("rls") {
1653 .arg(exe.join("RlsGroup.wxs"))
1655 .arg(etc.join("msi/remove-duplicates.xsl")),
1658 if built_tools.contains("rust-analyzer") {
1663 .arg("rust-analyzer")
1666 .arg("RustAnalyzerGroup")
1668 .arg("RustAnalyzer")
1670 .arg("var.RustAnalyzerDir")
1672 .arg(exe.join("RustAnalyzerGroup.wxs"))
1674 .arg(etc.join("msi/remove-duplicates.xsl")),
1688 .arg("var.ClippyDir")
1690 .arg(exe.join("ClippyGroup.wxs"))
1692 .arg(etc.join("msi/remove-duplicates.xsl")),
1694 if built_tools.contains("rust-demangler") {
1699 .arg("rust-demangler")
1702 .arg("RustDemanglerGroup")
1704 .arg("RustDemangler")
1706 .arg("var.RustDemanglerDir")
1708 .arg(exe.join("RustDemanglerGroup.wxs"))
1710 .arg(etc.join("msi/remove-duplicates.xsl")),
1713 if built_tools.contains("miri") {
1727 .arg(exe.join("MiriGroup.wxs"))
1729 .arg(etc.join("msi/remove-duplicates.xsl")),
1736 .arg("rust-analysis")
1739 .arg("AnalysisGroup")
1743 .arg("var.AnalysisDir")
1745 .arg(exe.join("AnalysisGroup.wxs"))
1747 .arg(etc.join("msi/remove-duplicates.xsl")),
1749 if target.contains("windows-gnu") {
1763 .arg(exe.join("GccGroup.wxs")),
1767 let candle = |input: &Path| {
1768 let output = exe.join(input.file_stem().unwrap()).with_extension("wixobj");
1769 let arch = if target.contains("x86_64") { "x64" } else { "x86" };
1770 let mut cmd = Command::new(&candle);
1771 cmd.current_dir(&exe)
1773 .arg("-dRustcDir=rustc")
1774 .arg("-dDocsDir=rust-docs")
1775 .arg("-dCargoDir=cargo")
1776 .arg("-dStdDir=rust-std")
1777 .arg("-dAnalysisDir=rust-analysis")
1778 .arg("-dClippyDir=clippy")
1784 add_env(builder, &mut cmd, target);
1786 if built_tools.contains("rust-demangler") {
1787 cmd.arg("-dRustDemanglerDir=rust-demangler");
1789 if built_tools.contains("rls") {
1790 cmd.arg("-dRlsDir=rls");
1792 if built_tools.contains("rust-analyzer") {
1793 cmd.arg("-dRustAnalyzerDir=rust-analyzer");
1795 if built_tools.contains("miri") {
1796 cmd.arg("-dMiriDir=miri");
1798 if target.contains("windows-gnu") {
1799 cmd.arg("-dGccDir=rust-mingw");
1801 builder.run(&mut cmd);
1803 candle(&xform(&etc.join("msi/rust.wxs")));
1804 candle(&etc.join("msi/ui.wxs"));
1805 candle(&etc.join("msi/rustwelcomedlg.wxs"));
1806 candle("RustcGroup.wxs".as_ref());
1807 candle("DocsGroup.wxs".as_ref());
1808 candle("CargoGroup.wxs".as_ref());
1809 candle("StdGroup.wxs".as_ref());
1810 candle("ClippyGroup.wxs".as_ref());
1811 if built_tools.contains("rust-demangler") {
1812 candle("RustDemanglerGroup.wxs".as_ref());
1814 if built_tools.contains("rls") {
1815 candle("RlsGroup.wxs".as_ref());
1817 if built_tools.contains("rust-analyzer") {
1818 candle("RustAnalyzerGroup.wxs".as_ref());
1820 if built_tools.contains("miri") {
1821 candle("MiriGroup.wxs".as_ref());
1823 candle("AnalysisGroup.wxs".as_ref());
1825 if target.contains("windows-gnu") {
1826 candle("GccGroup.wxs".as_ref());
1829 builder.create(&exe.join("LICENSE.rtf"), &rtf);
1830 builder.install(&etc.join("gfx/banner.bmp"), &exe, 0o644);
1831 builder.install(&etc.join("gfx/dialogbg.bmp"), &exe, 0o644);
1833 builder.info(&format!("building `msi` installer with {:?}", light));
1834 let filename = format!("{}-{}.msi", pkgname(builder, "rust"), target.triple);
1835 let mut cmd = Command::new(&light);
1838 .arg("WixUIExtension")
1840 .arg("WixUtilExtension")
1842 .arg(exe.join(&filename))
1845 .arg("rustwelcomedlg.wixobj")
1846 .arg("RustcGroup.wixobj")
1847 .arg("DocsGroup.wixobj")
1848 .arg("CargoGroup.wixobj")
1849 .arg("StdGroup.wixobj")
1850 .arg("AnalysisGroup.wixobj")
1851 .arg("ClippyGroup.wixobj")
1854 if built_tools.contains("rls") {
1855 cmd.arg("RlsGroup.wixobj");
1857 if built_tools.contains("rust-analyzer") {
1858 cmd.arg("RustAnalyzerGroup.wixobj");
1860 if built_tools.contains("rust-demangler") {
1861 cmd.arg("RustDemanglerGroup.wixobj");
1863 if built_tools.contains("miri") {
1864 cmd.arg("MiriGroup.wixobj");
1867 if target.contains("windows-gnu") {
1868 cmd.arg("GccGroup.wixobj");
1870 // ICE57 wrongly complains about the shortcuts
1871 cmd.arg("-sice:ICE57");
1873 let _time = timeit(builder);
1874 builder.run(&mut cmd);
1876 if !builder.config.dry_run {
1877 t!(fs::rename(exe.join(&filename), distdir(builder).join(&filename)));
1883 fn add_env(builder: &Builder<'_>, cmd: &mut Command, target: TargetSelection) {
1884 let mut parts = builder.version.split('.');
1885 cmd.env("CFG_RELEASE_INFO", builder.rust_version())
1886 .env("CFG_RELEASE_NUM", &builder.version)
1887 .env("CFG_RELEASE", builder.rust_release())
1888 .env("CFG_VER_MAJOR", parts.next().unwrap())
1889 .env("CFG_VER_MINOR", parts.next().unwrap())
1890 .env("CFG_VER_PATCH", parts.next().unwrap())
1891 .env("CFG_VER_BUILD", "0") // just needed to build
1892 .env("CFG_PACKAGE_VERS", builder.rust_package_vers())
1893 .env("CFG_PACKAGE_NAME", pkgname(builder, "rust"))
1894 .env("CFG_BUILD", target.triple)
1895 .env("CFG_CHANNEL", &builder.config.channel);
1897 if target.contains("windows-gnu") {
1898 cmd.env("CFG_MINGW", "1").env("CFG_ABI", "GNU");
1900 cmd.env("CFG_MINGW", "0").env("CFG_ABI", "MSVC");
1903 if target.contains("x86_64") {
1904 cmd.env("CFG_PLATFORM", "x64");
1906 cmd.env("CFG_PLATFORM", "x86");
1910 /// Maybe add LLVM object files to the given destination lib-dir. Allows either static or dynamic linking.
1913 /// Returns whether the files were actually copied.
1914 fn maybe_install_llvm(builder: &Builder<'_>, target: TargetSelection, dst_libdir: &Path) -> bool {
1915 if let Some(config) = builder.config.target_config.get(&target) {
1916 if config.llvm_config.is_some() && !builder.config.llvm_from_ci {
1917 // If the LLVM was externally provided, then we don't currently copy
1918 // artifacts into the sysroot. This is not necessarily the right
1919 // choice (in particular, it will require the LLVM dylib to be in
1920 // the linker's load path at runtime), but the common use case for
1921 // external LLVMs is distribution provided LLVMs, and in that case
1922 // they're usually in the standard search path (e.g., /usr/lib) and
1923 // copying them here is going to cause problems as we may end up
1924 // with the wrong files and isn't what distributions want.
1926 // This behavior may be revisited in the future though.
1928 // If the LLVM is coming from ourselves (just from CI) though, we
1929 // still want to install it, as it otherwise won't be available.
1934 // On macOS, rustc (and LLVM tools) link to an unversioned libLLVM.dylib
1935 // instead of libLLVM-11-rust-....dylib, as on linux. It's not entirely
1936 // clear why this is the case, though. llvm-config will emit the versioned
1937 // paths and we don't want those in the sysroot (as we're expecting
1938 // unversioned paths).
1939 if target.contains("apple-darwin") && builder.config.llvm_link_shared {
1940 let src_libdir = builder.llvm_out(target).join("lib");
1941 let llvm_dylib_path = src_libdir.join("libLLVM.dylib");
1942 if llvm_dylib_path.exists() {
1943 builder.install(&llvm_dylib_path, dst_libdir, 0o644);
1945 !builder.config.dry_run
1946 } else if let Ok(llvm_config) = crate::native::prebuilt_llvm_config(builder, target) {
1947 let mut cmd = Command::new(llvm_config);
1948 cmd.arg("--libfiles");
1949 builder.verbose(&format!("running {:?}", cmd));
1950 let files = output(&mut cmd);
1951 for file in files.trim_end().split(' ') {
1952 builder.install(Path::new(file), dst_libdir, 0o644);
1954 !builder.config.dry_run
1960 /// Maybe add libLLVM.so to the target lib-dir for linking.
1961 pub fn maybe_install_llvm_target(builder: &Builder<'_>, target: TargetSelection, sysroot: &Path) {
1962 let dst_libdir = sysroot.join("lib/rustlib").join(&*target.triple).join("lib");
1963 // We do not need to copy LLVM files into the sysroot if it is not
1964 // dynamically linked; it is already included into librustc_llvm
1966 if builder.config.llvm_link_shared {
1967 maybe_install_llvm(builder, target, &dst_libdir);
1971 /// Maybe add libLLVM.so to the runtime lib-dir for rustc itself.
1972 pub fn maybe_install_llvm_runtime(builder: &Builder<'_>, target: TargetSelection, sysroot: &Path) {
1974 sysroot.join(builder.sysroot_libdir_relative(Compiler { stage: 1, host: target }));
1975 // We do not need to copy LLVM files into the sysroot if it is not
1976 // dynamically linked; it is already included into librustc_llvm
1978 if builder.config.llvm_link_shared {
1979 maybe_install_llvm(builder, target, &dst_libdir);
1983 #[derive(Clone, Debug, Eq, Hash, PartialEq)]
1984 pub struct LlvmTools {
1985 pub target: TargetSelection,
1988 impl Step for LlvmTools {
1989 type Output = Option<GeneratedTarball>;
1990 const ONLY_HOSTS: bool = true;
1992 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1993 let default = should_build_extended_tool(&run.builder, "llvm-tools");
1994 run.path("llvm-tools").default_condition(default)
1997 fn make_run(run: RunConfig<'_>) {
1998 run.builder.ensure(LlvmTools { target: run.target });
2001 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
2002 let target = self.target;
2004 /* run only if llvm-config isn't used */
2005 if let Some(config) = builder.config.target_config.get(&target) {
2006 if let Some(ref _s) = config.llvm_config {
2007 builder.info(&format!("Skipping LlvmTools ({}): external LLVM", target));
2012 let mut tarball = Tarball::new(builder, "llvm-tools", &target.triple);
2013 tarball.set_overlay(OverlayKind::LLVM);
2014 tarball.is_preview(true);
2016 // Prepare the image directory
2017 let src_bindir = builder.llvm_out(target).join("bin");
2018 let dst_bindir = format!("lib/rustlib/{}/bin", target.triple);
2019 for tool in LLVM_TOOLS {
2020 let exe = src_bindir.join(exe(tool, target));
2021 tarball.add_file(&exe, &dst_bindir, 0o755);
2024 // Copy libLLVM.so to the target lib dir as well, so the RPATH like
2025 // `$ORIGIN/../lib` can find it. It may also be used as a dependency
2026 // of `rustc-dev` to support the inherited `-lLLVM` when using the
2027 // compiler libraries.
2028 maybe_install_llvm_target(builder, target, tarball.image_dir());
2030 Some(tarball.generate())
2034 // Tarball intended for internal consumption to ease rustc/std development.
2036 // Should not be considered stable by end users.
2037 #[derive(Clone, Debug, Eq, Hash, PartialEq)]
2038 pub struct RustDev {
2039 pub target: TargetSelection,
2042 impl Step for RustDev {
2043 type Output = Option<GeneratedTarball>;
2044 const DEFAULT: bool = true;
2045 const ONLY_HOSTS: bool = true;
2047 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2048 run.path("rust-dev")
2051 fn make_run(run: RunConfig<'_>) {
2052 run.builder.ensure(RustDev { target: run.target });
2055 fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
2056 let target = self.target;
2058 /* run only if llvm-config isn't used */
2059 if let Some(config) = builder.config.target_config.get(&target) {
2060 if let Some(ref _s) = config.llvm_config {
2061 builder.info(&format!("Skipping RustDev ({}): external LLVM", target));
2066 let mut tarball = Tarball::new(builder, "rust-dev", &target.triple);
2067 tarball.set_overlay(OverlayKind::LLVM);
2069 let src_bindir = builder.llvm_out(target).join("bin");
2079 tarball.add_file(src_bindir.join(exe(bin, target)), "bin", 0o755);
2081 tarball.add_file(&builder.llvm_filecheck(target), "bin", 0o755);
2083 // Copy the include directory as well; needed mostly to build
2084 // librustc_llvm properly (e.g., llvm-config.h is in here). But also
2085 // just broadly useful to be able to link against the bundled LLVM.
2086 tarball.add_dir(&builder.llvm_out(target).join("include"), "include");
2088 // Copy libLLVM.so to the target lib dir as well, so the RPATH like
2089 // `$ORIGIN/../lib` can find it. It may also be used as a dependency
2090 // of `rustc-dev` to support the inherited `-lLLVM` when using the
2091 // compiler libraries.
2092 let dst_libdir = tarball.image_dir().join("lib");
2093 maybe_install_llvm(builder, target, &dst_libdir);
2094 let link_type = if builder.config.llvm_link_shared { "dynamic" } else { "static" };
2095 t!(std::fs::write(tarball.image_dir().join("link-type.txt"), link_type), dst_libdir);
2097 Some(tarball.generate())
2101 /// Tarball containing a prebuilt version of the build-manifest tool, intented to be used by the
2102 /// release process to avoid cloning the monorepo and building stuff.
2104 /// Should not be considered stable by end users.
2105 #[derive(Clone, Debug, Eq, Hash, PartialEq)]
2106 pub struct BuildManifest {
2107 pub target: TargetSelection,
2110 impl Step for BuildManifest {
2111 type Output = GeneratedTarball;
2112 const DEFAULT: bool = false;
2113 const ONLY_HOSTS: bool = true;
2115 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2116 run.path("src/tools/build-manifest")
2119 fn make_run(run: RunConfig<'_>) {
2120 run.builder.ensure(BuildManifest { target: run.target });
2123 fn run(self, builder: &Builder<'_>) -> GeneratedTarball {
2124 let build_manifest = builder.tool_exe(Tool::BuildManifest);
2126 let tarball = Tarball::new(builder, "build-manifest", &self.target.triple);
2127 tarball.add_file(&build_manifest, "bin", 0o755);
2132 /// Tarball containing artifacts necessary to reproduce the build of rustc.
2134 /// Currently this is the PGO profile data.
2136 /// Should not be considered stable by end users.
2137 #[derive(Clone, Debug, Eq, Hash, PartialEq)]
2138 pub struct ReproducibleArtifacts {
2139 pub target: TargetSelection,
2142 impl Step for ReproducibleArtifacts {
2143 type Output = Option<GeneratedTarball>;
2144 const DEFAULT: bool = true;
2145 const ONLY_HOSTS: bool = true;
2147 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2148 run.path("reproducible")
2151 fn make_run(run: RunConfig<'_>) {
2152 run.builder.ensure(ReproducibleArtifacts { target: run.target });
2155 fn run(self, builder: &Builder<'_>) -> Self::Output {
2156 let path = builder.config.rust_profile_use.as_ref()?;
2158 let tarball = Tarball::new(builder, "reproducible-artifacts", &self.target.triple);
2159 tarball.add_file(path, ".", 0o644);
2160 Some(tarball.generate())