Skip to content

Commit e896d4f

Browse files
bootstrap: Link LLVM tools dynamically in order to save time in ThinLTO builds.
1 parent 8ad40ed commit e896d4f

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

src/bootstrap/dist.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,16 +1924,27 @@ impl Step for LlvmTools {
19241924
drop(fs::remove_dir_all(&image));
19251925

19261926
// Prepare the image directory
1927-
let bindir = builder
1927+
let src_bindir = builder
19281928
.llvm_out(target)
19291929
.join("bin");
1930-
let dst = image.join("lib/rustlib")
1930+
let dst_bindir = image.join("lib/rustlib")
19311931
.join(target)
19321932
.join("bin");
1933-
t!(fs::create_dir_all(&dst));
1933+
t!(fs::create_dir_all(&dst_bindir));
19341934
for tool in LLVM_TOOLS {
1935-
let exe = bindir.join(exe(tool, &target));
1936-
builder.install(&exe, &dst, 0o755);
1935+
let exe = src_bindir.join(exe(tool, &target));
1936+
builder.install(&exe, &dst_bindir, 0o755);
1937+
}
1938+
1939+
if builder.llvm_link_tools_dynamically(target) {
1940+
let src_libdir = builder
1941+
.llvm_out(target)
1942+
.join("lib");
1943+
let dst_libdir = image.join("lib/rustlib")
1944+
.join(target)
1945+
.join("lib");
1946+
t!(fs::create_dir_all(&dst_libdir));
1947+
builder.install(&src_libdir.join("libLLVM.so"), &dst_libdir, 0o644);
19371948
}
19381949

19391950
// Prepare the overlay

src/bootstrap/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,10 @@ impl Build {
10121012
self.rust_version()
10131013
}
10141014

1015+
fn llvm_link_tools_dynamically(&self, target: Interned<String>) -> bool {
1016+
target.contains("linux-gnu") || target.contains("apple-darwin")
1017+
}
1018+
10151019
/// Returns the `version` string associated with this compiler for Rust
10161020
/// itself.
10171021
///

src/bootstrap/native.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,10 @@ impl Step for Llvm {
170170

171171
// This setting makes the LLVM tools link to the dynamic LLVM library,
172172
// which saves both memory during parallel links and overall disk space
173-
// for the tools. We don't distribute any of those tools, so this is
174-
// just a local concern. However, it doesn't work well everywhere.
175-
//
176-
// If we are shipping llvm tools then we statically link them LLVM
177-
if (target.contains("linux-gnu") || target.contains("apple-darwin")) &&
178-
!builder.config.llvm_tools_enabled {
179-
cfg.define("LLVM_LINK_LLVM_DYLIB", "ON");
173+
// for the tools. We don't do this on every platform as it doesn't work
174+
// equally well everywhere.
175+
if builder.llvm_link_tools_dynamically(target) {
176+
cfg.define("LLVM_LINK_LLVM_DYLIB", "ON");
180177
}
181178

182179
// For distribution we want the LLVM tools to be *statically* linked to libstdc++

0 commit comments

Comments
 (0)