Skip to content

Commit

Permalink
bootstrap: do not rely on LIBRARY_PATH env variable
Browse files Browse the repository at this point in the history
Clang will not respect this value in cross configurations.
  • Loading branch information
rhelmot committed Jan 13, 2025
1 parent e7ad3ae commit 7f743c7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 34 deletions.
14 changes: 10 additions & 4 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ use crate::core::config::flags::{Subcommand, get_completion};
use crate::utils::build_stamp::{self, BuildStamp};
use crate::utils::exec::{BootstrapCommand, command};
use crate::utils::helpers::{
self, LldThreads, add_link_lib_path, add_rustdoc_cargo_linker_args, dylib_path, dylib_path_var,
linker_args, linker_flags, t, target_supports_cranelift_backend, up_to_date,
self, LldThreads, add_rustdoc_cargo_linker_args, dylib_path, dylib_path_var, linker_args,
linker_flags, t, target_supports_cranelift_backend, up_to_date,
};
use crate::utils::render_tests::{add_flags_and_try_run_tests, try_run_tests};
use crate::{CLang, DocTests, GitRepo, Mode, PathSet, envify};
Expand Down Expand Up @@ -1975,11 +1975,17 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
// Tests that use compiler libraries may inherit the `-lLLVM` link
// requirement, but the `-L` library path is not propagated across
// separate compilations. We can add LLVM's library path to the
// platform-specific environment variable as a workaround.
// rustc args as a workaround.
if !builder.config.dry_run() && suite.ends_with("fulldeps") {
let llvm_libdir =
command(&llvm_config).arg("--libdir").run_capture_stdout(builder).stdout();
add_link_lib_path(vec![llvm_libdir.trim().into()], &mut cmd);
let mut rustflags = env::var("RUSTFLAGS").unwrap_or_default();
if target.is_msvc() {
rustflags.push_str(&format!("-Clink-arg=-LIBPATH:{llvm_libdir}"));
} else {
rustflags.push_str(&format!("-Clink-arg=-L{llvm_libdir}"));
}
cmd.env("RUSTFLAGS", rustflags);
}

if !builder.config.dry_run() && matches!(mode, "run-make" | "coverage-run") {
Expand Down
12 changes: 7 additions & 5 deletions src/bootstrap/src/core/builder/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ use crate::core::build_steps::{compile, test};
use crate::core::config::SplitDebuginfo;
use crate::core::config::flags::Color;
use crate::utils::build_stamp;
use crate::utils::helpers::{
self, LldThreads, add_link_lib_path, check_cfg_arg, linker_args, linker_flags,
};
use crate::utils::helpers::{self, LldThreads, check_cfg_arg, linker_args, linker_flags};
use crate::{
BootstrapCommand, CLang, Compiler, DocTests, DryRun, EXTRA_CHECK_CFGS, GitRepo, Mode,
TargetSelection, command, prepare_behaviour_dump_dir, t,
Expand Down Expand Up @@ -947,12 +945,16 @@ impl Builder<'_> {
// 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.
// rustc args as a workaround.
if mode == Mode::ToolRustc || mode == Mode::Codegen {
if let Some(llvm_config) = self.llvm_config(target) {
let llvm_libdir =
command(llvm_config).arg("--libdir").run_capture_stdout(self).stdout();
add_link_lib_path(vec![llvm_libdir.trim().into()], &mut cargo);
if target.is_msvc() {
rustflags.arg(&format!("-Clink-arg=-LIBPATH:{llvm_libdir}"));
} else {
rustflags.arg(&format!("-Clink-arg=-L{llvm_libdir}"));
}
}
}

Expand Down
25 changes: 0 additions & 25 deletions src/bootstrap/src/utils/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,31 +106,6 @@ pub fn add_dylib_path(path: Vec<PathBuf>, cmd: &mut BootstrapCommand) {
cmd.env(dylib_path_var(), t!(env::join_paths(list)));
}

/// Adds a list of lookup paths to `cmd`'s link library lookup path.
pub fn add_link_lib_path(path: Vec<PathBuf>, cmd: &mut BootstrapCommand) {
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()
}

pub struct TimeIt(bool, Instant);

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

0 comments on commit 7f743c7

Please sign in to comment.