Skip to content

Commit c60b675

Browse files
committed
Auto merge of #72000 - cuviper:dist-llvm, r=Mark-Simulacrum
Move the target libLLVM to llvm-tools-preview For running the compiler, we usually only need LLVM from `$sysroot/lib`, which rustup will make available with `LD_LIBRARY_PATH`. We've also been shipping LLVM in the `$target/lib` directory, which bloats the download and installed size. The only times we do need the latter are for the RPATH of `llvm-tools-preview` binaries, and for linking `rustc-dev` libraries. We'll move it to the `llvm-tools-preview` component directly, and `rustc-dev` will have an implicit dependency on it. Here are the dist sizes that I got before and after this change: llvm-tools-1.45.0-dev-x86_64-unknown-linux-gnu.tar.gz 1.3M 24M llvm-tools-1.45.0-dev-x86_64-unknown-linux-gnu.tar.xz 748K 17M rustc-1.45.0-dev-x86_64-unknown-linux-gnu.tar.gz 83M 61M rustc-1.45.0-dev-x86_64-unknown-linux-gnu.tar.xz 56M 41M The installed size should reduce by exactly one `libLLVM.so` (~70-80M), unless you also install `llvm-tools`, and then it should be identical. Resolves #70838.
2 parents 458a3e7 + 9c97b3c commit c60b675

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed

src/bootstrap/compile.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,8 @@ impl Step for Assemble {
773773

774774
// Ensure that `libLLVM.so` ends up in the newly build compiler directory,
775775
// so that it can be found when the newly built `rustc` is run.
776-
dist::maybe_install_llvm_dylib(builder, target_compiler.host, &sysroot);
776+
dist::maybe_install_llvm_runtime(builder, target_compiler.host, &sysroot);
777+
dist::maybe_install_llvm_target(builder, target_compiler.host, &sysroot);
777778

778779
// Link the compiler binary itself into place
779780
let out_dir = builder.cargo_out(build_compiler, Mode::Rustc, host);

src/bootstrap/dist.rs

+28-19
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ impl Step for Rustc {
514514
// components like the llvm tools and LLD. LLD is included below and
515515
// tools/LLDB come later, so let's just throw it in the rustc
516516
// component for now.
517-
maybe_install_llvm_dylib(builder, host, image);
517+
maybe_install_llvm_runtime(builder, host, image);
518518

519519
// Copy over lld if it's there
520520
if builder.config.lld_enabled {
@@ -2228,27 +2228,18 @@ impl Step for HashSign {
22282228
}
22292229
}
22302230

2231-
// Maybe add libLLVM.so to the lib-dir. It will only have been built if
2232-
// LLVM tools are linked dynamically.
2233-
//
2234-
// We add this to both the libdir of the rustc binary itself (for it to load at
2235-
// runtime) and also to the target directory so it can find it at link-time.
2236-
//
2237-
// Note: This function does no yet support Windows but we also don't support
2238-
// linking LLVM tools dynamically on Windows yet.
2239-
pub fn maybe_install_llvm_dylib(builder: &Builder<'_>, target: Interned<String>, sysroot: &Path) {
2231+
/// Maybe add libLLVM.so to the given destination lib-dir. It will only have
2232+
/// been built if LLVM tools are linked dynamically.
2233+
///
2234+
/// Note: This function does not yet support Windows, but we also don't support
2235+
/// linking LLVM tools dynamically on Windows yet.
2236+
fn maybe_install_llvm(builder: &Builder<'_>, target: Interned<String>, dst_libdir: &Path) {
22402237
let src_libdir = builder.llvm_out(target).join("lib");
2241-
let dst_libdir1 = sysroot.join("lib/rustlib").join(&*target).join("lib");
2242-
let dst_libdir2 =
2243-
sysroot.join(builder.sysroot_libdir_relative(Compiler { stage: 1, host: target }));
2244-
t!(fs::create_dir_all(&dst_libdir1));
2245-
t!(fs::create_dir_all(&dst_libdir2));
22462238

22472239
if target.contains("apple-darwin") {
22482240
let llvm_dylib_path = src_libdir.join("libLLVM.dylib");
22492241
if llvm_dylib_path.exists() {
2250-
builder.install(&llvm_dylib_path, &dst_libdir1, 0o644);
2251-
builder.install(&llvm_dylib_path, &dst_libdir2, 0o644);
2242+
builder.install(&llvm_dylib_path, dst_libdir, 0o644);
22522243
}
22532244
return;
22542245
}
@@ -2262,11 +2253,23 @@ pub fn maybe_install_llvm_dylib(builder: &Builder<'_>, target: Interned<String>,
22622253
panic!("dist: Error calling canonicalize path `{}`: {}", llvm_dylib_path.display(), e);
22632254
});
22642255

2265-
builder.install(&llvm_dylib_path, &dst_libdir1, 0o644);
2266-
builder.install(&llvm_dylib_path, &dst_libdir2, 0o644);
2256+
builder.install(&llvm_dylib_path, dst_libdir, 0o644);
22672257
}
22682258
}
22692259

2260+
/// Maybe add libLLVM.so to the target lib-dir for linking.
2261+
pub fn maybe_install_llvm_target(builder: &Builder<'_>, target: Interned<String>, sysroot: &Path) {
2262+
let dst_libdir = sysroot.join("lib/rustlib").join(&*target).join("lib");
2263+
maybe_install_llvm(builder, target, &dst_libdir);
2264+
}
2265+
2266+
/// Maybe add libLLVM.so to the runtime lib-dir for rustc itself.
2267+
pub fn maybe_install_llvm_runtime(builder: &Builder<'_>, target: Interned<String>, sysroot: &Path) {
2268+
let dst_libdir =
2269+
sysroot.join(builder.sysroot_libdir_relative(Compiler { stage: 1, host: target }));
2270+
maybe_install_llvm(builder, target, &dst_libdir);
2271+
}
2272+
22702273
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
22712274
pub struct LlvmTools {
22722275
pub target: Interned<String>,
@@ -2314,6 +2317,12 @@ impl Step for LlvmTools {
23142317
builder.install(&exe, &dst_bindir, 0o755);
23152318
}
23162319

2320+
// Copy libLLVM.so to the target lib dir as well, so the RPATH like
2321+
// `$ORIGIN/../lib` can find it. It may also be used as a dependency
2322+
// of `rustc-dev` to support the inherited `-lLLVM` when using the
2323+
// compiler libraries.
2324+
maybe_install_llvm_target(builder, target, &image);
2325+
23172326
// Prepare the overlay
23182327
let overlay = tmp.join("llvm-tools-overlay");
23192328
drop(fs::remove_dir_all(&overlay));

0 commit comments

Comments
 (0)