Skip to content

Commit 695835e

Browse files
bootstrap: Link LLVM tools dynamically in order to save time in ThinLTO builds.
1 parent f4b8451 commit 695835e

File tree

4 files changed

+37
-16
lines changed

4 files changed

+37
-16
lines changed

src/bootstrap/dist.rs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1929,16 +1929,37 @@ impl Step for LlvmTools {
19291929
drop(fs::remove_dir_all(&image));
19301930

19311931
// Prepare the image directory
1932-
let bindir = builder
1932+
let src_bindir = builder
19331933
.llvm_out(target)
19341934
.join("bin");
1935-
let dst = image.join("lib/rustlib")
1936-
.join(target)
1937-
.join("bin");
1938-
t!(fs::create_dir_all(&dst));
1935+
let dst_bindir = image.join("bin");
1936+
t!(fs::create_dir_all(&dst_bindir));
19391937
for tool in LLVM_TOOLS {
1940-
let exe = bindir.join(exe(tool, &target));
1941-
builder.install(&exe, &dst, 0o755);
1938+
let exe = src_bindir.join(exe(tool, &target));
1939+
builder.install(&exe, &dst_bindir, 0o755);
1940+
}
1941+
1942+
// Maybe add libLLVM.so to the lib-dir. It will only have been built if
1943+
// LLVM tools are linked dynamically.
1944+
{
1945+
let src_libdir = builder
1946+
.llvm_out(target)
1947+
.join("lib");
1948+
let dst_libdir = image.join("lib");
1949+
t!(fs::create_dir_all(&dst_libdir));
1950+
1951+
// Usually libLLVM.so is a symlink to something like libLLVM-6.0.so.
1952+
// Since tools link to the latter rather than the former, we have to
1953+
// follow the symlink to find out what to distribute.
1954+
let llvm_dylib_path = src_libdir.join("libLLVM.so");
1955+
if llvm_dylib_path.exists() {
1956+
let llvm_dylib_path = llvm_dylib_path.canonicalize().unwrap_or_else(|e| {
1957+
panic!("dist: Error calling canonicalize path `{}`: {}",
1958+
llvm_dylib_path.display(), e);
1959+
});
1960+
1961+
builder.install(&llvm_dylib_path, &dst_libdir, 0o644);
1962+
}
19421963
}
19431964

19441965
// Prepare the overlay

src/bootstrap/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,10 @@ impl Build {
10251025
self.rust_version()
10261026
}
10271027

1028+
fn llvm_link_tools_dynamically(&self, target: Interned<String>) -> bool {
1029+
(target.contains("linux-gnu") || target.contains("apple-darwin"))
1030+
}
1031+
10281032
/// Returns the `version` string associated with this compiler for Rust
10291033
/// itself.
10301034
///

src/bootstrap/native.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,10 @@ impl Step for Llvm {
171171

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

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

src/ci/docker/dist-x86_64-linux/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ ENV RUST_CONFIGURE_ARGS \
9797
--set target.x86_64-unknown-linux-gnu.ar=/rustroot/bin/llvm-ar \
9898
--set target.x86_64-unknown-linux-gnu.ranlib=/rustroot/bin/llvm-ranlib \
9999
--set llvm.thin-lto=true
100-
ENV SCRIPT python2.7 ../x.py dist --host $HOSTS --target $HOSTS
100+
ENV SCRIPT python2.7 ../x.py dist --verbose --host $HOSTS --target $HOSTS
101101
ENV CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=clang
102102

103103
# This is the only builder which will create source tarballs

0 commit comments

Comments
 (0)