Skip to content

Commit da50f76

Browse files
alexcrichtonAaron1011
authored andcommitted
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 adfda1f commit da50f76

File tree

3 files changed

+24
-25
lines changed

3 files changed

+24
-25
lines changed

src/bootstrap/compile.rs

+8-20
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

+15-4
Original file line numberDiff line numberDiff line change
@@ -2124,6 +2124,10 @@ impl Step for HashSign {
21242124

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

21382147
if target.contains("apple-darwin") {
21392148
let llvm_dylib_path = src_libdir.join("libLLVM.dylib");
21402149
if llvm_dylib_path.exists() {
2141-
builder.install(&llvm_dylib_path, &dst_libdir, 0o644);
2150+
builder.install(&llvm_dylib_path, &dst_libdir1, 0o644);
2151+
builder.install(&llvm_dylib_path, &dst_libdir2, 0o644);
21422152
}
21432153
return
21442154
}
@@ -2154,7 +2164,8 @@ pub fn maybe_install_llvm_dylib(builder: &Builder<'_>,
21542164
});
21552165

21562166

2157-
builder.install(&llvm_dylib_path, &dst_libdir, 0o644);
2167+
builder.install(&llvm_dylib_path, &dst_libdir1, 0o644);
2168+
builder.install(&llvm_dylib_path, &dst_libdir2, 0o644);
21582169
}
21592170
}
21602171

src/bootstrap/doc.rs

+1-1
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)