Skip to content

Commit 130c6ec

Browse files
committed
Fix some linking of LLVM's dynamic library
Ensure it shows up in the same places it did before so tools can find it at runtime.
1 parent 826db5f commit 130c6ec

File tree

3 files changed

+24
-25
lines changed

3 files changed

+24
-25
lines changed

src/bootstrap/compile.rs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -579,24 +579,6 @@ impl Step for RustcLink {
579579
}
580580
}
581581

582-
fn copy_lld_to_sysroot(builder: &Builder<'_>,
583-
target_compiler: Compiler,
584-
lld_install_root: &Path) {
585-
let target = target_compiler.host;
586-
587-
let dst = builder.sysroot_libdir(target_compiler, target)
588-
.parent()
589-
.unwrap()
590-
.join("bin");
591-
t!(fs::create_dir_all(&dst));
592-
593-
let src_exe = exe("lld", &target);
594-
let dst_exe = exe("rust-lld", &target);
595-
// we prepend this bin directory to the user PATH when linking Rust binaries. To
596-
// avoid shadowing the system LLD we rename the LLD we provide to `rust-lld`.
597-
builder.copy(&lld_install_root.join("bin").join(&src_exe), &dst.join(&dst_exe));
598-
}
599-
600582
/// Cargo's output path for the standard library in a given stage, compiled
601583
/// by a particular compiler for the specified target.
602584
pub fn libstd_stamp(
@@ -745,10 +727,16 @@ impl Step for Assemble {
745727
}
746728
}
747729

730+
let libdir = builder.sysroot_libdir(target_compiler, target_compiler.host);
748731
if let Some(lld_install) = lld_install {
749-
copy_lld_to_sysroot(builder, target_compiler, &lld_install);
732+
let src_exe = exe("lld", &target_compiler.host);
733+
let dst_exe = exe("rust-lld", &target_compiler.host);
734+
// we prepend this bin directory to the user PATH when linking Rust binaries. To
735+
// avoid shadowing the system LLD we rename the LLD we provide to `rust-lld`.
736+
let dst = libdir.parent().unwrap().join("bin");
737+
t!(fs::create_dir_all(&dst));
738+
builder.copy(&lld_install.join("bin").join(&src_exe), &dst.join(&dst_exe));
750739
}
751-
752740
dist::maybe_install_llvm_dylib(builder, target_compiler.host, &sysroot);
753741

754742
// Link the compiler binary itself into place

src/bootstrap/dist.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,6 +2123,10 @@ impl Step for HashSign {
21232123

21242124
// Maybe add libLLVM.so to the lib-dir. It will only have been built if
21252125
// LLVM tools are linked dynamically.
2126+
//
2127+
// We add this to both the libdir of the rustc binary itself (for it to load at
2128+
// runtime) and also to the target directory so it can find it at link-time.
2129+
//
21262130
// Note: This function does no yet support Windows but we also don't support
21272131
// linking LLVM tools dynamically on Windows yet.
21282132
pub fn maybe_install_llvm_dylib(builder: &Builder<'_>,
@@ -2131,13 +2135,19 @@ pub fn maybe_install_llvm_dylib(builder: &Builder<'_>,
21312135
let src_libdir = builder
21322136
.llvm_out(target)
21332137
.join("lib");
2134-
let dst_libdir = sysroot.join("lib/rustlib").join(&*target).join("lib");
2135-
t!(fs::create_dir_all(&dst_libdir));
2138+
let dst_libdir1 = sysroot.join("lib/rustlib").join(&*target).join("lib");
2139+
let dst_libdir2 = sysroot.join(builder.sysroot_libdir_relative(Compiler {
2140+
stage: 1,
2141+
host: target,
2142+
}));
2143+
t!(fs::create_dir_all(&dst_libdir1));
2144+
t!(fs::create_dir_all(&dst_libdir2));
21362145

21372146
if target.contains("apple-darwin") {
21382147
let llvm_dylib_path = src_libdir.join("libLLVM.dylib");
21392148
if llvm_dylib_path.exists() {
2140-
builder.install(&llvm_dylib_path, &dst_libdir, 0o644);
2149+
builder.install(&llvm_dylib_path, &dst_libdir1, 0o644);
2150+
builder.install(&llvm_dylib_path, &dst_libdir2, 0o644);
21412151
}
21422152
return
21432153
}
@@ -2153,7 +2163,8 @@ pub fn maybe_install_llvm_dylib(builder: &Builder<'_>,
21532163
});
21542164

21552165

2156-
builder.install(&llvm_dylib_path, &dst_libdir, 0o644);
2166+
builder.install(&llvm_dylib_path, &dst_libdir1, 0o644);
2167+
builder.install(&llvm_dylib_path, &dst_libdir2, 0o644);
21572168
}
21582169
}
21592170

src/bootstrap/doc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ impl Step for Std {
433433
builder.info(&format!("Documenting stage{} std ({})", stage, target));
434434
let out = builder.doc_out(target);
435435
t!(fs::create_dir_all(&out));
436-
let compiler = builder.compiler_for(stage, builder.config.build, target);
436+
let compiler = builder.compiler(stage, builder.config.build);
437437

438438
builder.ensure(compile::Std { compiler, target });
439439
let out_dir = builder.stage_out(compiler, Mode::Std)

0 commit comments

Comments
 (0)