Skip to content

Commit

Permalink
Fix some linking of LLVM's dynamic library
Browse files Browse the repository at this point in the history
Ensure it shows up in the same places it did before so tools can find it
at runtime.
  • Loading branch information
alexcrichton authored and Aaron1011 committed Dec 11, 2019
1 parent 7f23e6e commit 91b25a8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 deletions.
28 changes: 8 additions & 20 deletions src/bootstrap/compile.rs
Expand Up @@ -579,24 +579,6 @@ impl Step for RustcLink {
}
}

fn copy_lld_to_sysroot(builder: &Builder<'_>,
target_compiler: Compiler,
lld_install_root: &Path) {
let target = target_compiler.host;

let dst = builder.sysroot_libdir(target_compiler, target)
.parent()
.unwrap()
.join("bin");
t!(fs::create_dir_all(&dst));

let src_exe = exe("lld", &target);
let dst_exe = exe("rust-lld", &target);
// we prepend this bin directory to the user PATH when linking Rust binaries. To
// avoid shadowing the system LLD we rename the LLD we provide to `rust-lld`.
builder.copy(&lld_install_root.join("bin").join(&src_exe), &dst.join(&dst_exe));
}

/// Cargo's output path for the standard library in a given stage, compiled
/// by a particular compiler for the specified target.
pub fn libstd_stamp(
Expand Down Expand Up @@ -745,10 +727,16 @@ impl Step for Assemble {
}
}

let libdir = builder.sysroot_libdir(target_compiler, target_compiler.host);
if let Some(lld_install) = lld_install {
copy_lld_to_sysroot(builder, target_compiler, &lld_install);
let src_exe = exe("lld", &target_compiler.host);
let dst_exe = exe("rust-lld", &target_compiler.host);
// we prepend this bin directory to the user PATH when linking Rust binaries. To
// avoid shadowing the system LLD we rename the LLD we provide to `rust-lld`.
let dst = libdir.parent().unwrap().join("bin");
t!(fs::create_dir_all(&dst));
builder.copy(&lld_install.join("bin").join(&src_exe), &dst.join(&dst_exe));
}

dist::maybe_install_llvm_dylib(builder, target_compiler.host, &sysroot);

// Link the compiler binary itself into place
Expand Down
19 changes: 15 additions & 4 deletions src/bootstrap/dist.rs
Expand Up @@ -2124,6 +2124,10 @@ 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<'_>,
Expand All @@ -2132,13 +2136,19 @@ pub fn maybe_install_llvm_dylib(builder: &Builder<'_>,
let src_libdir = builder
.llvm_out(target)
.join("lib");
let dst_libdir = sysroot.join("lib/rustlib").join(&*target).join("lib");
t!(fs::create_dir_all(&dst_libdir));
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_libdir, 0o644);
builder.install(&llvm_dylib_path, &dst_libdir1, 0o644);
builder.install(&llvm_dylib_path, &dst_libdir2, 0o644);
}
return
}
Expand All @@ -2154,7 +2164,8 @@ pub fn maybe_install_llvm_dylib(builder: &Builder<'_>,
});


builder.install(&llvm_dylib_path, &dst_libdir, 0o644);
builder.install(&llvm_dylib_path, &dst_libdir1, 0o644);
builder.install(&llvm_dylib_path, &dst_libdir2, 0o644);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/doc.rs
Expand Up @@ -433,7 +433,7 @@ impl Step for Std {
builder.info(&format!("Documenting stage{} std ({})", stage, target));
let out = builder.doc_out(target);
t!(fs::create_dir_all(&out));
let compiler = builder.compiler_for(stage, builder.config.build, target);
let compiler = builder.compiler(stage, builder.config.build);

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

0 comments on commit 91b25a8

Please sign in to comment.