diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index c9c9c73c84af2..e0932dbf91a13 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -451,6 +451,7 @@ impl<'a> Builder<'a> { dist::Cargo, dist::Rls, dist::Rustfmt, + dist::LlvmTools, dist::Extended, dist::HashSign ), diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index ea234c0016c34..231ed9d40d2de 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -31,7 +31,7 @@ use filetime::FileTime; use serde_json; use util::{exe, libdir, is_dylib, CiEnv}; -use {Compiler, Mode, LLVM_TOOLS}; +use {Compiler, Mode}; use native; use tool; @@ -775,23 +775,6 @@ fn copy_codegen_backends_to_sysroot(builder: &Builder, } } -fn copy_llvm_tools_to_sysroot(builder: &Builder, - target_compiler: Compiler) { - let target = target_compiler.host; - - let dst = builder.sysroot_libdir(target_compiler, target) - .parent() - .unwrap() - .join("bin"); - t!(fs::create_dir_all(&dst)); - - let src = builder.llvm_out(target).join("bin"); - for tool in LLVM_TOOLS { - let exe = exe(tool, &target); - builder.copy(&src.join(&exe), &dst.join(&exe)); - } -} - fn copy_lld_to_sysroot(builder: &Builder, target_compiler: Compiler, lld_install_root: &Path) { @@ -983,9 +966,6 @@ impl Step for Assemble { copy_codegen_backends_to_sysroot(builder, build_compiler, target_compiler); - if builder.config.ship_llvm_tools { - copy_llvm_tools_to_sysroot(builder, target_compiler); - } if let Some(lld_install) = lld_install { copy_lld_to_sysroot(builder, target_compiler, &lld_install); } diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index b676ba22172b5..c6b1b87247003 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -88,7 +88,7 @@ pub struct Config { pub llvm_link_jobs: Option, pub lld_enabled: bool, - pub ship_llvm_tools: bool, + pub llvm_tools_enabled: bool, // rust codegen options pub rust_optimize: bool, @@ -533,7 +533,7 @@ impl Config { set(&mut config.test_miri, rust.test_miri); set(&mut config.wasm_syscall, rust.wasm_syscall); set(&mut config.lld_enabled, rust.lld); - set(&mut config.ship_llvm_tools, rust.llvm_tools); + set(&mut config.llvm_tools_enabled, rust.llvm_tools); config.rustc_parallel_queries = rust.experimental_parallel_queries.unwrap_or(false); config.rustc_default_linker = rust.default_linker.clone(); config.musl_root = rust.musl_root.clone().map(PathBuf::from); diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index 9092deeac4618..73cda4b436d42 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -43,6 +43,8 @@ pub fn pkgname(builder: &Builder, component: &str) -> String { format!("{}-{}", component, builder.rls_package_vers()) } else if component == "rustfmt" { format!("{}-{}", component, builder.rustfmt_package_vers()) + } else if component == "llvm-tools" { + format!("{}-{}", component, builder.llvm_tools_vers()) } else { assert!(component.starts_with("rust")); format!("{}-{}", component, builder.rust_package_vers()) @@ -394,7 +396,7 @@ impl Step for Rustc { let compiler = self.compiler; let host = self.compiler.host; - builder.info(&format!("Dist rustc stage{} ({})", compiler.stage, compiler.host)); + builder.info(&format!("Dist rustc stage{} ({})", compiler.stage, host)); let name = pkgname(builder, "rustc"); let image = tmpdir(builder).join(format!("{}-{}-image", name, host)); let _ = fs::remove_dir_all(&image); @@ -503,24 +505,6 @@ impl Step for Rustc { builder.copy(&src, &dst); } - if builder.config.ship_llvm_tools { - let src = builder.sysroot_libdir(compiler, host) - .parent() - .unwrap() - .join("bin"); - - let dst = image.join("lib/rustlib") - .join(&*host) - .join("bin"); - - t!(fs::create_dir_all(&dst.parent().unwrap())); - - for tool in LLVM_TOOLS { - let exe = exe(tool, &compiler.host); - builder.copy(&src.join(&exe), &dst.join(&exe)); - } - } - // Man pages t!(fs::create_dir_all(image.join("share/man/man1"))); let man_src = builder.src.join("src/doc/man"); @@ -1756,6 +1740,7 @@ impl Step for HashSign { cmd.arg(builder.package_vers(&builder.release_num("cargo"))); cmd.arg(builder.package_vers(&builder.release_num("rls"))); cmd.arg(builder.package_vers(&builder.release_num("rustfmt"))); + cmd.arg(builder.llvm_tools_vers()); cmd.arg(addr); builder.create_dir(&distdir(builder)); @@ -1766,3 +1751,78 @@ impl Step for HashSign { assert!(status.success()); } } + +#[derive(Clone, Debug, Eq, Hash, PartialEq)] +pub struct LlvmTools { + pub stage: u32, + pub compiler: Compiler, + pub target: Interned, +} + +impl Step for LlvmTools { + type Output = Option; + const ONLY_HOSTS: bool = true; + + fn should_run(run: ShouldRun) -> ShouldRun { + run.path("llvm-tools") + } + + fn make_run(run: RunConfig) { + run.builder.ensure(LlvmTools { + stage: run.builder.top_stage, + compiler: run.builder.compiler(run.builder.top_stage, run.target), + target: run.target, + }); + } + + fn run(self, builder: &Builder) -> Option { + let compiler = self.compiler; + let host = compiler.host; + + let stage = self.stage; + assert!(builder.config.extended); + + builder.info(&format!("Dist LlvmTools stage{} ({})", stage, host)); + let src = builder.src.join("src/llvm"); + let name = pkgname(builder, "llvm-tools"); + + let tmp = tmpdir(builder); + let image = tmp.join("llvm-tools-image"); + drop(fs::remove_dir_all(&image)); + t!(fs::create_dir_all(&image.join("bin"))); + + // Prepare the image directory + for tool in LLVM_TOOLS { + let exe = builder + .llvm_out(host) + .join("bin") + .join(exe(tool, &compiler.host)); + builder.install(&exe, &image.join("bin"), 0o755); + } + + // Prepare the overlay + let overlay = tmp.join("llvm-tools-overlay"); + drop(fs::remove_dir_all(&overlay)); + builder.create_dir(&overlay); + builder.install(&src.join("README.txt"), &overlay, 0o644); + builder.install(&src.join("LICENSE.TXT"), &overlay, 0o644); + + // Generate the installer tarball + let mut cmd = rust_installer(builder); + cmd.arg("generate") + .arg("--product-name=Rust") + .arg("--rel-manifest-dir=rustlib") + .arg("--success-message=llvm-tools-installed.") + .arg("--image-dir").arg(&image) + .arg("--work-dir").arg(&tmpdir(builder)) + .arg("--output-dir").arg(&distdir(builder)) + .arg("--non-installed-overlay").arg(&overlay) + .arg(format!("--package-name={}-{}", name, host)) + .arg("--legacy-manifest-dirs=rustlib,cargo") + .arg("--component-name=llvm-tools"); + + + builder.run(&mut cmd); + Some(distdir(builder).join(format!("{}-{}.tar.gz", name, host))) + } +} diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index dec514a0da6e6..cb135ad6f3523 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -957,6 +957,24 @@ impl Build { self.package_vers(&self.release_num("rustfmt")) } + fn llvm_tools_vers(&self) -> String { + let stdout = build_helper::output( + Command::new(self.llvm_out(self.config.build).join("build/bin/llvm-size")) + .arg("--version"), + ); + + for line in stdout.lines() { + if line.contains("LLVM version") { + if let Some(vers) = line.split_whitespace().nth(2) { + return vers.to_string(); + } + } + } + + panic!("The output of $LLVM_TOOL has changed; \ + please fix `bootstrap::Build.llvm_tools_vers`"); + } + /// Returns the `version` string associated with this compiler for Rust /// itself. /// diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index 74083360aca78..c3f84378adfb2 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -170,12 +170,12 @@ impl Step for Llvm { // // If we are shipping llvm tools then we statically link them LLVM if (target.contains("linux-gnu") || target.contains("apple-darwin")) && - !builder.config.ship_llvm_tools { + !builder.config.llvm_tools_enabled { cfg.define("LLVM_LINK_LLVM_DYLIB", "ON"); } // For distribution we want the LLVM tools to be *statically* linked to libstdc++ - if builder.config.ship_llvm_tools { + if builder.config.llvm_tools_enabled { cfg.define("CMAKE_EXE_LINKER_FLAGS", "-Wl,-Bsymbolic -static-libstdc++"); }