From 8a1aa0520c27e7d3efe766028bda7f6608162c10 Mon Sep 17 00:00:00 2001
From: Jesus Checa Hidalgo <jchecahi@redhat.com>
Date: Wed, 7 May 2025 15:57:08 +0200
Subject: [PATCH] Fix broken-pipe-no-ice run-make test for rpath-less builds
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

tests/run-make/broken-pipe-no-ice currently fails to run when rpath is disabled
in bootstrap config, as the rustc and rustdoc binaries invoked cannot find the
required shared libs (librustc_driver.so).

This commit manually sets the dylib search path for both commands. The logic
mirrors what's implemented in run_make_support::util::set_host_compiler_dylib_path,
ensuring that the host compiler’s shared libraries are available at runtime even
when rpath is disabled.

This is necessary because the test manually constructs the rustc/rustdoc Command
instances instead of using the run_make_support wrappers, and would otherwise lack
the dynamic linker environment setup.

Fixes part of #140738
---
 tests/run-make/broken-pipe-no-ice/rmake.rs | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/tests/run-make/broken-pipe-no-ice/rmake.rs b/tests/run-make/broken-pipe-no-ice/rmake.rs
index 0521b3950207d..6d2d2dd13cf93 100644
--- a/tests/run-make/broken-pipe-no-ice/rmake.rs
+++ b/tests/run-make/broken-pipe-no-ice/rmake.rs
@@ -12,6 +12,7 @@
 // strange.
 
 use std::io::Read;
+use std::path::PathBuf;
 use std::process::{Command, Stdio};
 
 use run_make_support::env_var;
@@ -67,11 +68,21 @@ fn check_broken_pipe_handled_gracefully(bin: Binary, mut cmd: Command) {
 }
 
 fn main() {
+    // We need to set the runtime libs for rpath-less rustc. This mirrors the logic
+    // in run-make-support::util::set_host_compiler_dylib_path
+    let ld_lib_path_envvar = env_var("LD_LIB_PATH_ENVVAR");
+    let mut paths =
+        vec![std::env::current_dir().unwrap(), PathBuf::from(env_var("HOST_RUSTC_DYLIB_PATH"))];
+    paths.extend(std::env::split_paths(&env_var(&ld_lib_path_envvar)));
+    let ld_path = std::env::join_paths(paths.iter()).unwrap();
+
     let mut rustc = Command::new(env_var("RUSTC"));
     rustc.arg("--print=sysroot");
+    rustc.env(&ld_lib_path_envvar, ld_path.clone());
     check_broken_pipe_handled_gracefully(Binary::Rustc, rustc);
 
     let mut rustdoc = Command::new(env_var("RUSTDOC"));
     rustdoc.arg("--version");
+    rustdoc.env(&ld_lib_path_envvar, ld_path.clone());
     check_broken_pipe_handled_gracefully(Binary::Rustdoc, rustdoc);
 }