From df7d78cde8c1a922831b71873d8fb3253b4f8aeb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fabian=20Gr=C3=BCnbichler?= Date: Thu, 20 Jun 2024 21:58:10 +0200 Subject: [PATCH] [PATCH] Set the host library path in run-make v2 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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. FG: Partial backport for 1.78 Signed-off-by: Fabian Grünbichler Forwarded: https://github.com/rust-lang/rust/pull/123763 Gbp-Pq: Topic upstream Gbp-Pq: Name u-set-the-host-library-path-in-run-make-v2.patch --- src/tools/compiletest/src/runtest.rs | 6 ++++++ src/tools/run-make-support/src/lib.rs | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 5321cdd66d..31a601ff77 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -3772,6 +3772,11 @@ impl<'test> TestCx<'test> { debug!(?support_lib_deps); debug!(?support_lib_deps_deps); + let mut host_dylib_env_paths = String::new(); + host_dylib_env_paths.push_str(&cwd.join(&self.config.compile_lib_path).to_string_lossy()); + host_dylib_env_paths.push(':'); + host_dylib_env_paths.push_str(&env::var(dylib_env_var()).unwrap()); + let res = self.cmd2procres( Command::new(&self.config.rustc_path) .arg("-o") @@ -3792,6 +3797,7 @@ impl<'test> TestCx<'test> { .env("RUSTC", cwd.join(&self.config.rustc_path)) .env("TMPDIR", &tmpdir) .env("LD_LIB_PATH_ENVVAR", dylib_env_var()) + .env(dylib_env_var(), &host_dylib_env_paths) .env("HOST_RPATH_DIR", cwd.join(&self.config.compile_lib_path)) .env("TARGET_RPATH_DIR", cwd.join(&self.config.run_lib_path)) .env("LLVM_COMPONENTS", &self.config.llvm_components) diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 674860f841..f10ea133e7 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -11,6 +11,7 @@ pub fn out_dir() -> PathBuf { fn setup_common_build_cmd() -> Command { let rustc = env::var("RUSTC").unwrap(); let mut cmd = Command::new(rustc); + set_host_rpath(&mut cmd); cmd.arg("--out-dir").arg(out_dir()).arg("-L").arg(out_dir()); cmd } @@ -24,6 +25,20 @@ fn handle_failed_output(cmd: &str, output: Output, caller_line_number: u32) -> ! std::process::exit(1) } +/// Set the runtime library path as needed for running the host rustc/rustdoc/etc. +pub fn set_host_rpath(cmd: &mut Command) { + let ld_lib_path_envvar = env::var("LD_LIB_PATH_ENVVAR").unwrap(); + cmd.env(&ld_lib_path_envvar, { + let mut paths = vec![]; + paths.push(PathBuf::from(env::var("TMPDIR").unwrap())); + paths.push(PathBuf::from(env::var("HOST_RPATH_DIR").unwrap())); + for p in env::split_paths(&env::var(&ld_lib_path_envvar).unwrap()) { + paths.push(p.to_path_buf()); + } + env::join_paths(paths.iter()).unwrap() + }); +} + pub fn rustc() -> RustcInvocationBuilder { RustcInvocationBuilder::new() } -- 2.30.2