Skip to content

Commit

Permalink
Pass LLVM linker flags to librustc_llvm build
Browse files Browse the repository at this point in the history
Some -L and -l flags may be needed even when building librustc_llvm,
for example when using static libc++ on Linux we may need to manually
specify the library search path and -ldl -lpthread as additional link
dependencies. We pass LLVM linker flags from config to librustc_llvm
build to make sure these cases are handled.
  • Loading branch information
petrhosek committed Jun 11, 2019
1 parent 8b36867 commit 48f205d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,10 @@ pub fn build_codegen_backend(builder: &Builder<'_>,
cargo.env("CFG_LLVM_ROOT", s);
}
}
// Some LLVM linker flags (-L and -l) may be needed to link librustc_llvm.
if let Some(ref s) = builder.config.llvm_ldflags {
cargo.env("LLVM_LINKER_FLAGS", s);
}
// Building with a static libstdc++ is only supported on linux right now,
// not for MSVC or macOS
if builder.config.llvm_static_stdcpp &&
Expand Down
15 changes: 15 additions & 0 deletions src/librustc_llvm/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,21 @@ fn main() {
}
}

// Some LLVM linker flags (-L and -l) may be needed even when linking
// librustc_llvm, for example when using static libc++, we may need to
// manually specify the library search path and -ldl -lpthread as link
// dependencies.
let llvm_linker_flags = env::var_os("LLVM_LINKER_FLAGS");
if let Some(s) = llvm_linker_flags {
for lib in s.into_string().unwrap().split_whitespace() {
if lib.starts_with("-l") {
println!("cargo:rustc-link-lib={}", &lib[2..]);
} else if lib.starts_with("-L") {
println!("cargo:rustc-link-search=native={}", &lib[2..]);
}
}
}

let llvm_static_stdcpp = env::var_os("LLVM_STATIC_STDCPP");
let llvm_use_libcxx = env::var_os("LLVM_USE_LIBCXX");

Expand Down

0 comments on commit 48f205d

Please sign in to comment.