Skip to content

Commit e5d68d8

Browse files
committed
bootstrap: do not rely on LIBRARY_PATH env variable
Clang will not respect this value in cross configurations.
1 parent 8cdc67e commit e5d68d8

File tree

3 files changed

+17
-34
lines changed

3 files changed

+17
-34
lines changed

src/bootstrap/src/core/build_steps/test.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ use crate::core::config::TargetSelection;
2323
use crate::core::config::flags::{Subcommand, get_completion};
2424
use crate::utils::exec::{BootstrapCommand, command};
2525
use crate::utils::helpers::{
26-
self, LldThreads, add_link_lib_path, add_rustdoc_cargo_linker_args, dylib_path, dylib_path_var,
27-
linker_args, linker_flags, t, target_supports_cranelift_backend, up_to_date,
26+
self, LldThreads, add_rustdoc_cargo_linker_args, dylib_path, dylib_path_var, linker_args,
27+
linker_flags, t, target_supports_cranelift_backend, up_to_date,
2828
};
2929
use crate::utils::render_tests::{add_flags_and_try_run_tests, try_run_tests};
3030
use crate::{CLang, DocTests, GitRepo, Mode, envify};
@@ -2006,11 +2006,17 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
20062006
// Tests that use compiler libraries may inherit the `-lLLVM` link
20072007
// requirement, but the `-L` library path is not propagated across
20082008
// separate compilations. We can add LLVM's library path to the
2009-
// platform-specific environment variable as a workaround.
2009+
// rustc args as a workaround.
20102010
if !builder.config.dry_run() && suite.ends_with("fulldeps") {
20112011
let llvm_libdir =
20122012
command(&llvm_config).arg("--libdir").run_capture_stdout(builder).stdout();
2013-
add_link_lib_path(vec![llvm_libdir.trim().into()], &mut cmd);
2013+
let mut rustflags = env::var("RUSTFLAGS").unwrap_or_default();
2014+
if target.is_msvc() {
2015+
rustflags.push_str(&format!("-Clink-arg=-LIBPATH:{llvm_libdir}"));
2016+
} else {
2017+
rustflags.push_str(&format!("-Clink-arg=-L{llvm_libdir}"));
2018+
}
2019+
cmd.env("RUSTFLAGS", rustflags);
20142020
}
20152021

20162022
if !builder.config.dry_run() && matches!(mode, "run-make" | "coverage-run") {

src/bootstrap/src/core/builder/cargo.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ use crate::core::build_steps::tool::SourceType;
77
use crate::core::build_steps::{compile, test};
88
use crate::core::config::SplitDebuginfo;
99
use crate::core::config::flags::Color;
10-
use crate::utils::helpers::{
11-
self, LldThreads, add_link_lib_path, check_cfg_arg, linker_args, linker_flags,
12-
};
10+
use crate::utils::helpers::{self, LldThreads, check_cfg_arg, linker_args, linker_flags};
1311
use crate::{
1412
BootstrapCommand, CLang, Compiler, DocTests, DryRun, EXTRA_CHECK_CFGS, GitRepo, Mode,
1513
TargetSelection, command, prepare_behaviour_dump_dir, t,
@@ -946,12 +944,16 @@ impl Builder<'_> {
946944
// Tools that use compiler libraries may inherit the `-lLLVM` link
947945
// requirement, but the `-L` library path is not propagated across
948946
// separate Cargo projects. We can add LLVM's library path to the
949-
// platform-specific environment variable as a workaround.
947+
// rustc args as a workaround.
950948
if mode == Mode::ToolRustc || mode == Mode::Codegen {
951949
if let Some(llvm_config) = self.llvm_config(target) {
952950
let llvm_libdir =
953951
command(llvm_config).arg("--libdir").run_capture_stdout(self).stdout();
954-
add_link_lib_path(vec![llvm_libdir.trim().into()], &mut cargo);
952+
if target.is_msvc() {
953+
rustflags.arg(&format!("-Clink-arg=-LIBPATH:{llvm_libdir}"));
954+
} else {
955+
rustflags.arg(&format!("-Clink-arg=-L{llvm_libdir}"));
956+
}
955957
}
956958
}
957959

src/bootstrap/src/utils/helpers.rs

-25
Original file line numberDiff line numberDiff line change
@@ -99,31 +99,6 @@ pub fn add_dylib_path(path: Vec<PathBuf>, cmd: &mut BootstrapCommand) {
9999
cmd.env(dylib_path_var(), t!(env::join_paths(list)));
100100
}
101101

102-
/// Adds a list of lookup paths to `cmd`'s link library lookup path.
103-
pub fn add_link_lib_path(path: Vec<PathBuf>, cmd: &mut BootstrapCommand) {
104-
let mut list = link_lib_path();
105-
for path in path {
106-
list.insert(0, path);
107-
}
108-
cmd.env(link_lib_path_var(), t!(env::join_paths(list)));
109-
}
110-
111-
/// Returns the environment variable which the link library lookup path
112-
/// resides in for this platform.
113-
fn link_lib_path_var() -> &'static str {
114-
if cfg!(target_env = "msvc") { "LIB" } else { "LIBRARY_PATH" }
115-
}
116-
117-
/// Parses the `link_lib_path_var()` environment variable, returning a list of
118-
/// paths that are members of this lookup path.
119-
fn link_lib_path() -> Vec<PathBuf> {
120-
let var = match env::var_os(link_lib_path_var()) {
121-
Some(v) => v,
122-
None => return vec![],
123-
};
124-
env::split_paths(&var).collect()
125-
}
126-
127102
pub struct TimeIt(bool, Instant);
128103

129104
/// Returns an RAII structure that prints out how long it took to drop.

0 commit comments

Comments
 (0)