diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 0c754936bc242..1f4a4449e6807 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -772,7 +772,7 @@ impl Step for Assemble { // Ensure that `libLLVM.so` ends up in the newly build compiler directory, // so that it can be found when the newly built `rustc` is run. - dist::maybe_install_llvm_dylib(builder, target_compiler.host, &sysroot); + dist::maybe_install_llvm_runtime(builder, target_compiler.host, &sysroot); // Link the compiler binary itself into place let out_dir = builder.cargo_out(build_compiler, Mode::Rustc, host); diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index bae904114960a..b8d83c765f71d 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -516,7 +516,7 @@ impl Step for Rustc { // components like the llvm tools and LLD. LLD is included below and // tools/LLDB come later, so let's just throw it in the rustc // component for now. - maybe_install_llvm_dylib(builder, host, image); + maybe_install_llvm_runtime(builder, host, image); // Copy over lld if it's there if builder.config.lld_enabled { @@ -773,6 +773,10 @@ impl Step for RustcDev { let stamp = compile::librustc_stamp(builder, compiler_to_use, target); copy_target_libs(builder, &target, &image, &stamp); + // Copy libLLVM.so to the target lib dir as well, to support the + // inherited `-lLLVM` when using the compiler libraries. + maybe_install_llvm_target(builder, target, &image); + let mut cmd = rust_installer(builder); cmd.arg("generate") .arg("--product-name=Rust") @@ -2233,27 +2237,18 @@ impl Step for HashSign { } } -// Maybe add libLLVM.so to the lib-dir. It will only have been built if -// LLVM tools are linked dynamically. -// -// We add this to both the libdir of the rustc binary itself (for it to load at -// runtime) and also to the target directory so it can find it at link-time. -// -// Note: This function does no yet support Windows but we also don't support -// linking LLVM tools dynamically on Windows yet. -pub fn maybe_install_llvm_dylib(builder: &Builder<'_>, target: Interned, sysroot: &Path) { +/// Maybe add libLLVM.so to the given destination lib-dir. It will only have +/// been built if LLVM tools are linked dynamically. +/// +/// Note: This function does not yet support Windows, but we also don't support +/// linking LLVM tools dynamically on Windows yet. +fn maybe_install_llvm(builder: &Builder<'_>, target: Interned, dst_libdir: &Path) { let src_libdir = builder.llvm_out(target).join("lib"); - let dst_libdir1 = sysroot.join("lib/rustlib").join(&*target).join("lib"); - let dst_libdir2 = - sysroot.join(builder.sysroot_libdir_relative(Compiler { stage: 1, host: target })); - t!(fs::create_dir_all(&dst_libdir1)); - t!(fs::create_dir_all(&dst_libdir2)); if target.contains("apple-darwin") { let llvm_dylib_path = src_libdir.join("libLLVM.dylib"); if llvm_dylib_path.exists() { - builder.install(&llvm_dylib_path, &dst_libdir1, 0o644); - builder.install(&llvm_dylib_path, &dst_libdir2, 0o644); + builder.install(&llvm_dylib_path, dst_libdir, 0o644); } return; } @@ -2267,11 +2262,23 @@ pub fn maybe_install_llvm_dylib(builder: &Builder<'_>, target: Interned, panic!("dist: Error calling canonicalize path `{}`: {}", llvm_dylib_path.display(), e); }); - builder.install(&llvm_dylib_path, &dst_libdir1, 0o644); - builder.install(&llvm_dylib_path, &dst_libdir2, 0o644); + builder.install(&llvm_dylib_path, dst_libdir, 0o644); } } +/// Maybe add libLLVM.so to the target lib-dir for linking. +fn maybe_install_llvm_target(builder: &Builder<'_>, target: Interned, sysroot: &Path) { + let dst_libdir = sysroot.join("lib/rustlib").join(&*target).join("lib"); + maybe_install_llvm(builder, target, &dst_libdir); +} + +/// Maybe add libLLVM.so to the runtime lib-dir for rustc itself. +pub fn maybe_install_llvm_runtime(builder: &Builder<'_>, target: Interned, sysroot: &Path) { + let dst_libdir = + sysroot.join(builder.sysroot_libdir_relative(Compiler { stage: 1, host: target })); + maybe_install_llvm(builder, target, &dst_libdir); +} + #[derive(Clone, Debug, Eq, Hash, PartialEq)] pub struct LlvmTools { pub target: Interned,