Skip to content

Commit babebdb

Browse files
authored
Unrolled build for rust-lang#123763
Rollup merge of rust-lang#123763 - cuviper:host-rpath-run-make-v2, r=jieyouxu Set the host library path in run-make v2 When the build is configured with `[rust] rpath = false`, we need to set `LD_LIBRARY_PATH` (or equivalent) to what would have been the `RPATH`, so the compiler can find its own libraries. The old `tools.mk` code has this environment prefixed in the `$(BARE_RUSTC)` variable, so we just need to wire up something similar for run-make v2. This is now set while building each `rmake.rs` itself, as well as in the `rust-make-support` helpers for `rustc` and `rustdoc` commands. This is also available in a `set_host_rpath` function for manual commands, like in the `compiler-builtins` test.
2 parents 46961d2 + 7e171c7 commit babebdb

File tree

5 files changed

+43
-20
lines changed

5 files changed

+43
-20
lines changed

src/tools/compiletest/src/runtest.rs

+17-12
Original file line numberDiff line numberDiff line change
@@ -3785,6 +3785,14 @@ impl<'test> TestCx<'test> {
37853785
debug!(?support_lib_deps);
37863786
debug!(?support_lib_deps_deps);
37873787

3788+
let orig_dylib_env_paths =
3789+
Vec::from_iter(env::split_paths(&env::var(dylib_env_var()).unwrap()));
3790+
3791+
let mut host_dylib_env_paths = Vec::new();
3792+
host_dylib_env_paths.push(cwd.join(&self.config.compile_lib_path));
3793+
host_dylib_env_paths.extend(orig_dylib_env_paths.iter().cloned());
3794+
let host_dylib_env_paths = env::join_paths(host_dylib_env_paths).unwrap();
3795+
37883796
let mut cmd = Command::new(&self.config.rustc_path);
37893797
cmd.arg("-o")
37903798
.arg(&recipe_bin)
@@ -3801,6 +3809,7 @@ impl<'test> TestCx<'test> {
38013809
.env("RUSTC", cwd.join(&self.config.rustc_path))
38023810
.env("TMPDIR", &tmpdir)
38033811
.env("LD_LIB_PATH_ENVVAR", dylib_env_var())
3812+
.env(dylib_env_var(), &host_dylib_env_paths)
38043813
.env("HOST_RPATH_DIR", cwd.join(&self.config.compile_lib_path))
38053814
.env("TARGET_RPATH_DIR", cwd.join(&self.config.run_lib_path))
38063815
.env("LLVM_COMPONENTS", &self.config.llvm_components)
@@ -3828,19 +3837,15 @@ impl<'test> TestCx<'test> {
38283837
// Finally, we need to run the recipe binary to build and run the actual tests.
38293838
debug!(?recipe_bin);
38303839

3831-
let mut dylib_env_paths = String::new();
3832-
dylib_env_paths.push_str(&env::var(dylib_env_var()).unwrap());
3833-
dylib_env_paths.push(':');
3834-
dylib_env_paths.push_str(&support_lib_path.parent().unwrap().to_string_lossy());
3835-
dylib_env_paths.push(':');
3836-
dylib_env_paths.push_str(
3837-
&stage_std_path.join("rustlib").join(&self.config.host).join("lib").to_string_lossy(),
3838-
);
3840+
let mut dylib_env_paths = orig_dylib_env_paths.clone();
3841+
dylib_env_paths.push(support_lib_path.parent().unwrap().to_path_buf());
3842+
dylib_env_paths.push(stage_std_path.join("rustlib").join(&self.config.host).join("lib"));
3843+
let dylib_env_paths = env::join_paths(dylib_env_paths).unwrap();
38393844

3840-
let mut target_rpath_env_path = String::new();
3841-
target_rpath_env_path.push_str(&tmpdir.to_string_lossy());
3842-
target_rpath_env_path.push(':');
3843-
target_rpath_env_path.push_str(&dylib_env_paths);
3845+
let mut target_rpath_env_path = Vec::new();
3846+
target_rpath_env_path.push(&tmpdir);
3847+
target_rpath_env_path.extend(&orig_dylib_env_paths);
3848+
let target_rpath_env_path = env::join_paths(target_rpath_env_path).unwrap();
38443849

38453850
let mut cmd = Command::new(&recipe_bin);
38463851
cmd.current_dir(&self.testpaths.file)

src/tools/run-make-support/src/lib.rs

+14
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,17 @@ fn handle_failed_output(cmd: &str, output: Output, caller_line_number: u32) -> !
115115
eprintln!("=== STDERR ===\n{}\n\n", String::from_utf8(output.stderr).unwrap());
116116
std::process::exit(1)
117117
}
118+
119+
/// Set the runtime library path as needed for running the host rustc/rustdoc/etc.
120+
pub fn set_host_rpath(cmd: &mut Command) {
121+
let ld_lib_path_envvar = env::var("LD_LIB_PATH_ENVVAR").unwrap();
122+
cmd.env(&ld_lib_path_envvar, {
123+
let mut paths = vec![];
124+
paths.push(PathBuf::from(env::var("TMPDIR").unwrap()));
125+
paths.push(PathBuf::from(env::var("HOST_RPATH_DIR").unwrap()));
126+
for p in env::split_paths(&env::var(&ld_lib_path_envvar).unwrap()) {
127+
paths.push(p.to_path_buf());
128+
}
129+
env::join_paths(paths.iter()).unwrap()
130+
});
131+
}

src/tools/run-make-support/src/rustc.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::ffi::{OsStr, OsString};
33
use std::path::Path;
44
use std::process::{Command, Output};
55

6-
use crate::{handle_failed_output, tmp_dir};
6+
use crate::{handle_failed_output, set_host_rpath, tmp_dir};
77

88
/// Construct a new `rustc` invocation.
99
pub fn rustc() -> Rustc {
@@ -24,6 +24,7 @@ pub struct Rustc {
2424
fn setup_common() -> Command {
2525
let rustc = env::var("RUSTC").unwrap();
2626
let mut cmd = Command::new(rustc);
27+
set_host_rpath(&mut cmd);
2728
cmd.arg("--out-dir").arg(tmp_dir()).arg("-L").arg(tmp_dir());
2829
cmd
2930
}

src/tools/run-make-support/src/rustdoc.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::ffi::OsStr;
33
use std::path::Path;
44
use std::process::{Command, Output};
55

6-
use crate::handle_failed_output;
6+
use crate::{handle_failed_output, set_host_rpath};
77

88
/// Construct a plain `rustdoc` invocation with no flags set.
99
pub fn bare_rustdoc() -> Rustdoc {
@@ -22,7 +22,9 @@ pub struct Rustdoc {
2222

2323
fn setup_common() -> Command {
2424
let rustdoc = env::var("RUSTDOC").unwrap();
25-
Command::new(rustdoc)
25+
let mut cmd = Command::new(rustdoc);
26+
set_host_rpath(&mut cmd);
27+
cmd
2628
}
2729

2830
impl Rustdoc {

tests/run-make/compiler-builtins/rmake.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use run_make_support::object::read::Object;
2222
use run_make_support::object::ObjectSection;
2323
use run_make_support::object::ObjectSymbol;
2424
use run_make_support::object::RelocationTarget;
25+
use run_make_support::set_host_rpath;
2526
use run_make_support::tmp_dir;
2627
use std::collections::HashSet;
2728

@@ -48,8 +49,8 @@ fn main() {
4849
let path = std::env::var("PATH").unwrap();
4950
let rustc = std::env::var("RUSTC").unwrap();
5051
let bootstrap_cargo = std::env::var("BOOTSTRAP_CARGO").unwrap();
51-
let status = std::process::Command::new(bootstrap_cargo)
52-
.args([
52+
let mut cmd = std::process::Command::new(bootstrap_cargo);
53+
cmd.args([
5354
"build",
5455
"--manifest-path",
5556
manifest_path.to_str().unwrap(),
@@ -62,10 +63,10 @@ fn main() {
6263
.env("RUSTC", rustc)
6364
.env("RUSTFLAGS", "-Copt-level=0 -Cdebug-assertions=yes")
6465
.env("CARGO_TARGET_DIR", &target_dir)
65-
.env("RUSTC_BOOTSTRAP", "1")
66-
.status()
67-
.unwrap();
66+
.env("RUSTC_BOOTSTRAP", "1");
67+
set_host_rpath(&mut cmd);
6868

69+
let status = cmd.status().unwrap();
6970
assert!(status.success());
7071

7172
let rlibs_path = target_dir.join(target).join("debug").join("deps");

0 commit comments

Comments
 (0)