|
|
a094b5 |
commit 9423c4f0dda638ec2a925140850b85e8d3e6d455 (from bee074f032970fd1b59650c04a70e75eeee9c63b)
|
|
|
a094b5 |
Merge: bee074f03297 3a2a4429a288
|
|
|
a094b5 |
Author: Mazdak Farrokhzad <twingoow@gmail.com>
|
|
|
a094b5 |
Date: Mon Mar 23 10:29:13 2020 +0100
|
|
|
a094b5 |
|
|
|
a094b5 |
Rollup merge of #70123 - cuviper:library-path, r=Mark-Simulacrum
|
|
|
a094b5 |
|
|
|
a094b5 |
Ensure LLVM is in the link path for rustc tools
|
|
|
a094b5 |
|
|
|
a094b5 |
The build script for `rustc_llvm` outputs LLVM information in `cargo:rustc-link-lib` and `cargo:rustc-link-search` so the compiler can be linked correctly. However, while the lib is carried along in metadata, the search paths are not. So when cargo is invoked again later for rustc _tools_, they'll also try to link with LLVM, but the necessary paths may be left out.
|
|
|
a094b5 |
|
|
|
a094b5 |
Rustbuild can use the environment to set the LLVM link path for tools -- `LIB` for MSVC toolchains and `LIBRARY_PATH` for everyone else.
|
|
|
a094b5 |
|
|
|
a094b5 |
Fixes #68714.
|
|
|
a094b5 |
|
|
|
a094b5 |
diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs
|
|
|
a094b5 |
index 602e4511ea58..dd519506d42a 100644
|
|
|
a094b5 |
--- a/src/bootstrap/builder.rs
|
|
|
a094b5 |
+++ b/src/bootstrap/builder.rs
|
|
|
a094b5 |
@@ -11,7 +11,7 @@ use std::path::{Path, PathBuf};
|
|
|
a094b5 |
use std::process::Command;
|
|
|
a094b5 |
use std::time::{Duration, Instant};
|
|
|
a094b5 |
|
|
|
a094b5 |
-use build_helper::t;
|
|
|
a094b5 |
+use build_helper::{output, t};
|
|
|
a094b5 |
|
|
|
a094b5 |
use crate::cache::{Cache, Interned, INTERNER};
|
|
|
a094b5 |
use crate::check;
|
|
|
a094b5 |
@@ -23,7 +23,7 @@ use crate::install;
|
|
|
a094b5 |
use crate::native;
|
|
|
a094b5 |
use crate::test;
|
|
|
a094b5 |
use crate::tool;
|
|
|
a094b5 |
-use crate::util::{self, add_lib_path, exe, libdir};
|
|
|
a094b5 |
+use crate::util::{self, add_dylib_path, add_link_lib_path, exe, libdir};
|
|
|
a094b5 |
use crate::{Build, DocTests, GitRepo, Mode};
|
|
|
a094b5 |
|
|
|
a094b5 |
pub use crate::Compiler;
|
|
|
a094b5 |
@@ -660,7 +660,7 @@ impl<'a> Builder<'a> {
|
|
|
a094b5 |
return;
|
|
|
a094b5 |
}
|
|
|
a094b5 |
|
|
|
a094b5 |
- add_lib_path(vec![self.rustc_libdir(compiler)], &mut cmd.command);
|
|
|
a094b5 |
+ add_dylib_path(vec![self.rustc_libdir(compiler)], &mut cmd.command);
|
|
|
a094b5 |
}
|
|
|
a094b5 |
|
|
|
a094b5 |
/// Gets a path to the compiler specified.
|
|
|
a094b5 |
@@ -698,6 +698,20 @@ impl<'a> Builder<'a> {
|
|
|
a094b5 |
cmd
|
|
|
a094b5 |
}
|
|
|
a094b5 |
|
|
|
a094b5 |
+ /// Return the path to `llvm-config` for the target, if it exists.
|
|
|
a094b5 |
+ ///
|
|
|
a094b5 |
+ /// Note that this returns `None` if LLVM is disabled, or if we're in a
|
|
|
a094b5 |
+ /// check build or dry-run, where there's no need to build all of LLVM.
|
|
|
a094b5 |
+ fn llvm_config(&self, target: Interned<String>) -> Option<PathBuf> {
|
|
|
a094b5 |
+ if self.config.llvm_enabled() && self.kind != Kind::Check && !self.config.dry_run {
|
|
|
a094b5 |
+ let llvm_config = self.ensure(native::Llvm { target });
|
|
|
a094b5 |
+ if llvm_config.is_file() {
|
|
|
a094b5 |
+ return Some(llvm_config);
|
|
|
a094b5 |
+ }
|
|
|
a094b5 |
+ }
|
|
|
a094b5 |
+ None
|
|
|
a094b5 |
+ }
|
|
|
a094b5 |
+
|
|
|
a094b5 |
/// Prepares an invocation of `cargo` to be run.
|
|
|
a094b5 |
///
|
|
|
a094b5 |
/// This will create a `Command` that represents a pending execution of
|
|
|
a094b5 |
@@ -1034,6 +1048,17 @@ impl<'a> Builder<'a> {
|
|
|
a094b5 |
.env("RUSTC_SNAPSHOT_LIBDIR", self.rustc_libdir(compiler));
|
|
|
a094b5 |
}
|
|
|
a094b5 |
|
|
|
a094b5 |
+ // Tools that use compiler libraries may inherit the `-lLLVM` link
|
|
|
a094b5 |
+ // requirement, but the `-L` library path is not propagated across
|
|
|
a094b5 |
+ // separate Cargo projects. We can add LLVM's library path to the
|
|
|
a094b5 |
+ // platform-specific environment variable as a workaround.
|
|
|
a094b5 |
+ if mode == Mode::ToolRustc {
|
|
|
a094b5 |
+ if let Some(llvm_config) = self.llvm_config(target) {
|
|
|
a094b5 |
+ let llvm_libdir = output(Command::new(&llvm_config).arg("--libdir"));
|
|
|
a094b5 |
+ add_link_lib_path(vec![llvm_libdir.trim().into()], &mut cargo);
|
|
|
a094b5 |
+ }
|
|
|
a094b5 |
+ }
|
|
|
a094b5 |
+
|
|
|
a094b5 |
if self.config.incremental {
|
|
|
a094b5 |
cargo.env("CARGO_INCREMENTAL", "1");
|
|
|
a094b5 |
} else {
|
|
|
a094b5 |
diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs
|
|
|
a094b5 |
index 65a00db33949..ad494b88b3af 100644
|
|
|
a094b5 |
--- a/src/bootstrap/compile.rs
|
|
|
a094b5 |
+++ b/src/bootstrap/compile.rs
|
|
|
a094b5 |
@@ -451,44 +451,6 @@ impl Step for Rustc {
|
|
|
a094b5 |
false,
|
|
|
a094b5 |
);
|
|
|
a094b5 |
|
|
|
a094b5 |
- // We used to build librustc_codegen_llvm as a separate step,
|
|
|
a094b5 |
- // which produced a dylib that the compiler would dlopen() at runtime.
|
|
|
a094b5 |
- // This meant that we only needed to make sure that libLLVM.so was
|
|
|
a094b5 |
- // installed by the time we went to run a tool using it - since
|
|
|
a094b5 |
- // librustc_codegen_llvm was effectively a standalone artifact,
|
|
|
a094b5 |
- // other crates were completely oblivious to its dependency
|
|
|
a094b5 |
- // on `libLLVM.so` during build time.
|
|
|
a094b5 |
- //
|
|
|
a094b5 |
- // However, librustc_codegen_llvm is now built as an ordinary
|
|
|
a094b5 |
- // crate during the same step as the rest of the compiler crates.
|
|
|
a094b5 |
- // This means that any crates depending on it will see the fact
|
|
|
a094b5 |
- // that it uses `libLLVM.so` as a native library, and will
|
|
|
a094b5 |
- // cause us to pass `-llibLLVM.so` to the linker when we link
|
|
|
a094b5 |
- // a binary.
|
|
|
a094b5 |
- //
|
|
|
a094b5 |
- // For `rustc` itself, this works out fine.
|
|
|
a094b5 |
- // During the `Assemble` step, we call `dist::maybe_install_llvm_dylib`
|
|
|
a094b5 |
- // to copy libLLVM.so into the `stage` directory. We then link
|
|
|
a094b5 |
- // the compiler binary, which will find `libLLVM.so` in the correct place.
|
|
|
a094b5 |
- //
|
|
|
a094b5 |
- // However, this is insufficient for tools that are build against stage0
|
|
|
a094b5 |
- // (e.g. stage1 rustdoc). Since `Assemble` for stage0 doesn't actually do anything,
|
|
|
a094b5 |
- // we won't have `libLLVM.so` in the stage0 sysroot. In the past, this wasn't
|
|
|
a094b5 |
- // a problem - we would copy the tool binary into its correct stage directory
|
|
|
a094b5 |
- // (e.g. stage1 for a stage1 rustdoc built against a stage0 compiler).
|
|
|
a094b5 |
- // Since libLLVM.so wasn't resolved until runtime, it was fine for it to
|
|
|
a094b5 |
- // not exist while we were building it.
|
|
|
a094b5 |
- //
|
|
|
a094b5 |
- // To ensure that we can still build stage1 tools against a stage0 compiler,
|
|
|
a094b5 |
- // we explicitly copy libLLVM.so into the stage0 sysroot when building
|
|
|
a094b5 |
- // the stage0 compiler. This ensures that tools built against stage0
|
|
|
a094b5 |
- // will see libLLVM.so at build time, making the linker happy.
|
|
|
a094b5 |
- if compiler.stage == 0 {
|
|
|
a094b5 |
- builder.info(&format!("Installing libLLVM.so to stage 0 ({})", compiler.host));
|
|
|
a094b5 |
- let sysroot = builder.sysroot(compiler);
|
|
|
a094b5 |
- dist::maybe_install_llvm_dylib(builder, compiler.host, &sysroot);
|
|
|
a094b5 |
- }
|
|
|
a094b5 |
-
|
|
|
a094b5 |
builder.ensure(RustcLink {
|
|
|
a094b5 |
compiler: builder.compiler(compiler.stage, builder.config.build),
|
|
|
a094b5 |
target_compiler: compiler,
|
|
|
a094b5 |
diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs
|
|
|
a094b5 |
index 67e0ed5c5802..c8ccba467e50 100644
|
|
|
a094b5 |
--- a/src/bootstrap/tool.rs
|
|
|
a094b5 |
+++ b/src/bootstrap/tool.rs
|
|
|
a094b5 |
@@ -12,7 +12,7 @@ use crate::channel;
|
|
|
a094b5 |
use crate::channel::GitInfo;
|
|
|
a094b5 |
use crate::compile;
|
|
|
a094b5 |
use crate::toolstate::ToolState;
|
|
|
a094b5 |
-use crate::util::{add_lib_path, exe, CiEnv};
|
|
|
a094b5 |
+use crate::util::{add_dylib_path, exe, CiEnv};
|
|
|
a094b5 |
use crate::Compiler;
|
|
|
a094b5 |
use crate::Mode;
|
|
|
a094b5 |
|
|
|
a094b5 |
@@ -388,7 +388,7 @@ pub struct ErrorIndex {
|
|
|
a094b5 |
impl ErrorIndex {
|
|
|
a094b5 |
pub fn command(builder: &Builder<'_>, compiler: Compiler) -> Command {
|
|
|
a094b5 |
let mut cmd = Command::new(builder.ensure(ErrorIndex { compiler }));
|
|
|
a094b5 |
- add_lib_path(
|
|
|
a094b5 |
+ add_dylib_path(
|
|
|
a094b5 |
vec![PathBuf::from(&builder.sysroot_libdir(compiler, compiler.host))],
|
|
|
a094b5 |
&mut cmd,
|
|
|
a094b5 |
);
|
|
|
a094b5 |
@@ -689,7 +689,7 @@ impl<'a> Builder<'a> {
|
|
|
a094b5 |
}
|
|
|
a094b5 |
}
|
|
|
a094b5 |
|
|
|
a094b5 |
- add_lib_path(lib_paths, &mut cmd);
|
|
|
a094b5 |
+ add_dylib_path(lib_paths, &mut cmd);
|
|
|
a094b5 |
cmd
|
|
|
a094b5 |
}
|
|
|
a094b5 |
}
|
|
|
a094b5 |
diff --git a/src/bootstrap/util.rs b/src/bootstrap/util.rs
|
|
|
a094b5 |
index eac790fe504b..2bc6f1939d97 100644
|
|
|
a094b5 |
--- a/src/bootstrap/util.rs
|
|
|
a094b5 |
+++ b/src/bootstrap/util.rs
|
|
|
a094b5 |
@@ -40,7 +40,7 @@ pub fn libdir(target: &str) -> &'static str {
|
|
|
a094b5 |
}
|
|
|
a094b5 |
|
|
|
a094b5 |
/// Adds a list of lookup paths to `cmd`'s dynamic library lookup path.
|
|
|
a094b5 |
-pub fn add_lib_path(path: Vec<PathBuf>, cmd: &mut Command) {
|
|
|
a094b5 |
+pub fn add_dylib_path(path: Vec<PathBuf>, cmd: &mut Command) {
|
|
|
a094b5 |
let mut list = dylib_path();
|
|
|
a094b5 |
for path in path {
|
|
|
a094b5 |
list.insert(0, path);
|
|
|
a094b5 |
@@ -72,6 +72,31 @@ pub fn dylib_path() -> Vec<PathBuf> {
|
|
|
a094b5 |
env::split_paths(&var).collect()
|
|
|
a094b5 |
}
|
|
|
a094b5 |
|
|
|
a094b5 |
+/// Adds a list of lookup paths to `cmd`'s link library lookup path.
|
|
|
a094b5 |
+pub fn add_link_lib_path(path: Vec<PathBuf>, cmd: &mut Command) {
|
|
|
a094b5 |
+ let mut list = link_lib_path();
|
|
|
a094b5 |
+ for path in path {
|
|
|
a094b5 |
+ list.insert(0, path);
|
|
|
a094b5 |
+ }
|
|
|
a094b5 |
+ cmd.env(link_lib_path_var(), t!(env::join_paths(list)));
|
|
|
a094b5 |
+}
|
|
|
a094b5 |
+
|
|
|
a094b5 |
+/// Returns the environment variable which the link library lookup path
|
|
|
a094b5 |
+/// resides in for this platform.
|
|
|
a094b5 |
+fn link_lib_path_var() -> &'static str {
|
|
|
a094b5 |
+ if cfg!(target_env = "msvc") { "LIB" } else { "LIBRARY_PATH" }
|
|
|
a094b5 |
+}
|
|
|
a094b5 |
+
|
|
|
a094b5 |
+/// Parses the `link_lib_path_var()` environment variable, returning a list of
|
|
|
a094b5 |
+/// paths that are members of this lookup path.
|
|
|
a094b5 |
+fn link_lib_path() -> Vec<PathBuf> {
|
|
|
a094b5 |
+ let var = match env::var_os(link_lib_path_var()) {
|
|
|
a094b5 |
+ Some(v) => v,
|
|
|
a094b5 |
+ None => return vec![],
|
|
|
a094b5 |
+ };
|
|
|
a094b5 |
+ env::split_paths(&var).collect()
|
|
|
a094b5 |
+}
|
|
|
a094b5 |
+
|
|
|
a094b5 |
/// `push` all components to `buf`. On windows, append `.exe` to the last component.
|
|
|
a094b5 |
pub fn push_exe_path(mut buf: PathBuf, components: &[&str]) -> PathBuf {
|
|
|
a094b5 |
let (&file, components) = components.split_last().expect("at least one component required");
|