Skip to content

Commit 149524b

Browse files
committed
Auto merge of rust-lang#72000 - cuviper:dist-llvm, r=<try>
Move the target libLLVM to rustc-dev 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 one time we do need the latter is for linking `rustc-dev` libraries, so let's move it to that component directly. Here are the dist sizes that I got before and after this change: rust-1.45.0-dev-x86_64-unknown-linux-gnu.tar.gz 182M 159M rust-1.45.0-dev-x86_64-unknown-linux-gnu.tar.xz 107M 91M rustc-1.45.0-dev-x86_64-unknown-linux-gnu.tar.gz 100M 78M rustc-1.45.0-dev-x86_64-unknown-linux-gnu.tar.xz 68M 53M rustc-dev-1.45.0-dev-x86_64-unknown-linux-gnu.tar.gz 146M 168M rustc-dev-1.45.0-dev-x86_64-unknown-linux-gnu.tar.xz 92M 108M The installed size should reduce by exactly one `libLLVM.so` (~70-80M), unless you also install `rustc-dev`, and then it should be identical. Resolves rust-lang#70838.
2 parents 75e1463 + 90b2c8e commit 149524b

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

src/bootstrap/compile.rs

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

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

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

src/bootstrap/dist.rs

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

521521
// Copy over lld if it's there
522522
if builder.config.lld_enabled {
@@ -773,6 +773,10 @@ impl Step for RustcDev {
773773
let stamp = compile::librustc_stamp(builder, compiler_to_use, target);
774774
copy_target_libs(builder, &target, &image, &stamp);
775775

776+
// Copy libLLVM.so to the target lib dir as well, to support the
777+
// inherited `-lLLVM` when using the compiler libraries.
778+
maybe_install_llvm_target(builder, target, &image);
779+
776780
let mut cmd = rust_installer(builder);
777781
cmd.arg("generate")
778782
.arg("--product-name=Rust")
@@ -2233,27 +2237,18 @@ impl Step for HashSign {
22332237
}
22342238
}
22352239

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

22522248
if target.contains("apple-darwin") {
22532249
let llvm_dylib_path = src_libdir.join("libLLVM.dylib");
22542250
if llvm_dylib_path.exists() {
2255-
builder.install(&llvm_dylib_path, &dst_libdir1, 0o644);
2256-
builder.install(&llvm_dylib_path, &dst_libdir2, 0o644);
2251+
builder.install(&llvm_dylib_path, dst_libdir, 0o644);
22572252
}
22582253
return;
22592254
}
@@ -2267,11 +2262,23 @@ pub fn maybe_install_llvm_dylib(builder: &Builder<'_>, target: Interned<String>,
22672262
panic!("dist: Error calling canonicalize path `{}`: {}", llvm_dylib_path.display(), e);
22682263
});
22692264

2270-
builder.install(&llvm_dylib_path, &dst_libdir1, 0o644);
2271-
builder.install(&llvm_dylib_path, &dst_libdir2, 0o644);
2265+
builder.install(&llvm_dylib_path, dst_libdir, 0o644);
22722266
}
22732267
}
22742268

2269+
/// Maybe add libLLVM.so to the target lib-dir for linking.
2270+
pub fn maybe_install_llvm_target(builder: &Builder<'_>, target: Interned<String>, sysroot: &Path) {
2271+
let dst_libdir = sysroot.join("lib/rustlib").join(&*target).join("lib");
2272+
maybe_install_llvm(builder, target, &dst_libdir);
2273+
}
2274+
2275+
/// Maybe add libLLVM.so to the runtime lib-dir for rustc itself.
2276+
pub fn maybe_install_llvm_runtime(builder: &Builder<'_>, target: Interned<String>, sysroot: &Path) {
2277+
let dst_libdir =
2278+
sysroot.join(builder.sysroot_libdir_relative(Compiler { stage: 1, host: target }));
2279+
maybe_install_llvm(builder, target, &dst_libdir);
2280+
}
2281+
22752282
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
22762283
pub struct LlvmTools {
22772284
pub target: Interned<String>,
@@ -2319,6 +2326,10 @@ impl Step for LlvmTools {
23192326
builder.install(&exe, &dst_bindir, 0o755);
23202327
}
23212328

2329+
// Copy libLLVM.so to the target lib dir as well,
2330+
// so the RPATH like `$ORIGIN/../lib` can find it.
2331+
maybe_install_llvm_target(builder, target, &image);
2332+
23222333
// Prepare the overlay
23232334
let overlay = tmp.join("llvm-tools-overlay");
23242335
drop(fs::remove_dir_all(&overlay));

0 commit comments

Comments
 (0)