Skip to content

Commit

Permalink
Do not link LLVM tools to LLVM dylib unless rustc is
Browse files Browse the repository at this point in the history
Previously we would have some platforms where LLVM was linked to rustc
statically, but to the LLVM tools dynamically. That meant we were distributing
two copies of LLVM: one as a separate dylib and one statically linked in to
librustc_driver.
  • Loading branch information
Mark-Simulacrum committed Sep 19, 2020
1 parent 8e9d5db commit 389b7ff
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
13 changes: 5 additions & 8 deletions src/bootstrap/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2401,14 +2401,11 @@ fn maybe_install_llvm(builder: &Builder<'_>, target: TargetSelection, dst_libdir
return;
}

// On macOS for some reason the llvm-config binary behaves differently and
// and fails on missing .a files if run without --link-shared. If run with
// that option, it still fails, but because we only ship a libLLVM.dylib
// rather than libLLVM-11-rust-....dylib file.
//
// For now just don't use llvm-config here on macOS; that will fail to
// support CI-built LLVM, but until we work out the different behavior that
// is fine as it is off by default.
// On macOS, rustc (and LLVM tools) link to an unversioned libLLVM.dylib
// instead of libLLVM-11-rust-....dylib, as on linux. It's not entirely
// clear why this is the case, though. llvm-config will emit the versioned
// paths and we don't want those in the sysroot (as we're expecting
// unversioned paths).
if target.contains("apple-darwin") {
let src_libdir = builder.llvm_out(target).join("lib");
let llvm_dylib_path = src_libdir.join("libLLVM.dylib");
Expand Down
11 changes: 8 additions & 3 deletions src/bootstrap/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,10 @@ impl Step for Llvm {
Err(m) => m,
};

if builder.config.llvm_link_shared && target.contains("windows") {
panic!("shared linking to LLVM is not currently supported on Windows");
if builder.config.llvm_link_shared
&& (target.contains("windows") || target.contains("apple-darwin"))
{
panic!("shared linking to LLVM is not currently supported on {}", target.triple);
}

builder.info(&format!("Building LLVM for {}", target));
Expand Down Expand Up @@ -209,7 +211,10 @@ impl Step for Llvm {
// which saves both memory during parallel links and overall disk space
// for the tools. We don't do this on every platform as it doesn't work
// equally well everywhere.
if builder.llvm_link_tools_dynamically(target) {
//
// If we're not linking rustc to a dynamic LLVM, though, then don't link
// tools to it.
if builder.llvm_link_tools_dynamically(target) && builder.config.llvm_link_shared {
cfg.define("LLVM_LINK_LLVM_DYLIB", "ON");
}

Expand Down
7 changes: 0 additions & 7 deletions src/ci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,6 @@ if [ "$DEPLOY$DEPLOY_ALT" = "1" ]; then
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.remap-debuginfo"
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --debuginfo-level-std=1"

# If we're distributing binaries, we want a shared LLVM link. We're already
# going to link LLVM to the LLVM tools dynamically, so we need to ship a
# libLLVM library anyway.
if !isWindows; then
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set llvm.link-shared=true"
fi

if [ "$NO_LLVM_ASSERTIONS" = "1" ]; then
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --disable-llvm-assertions"
elif [ "$DEPLOY_ALT" != "" ]; then
Expand Down

0 comments on commit 389b7ff

Please sign in to comment.