From 80e27cdd02e86dc1a35b1695049a42a09586320d Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Wed, 30 May 2018 16:36:18 +0200 Subject: [PATCH 1/7] bootstrap: Allow to specify ranlib tool used when compiling C++ code. --- config.toml.example | 4 ++++ src/bootstrap/config.rs | 3 +++ src/bootstrap/lib.rs | 7 +++++++ src/bootstrap/native.rs | 8 ++++++++ 4 files changed, 22 insertions(+) diff --git a/config.toml.example b/config.toml.example index 107375ac5cc3a..e7a530ba4c2af 100644 --- a/config.toml.example +++ b/config.toml.example @@ -388,6 +388,10 @@ # Note: an absolute path should be used, otherwise LLVM build will break. #ar = "ar" +# Ranlib to be used to assemble static libraries compiled from C/C++ code. +# Note: an absolute path should be used, otherwise LLVM build will break. +#ranlib = "ranlib" + # Linker to be used to link Rust code. Note that the # default value is platform specific, and if not specified it may also depend on # what platform is crossing to what platform. diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 43650332d3b67..aef97204a4abc 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -163,6 +163,7 @@ pub struct Target { pub cc: Option, pub cxx: Option, pub ar: Option, + pub ranlib: Option, pub linker: Option, pub ndk: Option, pub crt_static: Option, @@ -327,6 +328,7 @@ struct TomlTarget { cc: Option, cxx: Option, ar: Option, + ranlib: Option, linker: Option, android_ndk: Option, crt_static: Option, @@ -581,6 +583,7 @@ impl Config { target.cc = cfg.cc.clone().map(PathBuf::from); target.cxx = cfg.cxx.clone().map(PathBuf::from); target.ar = cfg.ar.clone().map(PathBuf::from); + target.ranlib = cfg.ranlib.clone().map(PathBuf::from); target.linker = cfg.linker.clone().map(PathBuf::from); target.crt_static = cfg.crt_static.clone(); target.musl_root = cfg.musl_root.clone().map(PathBuf::from); diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 5bb475e07ba8d..97b05059c88d1 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -281,6 +281,7 @@ pub struct Build { cc: HashMap, cc::Tool>, cxx: HashMap, cc::Tool>, ar: HashMap, PathBuf>, + ranlib: HashMap, PathBuf>, // Misc crates: HashMap, Crate>, is_sudo: bool, @@ -406,6 +407,7 @@ impl Build { cc: HashMap::new(), cxx: HashMap::new(), ar: HashMap::new(), + ranlib: HashMap::new(), crates: HashMap::new(), lldb_version: None, lldb_python_dir: None, @@ -772,6 +774,11 @@ impl Build { self.ar.get(&target).map(|p| &**p) } + /// Returns the path to the `ranlib` utility for the target specified. + fn ranlib(&self, target: Interned) -> Option<&Path> { + self.ranlib.get(&target).map(|p| &**p) + } + /// Returns the path to the C++ compiler for the target specified. fn cxx(&self, target: Interned) -> Result<&Path, String> { match self.cxx.get(&target) { diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index c99347aa94e66..0e8605750dc64 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -379,6 +379,14 @@ fn configure_cmake(builder: &Builder, } } + if let Some(ranlib) = builder.ranlib(target) { + if ranlib.is_absolute() { + // LLVM build breaks if `CMAKE_RANLIB` is a relative path, for some reason it + // tries to resolve this path in the LLVM build directory. + cfg.define("CMAKE_RANLIB", sanitize_cc(ranlib)); + } + } + if env::var_os("SCCACHE_ERROR_LOG").is_some() { cfg.env("RUST_LOG", "sccache=warn"); } From 34a654caa3640b606316169ebb57e4236e35f57a Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Fri, 10 Aug 2018 12:22:28 +0200 Subject: [PATCH 2/7] bootstrap: Allow to invoke cargo with the Usage: rustc [OPTIONS] INPUT Options: -h, --help Display this message --cfg SPEC Configure the compilation environment -L [KIND=]PATH Add a directory to the library search path. The optional KIND can be one of dependency, crate, native, framework or all (the default). -l [KIND=]NAME Link the generated crate(s) to the specified native library NAME. The optional KIND can be one of static, dylib, or framework. If omitted, dylib is assumed. --crate-type [bin|lib|rlib|dylib|cdylib|staticlib|proc-macro] Comma separated list of types of crates for the compiler to emit --crate-name NAME Specify the name of the crate being built --emit [asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info|mir] Comma separated list of types of output for the compiler to emit --print [crate-name|file-names|sysroot|cfg|target-list|target-cpus|target-features|relocation-models|code-models|tls-models|target-spec-json|native-static-libs] Comma separated list of compiler information to print on stdout -g Equivalent to -C debuginfo=2 -O Equivalent to -C opt-level=2 -o FILENAME Write output to --out-dir DIR Write output to compiler-chosen filename in --explain OPT Provide a detailed explanation of an error message --test Build a test harness --target TARGET Target triple for which the code is compiled -W, --warn OPT Set lint warnings -A, --allow OPT Set lint allowed -D, --deny OPT Set lint denied -F, --forbid OPT Set lint forbidden --cap-lints LEVEL Set the most restrictive lint level. More restrictive lints are capped at this level -C, --codegen OPT[=VALUE] Set a codegen option -V, --version Print version info and exit -v, --verbose Use verbose output Additional help: -C help Print codegen options -W help Print 'lint' options and default settings --help -v Print the full set of options rustc accepts command. --- src/bootstrap/builder.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 12c1972c22039..5c287f25e26bc 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -827,7 +827,7 @@ impl<'a> Builder<'a> { if let Some(ref error_format) = self.config.rustc_error_format { cargo.env("RUSTC_ERROR_FORMAT", error_format); } - if cmd != "build" && cmd != "check" && want_rustdoc { + if cmd != "build" && cmd != "check" && cmd != "rustc" && want_rustdoc { cargo.env("RUSTDOC_LIBDIR", self.sysroot_libdir(compiler, self.config.build)); } @@ -988,7 +988,7 @@ impl<'a> Builder<'a> { } } - if cmd == "build" + if (cmd == "build" || cmd == "rustc") && mode == Mode::Std && self.config.extended && compiler.is_final_stage(self) From 45497e32ccade5671f564ea6df69db1423fe090c Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Fri, 10 Aug 2018 12:23:48 +0200 Subject: [PATCH 3/7] bootstrap: Allow for building LLVM with ThinLTO. --- config.toml.example | 6 +++++ src/bootstrap/check.rs | 5 +++++ src/bootstrap/compile.rs | 47 +++++++++++++++++++++++++++++++++++++--- src/bootstrap/config.rs | 3 +++ src/bootstrap/native.rs | 5 +++++ src/bootstrap/tool.rs | 2 +- 6 files changed, 64 insertions(+), 4 deletions(-) diff --git a/config.toml.example b/config.toml.example index e7a530ba4c2af..35f69cd05b607 100644 --- a/config.toml.example +++ b/config.toml.example @@ -21,6 +21,12 @@ # Indicates whether the LLVM build is a Release or Debug build #optimize = true +# Indicates whether LLVM should be built with ThinLTO. Note that this will +# only succeed if you use clang, lld, llvm-ar, and llvm-ranlib in your C/C++ +# toolchain (see the `cc`, `cxx`, `linker`, `ar`, and `ranlib` options below). +# More info at: https://clang.llvm.org/docs/ThinLTO.html#clang-bootstrap +#thin-lto = false + # Indicates whether an LLVM Release build should include debug info #release-debuginfo = false diff --git a/src/bootstrap/check.rs b/src/bootstrap/check.rs index 133e5aa37a7db..20cdfcb3d2981 100644 --- a/src/bootstrap/check.rs +++ b/src/bootstrap/check.rs @@ -50,6 +50,7 @@ impl Step for Std { println!("Checking std artifacts ({} -> {})", &compiler.host, target); run_cargo(builder, &mut cargo, + vec![], &libstd_stamp(builder, compiler, target), true); @@ -98,6 +99,7 @@ impl Step for Rustc { println!("Checking compiler artifacts ({} -> {})", &compiler.host, target); run_cargo(builder, &mut cargo, + vec![], &librustc_stamp(builder, compiler, target), true); @@ -149,6 +151,7 @@ impl Step for CodegenBackend { let _folder = builder.fold_output(|| format!("stage{}-rustc_codegen_llvm", compiler.stage)); run_cargo(builder, &mut cargo, + vec![], &codegen_backend_stamp(builder, compiler, target, backend), true); } @@ -187,6 +190,7 @@ impl Step for Test { println!("Checking test artifacts ({} -> {})", &compiler.host, target); run_cargo(builder, &mut cargo, + vec![], &libtest_stamp(builder, compiler, target), true); @@ -236,6 +240,7 @@ impl Step for Rustdoc { println!("Checking rustdoc artifacts ({} -> {})", &compiler.host, target); run_cargo(builder, &mut cargo, + vec![], &rustdoc_stamp(builder, compiler, target), true); diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 2f8816d111a9d..da0ccf5e1773d 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -117,6 +117,7 @@ impl Step for Std { &compiler.host, target)); run_cargo(builder, &mut cargo, + vec![], &libstd_stamp(builder, compiler, target), false); @@ -396,6 +397,7 @@ impl Step for Test { &compiler.host, target)); run_cargo(builder, &mut cargo, + vec![], &libtest_stamp(builder, compiler, target), false); @@ -529,6 +531,7 @@ impl Step for Rustc { compiler.stage, &compiler.host, target)); run_cargo(builder, &mut cargo, + vec![], &librustc_stamp(builder, compiler, target), false); @@ -673,18 +676,47 @@ impl Step for CodegenBackend { let out_dir = builder.cargo_out(compiler, Mode::Codegen, target); builder.clear_if_dirty(&out_dir, &librustc_stamp(builder, compiler, target)); - let mut cargo = builder.cargo(compiler, Mode::Codegen, target, "build"); + let mut cargo = builder.cargo(compiler, Mode::Codegen, target, "rustc"); cargo.arg("--manifest-path") .arg(builder.src.join("src/librustc_codegen_llvm/Cargo.toml")); rustc_cargo_env(builder, &mut cargo); let features = build_codegen_backend(&builder, &mut cargo, &compiler, target, backend); + let mut cargo_tails_args = vec![]; + + if builder.config.llvm_thin_lto { + cargo_tails_args.push("--".to_string()); + + let num_jobs = builder.jobs(); + + if !target.contains("msvc") { + // Here we assume that the linker is clang. If it's not, there'll + // be linker errors. + cargo_tails_args.push("-Clink-arg=-fuse-ld=lld".to_string()); + cargo_tails_args.push("-Clink-arg=-flto=thin".to_string()); + + if builder.config.llvm_optimize { + cargo_tails_args.push("-Clink-arg=-O2".to_string()); + } + + // Let's make LLD respect the `-j` option. + let num_jobs_arg = format!("-Clink-arg=-Wl,--thinlto-jobs={}", num_jobs); + cargo_tails_args.push(num_jobs_arg); + } else { + // Here we assume that the linker is lld-link.exe. lld-link.exe + // does not need the extra arguments except for num_jobs + let num_jobs_arg = format!("-Clink-arg=/opt:lldltojobs={}", num_jobs); + cargo_tails_args.push(num_jobs_arg); + } + } + let tmp_stamp = out_dir.join(".tmp.stamp"); let _folder = builder.fold_output(|| format!("stage{}-rustc_codegen_llvm", compiler.stage)); let files = run_cargo(builder, cargo.arg("--features").arg(features), + cargo_tails_args, &tmp_stamp, false); if builder.config.dry_run { @@ -1045,7 +1077,11 @@ fn stderr_isatty() -> bool { } } -pub fn run_cargo(builder: &Builder, cargo: &mut Command, stamp: &Path, is_check: bool) +pub fn run_cargo(builder: &Builder, + cargo: &mut Command, + tail_args: Vec, + stamp: &Path, + is_check: bool) -> Vec { if builder.config.dry_run { @@ -1066,7 +1102,7 @@ pub fn run_cargo(builder: &Builder, cargo: &mut Command, stamp: &Path, is_check: // files we need to probe for later. let mut deps = Vec::new(); let mut toplevel = Vec::new(); - let ok = stream_cargo(builder, cargo, &mut |msg| { + let ok = stream_cargo(builder, cargo, tail_args, &mut |msg| { let filenames = match msg { CargoMessage::CompilerArtifact { filenames, .. } => filenames, _ => return, @@ -1191,6 +1227,7 @@ pub fn run_cargo(builder: &Builder, cargo: &mut Command, stamp: &Path, is_check: pub fn stream_cargo( builder: &Builder, cargo: &mut Command, + tail_args: Vec, cb: &mut dyn FnMut(CargoMessage), ) -> bool { if builder.config.dry_run { @@ -1210,6 +1247,10 @@ pub fn stream_cargo( cargo.env("RUSTC_COLOR", "1"); } + for arg in tail_args { + cargo.arg(arg); + } + builder.verbose(&format!("running: {:?}", cargo)); let mut child = match cargo.spawn() { Ok(child) => child, diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index aef97204a4abc..bf4d39c4947e5 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -77,6 +77,7 @@ pub struct Config { pub llvm_enabled: bool, pub llvm_assertions: bool, pub llvm_optimize: bool, + pub llvm_thin_lto: bool, pub llvm_release_debuginfo: bool, pub llvm_version_check: bool, pub llvm_static_stdcpp: bool, @@ -247,6 +248,7 @@ struct Llvm { ninja: Option, assertions: Option, optimize: Option, + thin_lto: Option, release_debuginfo: Option, version_check: Option, static_libstdcpp: Option, @@ -505,6 +507,7 @@ impl Config { set(&mut config.llvm_enabled, llvm.enabled); llvm_assertions = llvm.assertions; set(&mut config.llvm_optimize, llvm.optimize); + set(&mut config.llvm_thin_lto, llvm.thin_lto); set(&mut config.llvm_release_debuginfo, llvm.release_debuginfo); set(&mut config.llvm_version_check, llvm.version_check); set(&mut config.llvm_static_stdcpp, llvm.static_libstdcpp); diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index 0e8605750dc64..966673d7d2c14 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -153,6 +153,11 @@ impl Step for Llvm { .define("LLVM_TARGET_ARCH", target.split('-').next().unwrap()) .define("LLVM_DEFAULT_TARGET_TRIPLE", target); + if builder.config.llvm_thin_lto { + cfg.define("LLVM_ENABLE_LTO", "Thin") + .define("LLVM_ENABLE_LLD", "ON"); + } + // By default, LLVM will automatically find OCaml and, if it finds it, // install the LLVM bindings in LLVM_OCAML_INSTALL_PATH, which defaults // to /usr/bin/ocaml. diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs index 23ef031dcb703..04aaa97065473 100644 --- a/src/bootstrap/tool.rs +++ b/src/bootstrap/tool.rs @@ -136,7 +136,7 @@ impl Step for ToolBuild { let _folder = builder.fold_output(|| format!("stage{}-{}", compiler.stage, tool)); builder.info(&format!("Building stage{} tool {} ({})", compiler.stage, tool, target)); let mut duplicates = Vec::new(); - let is_expected = compile::stream_cargo(builder, &mut cargo, &mut |msg| { + let is_expected = compile::stream_cargo(builder, &mut cargo, vec![], &mut |msg| { // Only care about big things like the RLS/Cargo for now match tool { | "rls" From 9574bf5a3ebe3ebd0059a06067a2d13d0a9da043 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Wed, 30 May 2018 11:12:50 +0200 Subject: [PATCH 4/7] Build LLD in addition to Clang in Linux CI --- src/ci/docker/dist-x86_64-linux/build-clang.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ci/docker/dist-x86_64-linux/build-clang.sh b/src/ci/docker/dist-x86_64-linux/build-clang.sh index b0c27aa45bf93..4595eacb31061 100755 --- a/src/ci/docker/dist-x86_64-linux/build-clang.sh +++ b/src/ci/docker/dist-x86_64-linux/build-clang.sh @@ -30,6 +30,12 @@ curl https://releases.llvm.org/$LLVM/cfe-$LLVM.src.tar.xz | \ xz -d | \ tar xf - -C tools/clang --strip-components=1 +mkdir -p tools/lld + +curl https://releases.llvm.org/$LLVM/lld-$LLVM.src.tar.xz | \ + xz -d | \ + tar xf - -C tools/lld --strip-components=1 + mkdir ../clang-build cd ../clang-build From 73364c8befd11d08c04511f4b0639e3bd9a1ab30 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Fri, 10 Aug 2018 12:29:28 +0200 Subject: [PATCH 5/7] Compile LLVM with ThinLTO for x86_64 Linux dist builds. --- src/ci/docker/dist-x86_64-linux/Dockerfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ci/docker/dist-x86_64-linux/Dockerfile b/src/ci/docker/dist-x86_64-linux/Dockerfile index 5726fab7524ae..01f6db03e8ee0 100644 --- a/src/ci/docker/dist-x86_64-linux/Dockerfile +++ b/src/ci/docker/dist-x86_64-linux/Dockerfile @@ -93,7 +93,10 @@ ENV RUST_CONFIGURE_ARGS \ --enable-sanitizers \ --enable-profiler \ --enable-compiler-docs \ - --set target.x86_64-unknown-linux-gnu.linker=clang + --set target.x86_64-unknown-linux-gnu.linker=clang \ + --set target.x86_64-unknown-linux-gnu.ar=/rustroot/bin/llvm-ar \ + --set target.x86_64-unknown-linux-gnu.ranlib=/rustroot/bin/llvm-ranlib \ + --set llvm.thin-lto=true ENV SCRIPT python2.7 ../x.py dist --host $HOSTS --target $HOSTS ENV CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=clang From f4b8451ad9e2a30792f17f913ee4d1b0513d199c Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Tue, 14 Aug 2018 14:26:34 +0200 Subject: [PATCH 6/7] bootstrap: Never compiler llvm-emscripten with ThinLTO. --- src/bootstrap/native.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index 966673d7d2c14..518fe95f3ddd8 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -153,7 +153,7 @@ impl Step for Llvm { .define("LLVM_TARGET_ARCH", target.split('-').next().unwrap()) .define("LLVM_DEFAULT_TARGET_TRIPLE", target); - if builder.config.llvm_thin_lto { + if builder.config.llvm_thin_lto && !emscripten { cfg.define("LLVM_ENABLE_LTO", "Thin") .define("LLVM_ENABLE_LLD", "ON"); } From 3cf6f0db1ab61ed33c585b156a0d5c41279f0810 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Tue, 14 Aug 2018 14:31:12 +0200 Subject: [PATCH 7/7] bootstrap: Link LLVM tools dynamically in order to save time in ThinLTO builds. --- src/bootstrap/dist.rs | 46 ++++++++++++++++++++++++++++++++++------- src/bootstrap/lib.rs | 4 ++++ src/bootstrap/native.rs | 12 ++++------- 3 files changed, 46 insertions(+), 16 deletions(-) diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index 6e473fae3be5c..c6ff63ad71b80 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -1885,6 +1885,34 @@ impl Step for HashSign { } } +// Maybe add libLLVM.so to the lib-dir. It will only have been built if +// LLVM tools are linked dynamically. +// Note: This function does no yet support Windows but we also don't support +// linking LLVM tools dynamically on Windows yet. +fn maybe_install_llvm_dylib(builder: &Builder, + target: Interned, + image: &Path) { + let src_libdir = builder + .llvm_out(target) + .join("lib"); + + // Usually libLLVM.so is a symlink to something like libLLVM-6.0.so. + // Since tools link to the latter rather than the former, we have to + // follow the symlink to find out what to distribute. + let llvm_dylib_path = src_libdir.join("libLLVM.so"); + if llvm_dylib_path.exists() { + let llvm_dylib_path = llvm_dylib_path.canonicalize().unwrap_or_else(|e| { + panic!("dist: Error calling canonicalize path `{}`: {}", + llvm_dylib_path.display(), e); + }); + + let dst_libdir = image.join("lib"); + t!(fs::create_dir_all(&dst_libdir)); + + builder.install(&llvm_dylib_path, &dst_libdir, 0o644); + } +} + #[derive(Clone, Debug, Eq, Hash, PartialEq)] pub struct LlvmTools { pub stage: u32, @@ -1929,18 +1957,18 @@ impl Step for LlvmTools { drop(fs::remove_dir_all(&image)); // Prepare the image directory - let bindir = builder + let src_bindir = builder .llvm_out(target) .join("bin"); - let dst = image.join("lib/rustlib") - .join(target) - .join("bin"); - t!(fs::create_dir_all(&dst)); + let dst_bindir = image.join("bin"); + t!(fs::create_dir_all(&dst_bindir)); for tool in LLVM_TOOLS { - let exe = bindir.join(exe(tool, &target)); - builder.install(&exe, &dst, 0o755); + let exe = src_bindir.join(exe(tool, &target)); + builder.install(&exe, &dst_bindir, 0o755); } + maybe_install_llvm_dylib(builder, target, &image); + // Prepare the overlay let overlay = tmp.join("llvm-tools-overlay"); drop(fs::remove_dir_all(&overlay)); @@ -2025,7 +2053,6 @@ impl Step for Lldb { let dst = image.join("lib"); t!(fs::create_dir_all(&dst)); for entry in t!(fs::read_dir(&libdir)) { - // let entry = t!(entry); let entry = entry.unwrap(); if let Ok(name) = entry.file_name().into_string() { if name.starts_with("liblldb.") && !name.ends_with(".a") { @@ -2060,6 +2087,9 @@ impl Step for Lldb { } } + // Copy libLLVM.so to the lib dir as well, if needed. + maybe_install_llvm_dylib(builder, target, &image); + // Prepare the overlay let overlay = tmp.join("lldb-overlay"); drop(fs::remove_dir_all(&overlay)); diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 97b05059c88d1..b6a89e1c18fab 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -1025,6 +1025,10 @@ impl Build { self.rust_version() } + fn llvm_link_tools_dynamically(&self, target: Interned) -> bool { + (target.contains("linux-gnu") || target.contains("apple-darwin")) + } + /// Returns the `version` string associated with this compiler for Rust /// itself. /// diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index 518fe95f3ddd8..c28b467df5093 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -171,14 +171,10 @@ impl Step for Llvm { // This setting makes the LLVM tools link to the dynamic LLVM library, // which saves both memory during parallel links and overall disk space - // for the tools. We don't distribute any of those tools, so this is - // just a local concern. However, it doesn't work well everywhere. - // - // If we are shipping llvm tools then we statically link them LLVM - if (target.contains("linux-gnu") || target.contains("apple-darwin")) && - !builder.config.llvm_tools_enabled && - !want_lldb { - cfg.define("LLVM_LINK_LLVM_DYLIB", "ON"); + // for the tools. We don't do this on every platform as it doesn't work + // equally well everywhere. + if builder.llvm_link_tools_dynamically(target) && !emscripten { + cfg.define("LLVM_LINK_LLVM_DYLIB", "ON"); } // For distribution we want the LLVM tools to be *statically* linked to libstdc++