From 48f205d496213ac64e7596b1e3e3807b28833e14 Mon Sep 17 00:00:00 2001 From: Petr Hosek Date: Sun, 9 Jun 2019 16:28:25 -0700 Subject: [PATCH] Pass LLVM linker flags to librustc_llvm build 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. --- src/bootstrap/compile.rs | 4 ++++ src/librustc_llvm/build.rs | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index c7fa8e788b573..576267e6948f5 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -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 && diff --git a/src/librustc_llvm/build.rs b/src/librustc_llvm/build.rs index 7fa83dd977950..21fa872c8dadb 100644 --- a/src/librustc_llvm/build.rs +++ b/src/librustc_llvm/build.rs @@ -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");