Ensure LLVM is in the link path for rustc tools
This commit is contained in:
parent
71f5aed385
commit
0536b8dcaa
@ -11,7 +11,7 @@ use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use build_helper::t;
|
||||
use build_helper::{output, t};
|
||||
|
||||
use crate::cache::{Cache, Interned, INTERNER};
|
||||
use crate::check;
|
||||
@ -23,7 +23,7 @@ use crate::install;
|
||||
use crate::native;
|
||||
use crate::test;
|
||||
use crate::tool;
|
||||
use crate::util::{self, add_dylib_path, exe, libdir};
|
||||
use crate::util::{self, add_dylib_path, add_link_lib_path, exe, libdir};
|
||||
use crate::{Build, DocTests, GitRepo, Mode};
|
||||
|
||||
pub use crate::Compiler;
|
||||
@ -1034,6 +1034,20 @@ impl<'a> Builder<'a> {
|
||||
.env("RUSTC_SNAPSHOT_LIBDIR", self.rustc_libdir(compiler));
|
||||
}
|
||||
|
||||
// Tools that use compiler libraries may inherit the `-lLLVM` link
|
||||
// requirement, but the `-L` library path is not propagated across
|
||||
// separate Cargo projects. We can add LLVM's library path to the
|
||||
// platform-specific environment variable as a workaround.
|
||||
//
|
||||
// Note that this is disabled if LLVM itself is disabled or we're in a
|
||||
// check build, where if we're in a check build there's no need to build
|
||||
// all of LLVM and such.
|
||||
if self.config.llvm_enabled() && self.kind != Kind::Check && mode == Mode::ToolRustc {
|
||||
let llvm_config = self.ensure(native::Llvm { target });
|
||||
let llvm_libdir = output(Command::new(&llvm_config).arg("--libdir"));
|
||||
add_link_lib_path(vec![llvm_libdir.trim().into()], &mut cargo);
|
||||
}
|
||||
|
||||
if self.config.incremental {
|
||||
cargo.env("CARGO_INCREMENTAL", "1");
|
||||
} else {
|
||||
|
@ -72,6 +72,31 @@ pub fn dylib_path() -> Vec<PathBuf> {
|
||||
env::split_paths(&var).collect()
|
||||
}
|
||||
|
||||
/// Adds a list of lookup paths to `cmd`'s link library lookup path.
|
||||
pub fn add_link_lib_path(path: Vec<PathBuf>, cmd: &mut Command) {
|
||||
let mut list = link_lib_path();
|
||||
for path in path {
|
||||
list.insert(0, path);
|
||||
}
|
||||
cmd.env(link_lib_path_var(), t!(env::join_paths(list)));
|
||||
}
|
||||
|
||||
/// Returns the environment variable which the link library lookup path
|
||||
/// resides in for this platform.
|
||||
fn link_lib_path_var() -> &'static str {
|
||||
if cfg!(target_env = "msvc") { "LIB" } else { "LIBRARY_PATH" }
|
||||
}
|
||||
|
||||
/// Parses the `link_lib_path_var()` environment variable, returning a list of
|
||||
/// paths that are members of this lookup path.
|
||||
fn link_lib_path() -> Vec<PathBuf> {
|
||||
let var = match env::var_os(link_lib_path_var()) {
|
||||
Some(v) => v,
|
||||
None => return vec![],
|
||||
};
|
||||
env::split_paths(&var).collect()
|
||||
}
|
||||
|
||||
/// `push` all components to `buf`. On windows, append `.exe` to the last component.
|
||||
pub fn push_exe_path(mut buf: PathBuf, components: &[&str]) -> PathBuf {
|
||||
let (&file, components) = components.split_last().expect("at least one component required");
|
||||
|
Loading…
x
Reference in New Issue
Block a user