diff --git a/src/compiler/c.rs b/src/compiler/c.rs index 134bfb38e..8e390216c 100644 --- a/src/compiler/c.rs +++ b/src/compiler/c.rs @@ -299,6 +299,7 @@ impl Compiler for CCompiler { #[cfg(feature = "dist-client")] fn get_toolchain_packager(&self) -> Box { Box::new(CToolchainPackager { + env_vars: vec![], executable: self.executable.clone(), kind: self.compiler.kind(), }) @@ -1190,6 +1191,7 @@ impl Compilation for CCompilation preprocessed_input, executable, compiler, + env_vars, .. } = *self; trace!("Dist inputs: {:?}", parsed_args.input); @@ -1203,6 +1205,7 @@ impl Compilation for CCompilation extra_hash_files: parsed_args.extra_hash_files, }); let toolchain_packager = Box::new(CToolchainPackager { + env_vars, executable, kind: compiler.kind(), }); @@ -1299,6 +1302,7 @@ impl pkg::InputsPackager for CInputsPackager { #[cfg(feature = "dist-client")] #[allow(unused)] struct CToolchainPackager { + env_vars: Vec<(OsString, OsString)>, executable: PathBuf, kind: CCompilerKind, } @@ -1315,7 +1319,7 @@ impl pkg::ToolchainPackager for CToolchainPackager { debug!("Generating toolchain {}", self.executable.display()); let mut package_builder = pkg::ToolchainPackageBuilder::new(); package_builder.add_common()?; - package_builder.add_executable_and_deps(self.executable.clone())?; + package_builder.add_executable_and_deps(&self.env_vars, self.executable.clone())?; // Helper to use -print-file-name and -print-prog-name to look up // files by path. @@ -1356,7 +1360,7 @@ impl pkg::ToolchainPackager for CToolchainPackager { let add_named_prog = |builder: &mut pkg::ToolchainPackageBuilder, name: &str| -> Result<()> { if let Some(path) = named_file("prog", name) { - builder.add_executable_and_deps(path)?; + builder.add_executable_and_deps(&self.env_vars, path)?; } Ok(()) }; diff --git a/src/compiler/rust.rs b/src/compiler/rust.rs index 6c0a33755..b9869c944 100644 --- a/src/compiler/rust.rs +++ b/src/compiler/rust.rs @@ -2130,7 +2130,7 @@ impl pkg::ToolchainPackager for RustToolchainPackager { let bins_path = sysroot.join(BINS_DIR); let sysroot_executable = bins_path.join("rustc").with_extension(EXE_EXTENSION); - package_builder.add_executable_and_deps(sysroot_executable)?; + package_builder.add_executable_and_deps(&[], sysroot_executable)?; package_builder.add_dir_contents(&bins_path)?; if BINS_DIR != LIBS_DIR { diff --git a/src/dist/pkg.rs b/src/dist/pkg.rs index 2e6670443..355479c54 100644 --- a/src/dist/pkg.rs +++ b/src/dist/pkg.rs @@ -66,6 +66,7 @@ mod toolchain_imp { use super::SimplifyPath; use fs_err as fs; use std::collections::BTreeMap; + use std::ffi::OsString; use std::io::{Read, Write}; use std::path::{Component, Path, PathBuf}; use std::process; @@ -97,7 +98,11 @@ mod toolchain_imp { self.add_dir(PathBuf::from("/tmp")) } - pub fn add_executable_and_deps(&mut self, executable: PathBuf) -> Result<()> { + pub fn add_executable_and_deps( + &mut self, + env_vars: &[(OsString, OsString)], + executable: PathBuf, + ) -> Result<()> { let mut remaining = vec![executable]; while let Some(obj_path) = remaining.pop() { assert!(obj_path.is_absolute()); @@ -110,10 +115,11 @@ mod toolchain_imp { if self.file_set.contains_key(&tar_path) { continue; } - let ldd_libraries = find_ldd_libraries(&obj_path).with_context(|| { + let ldd_libraries = find_ldd_libraries(env_vars, &obj_path).with_context(|| { format!("Failed to analyse {} with ldd", obj_path.display()) })?; remaining.extend(ldd_libraries); + trace!("add_executable_and_deps {}", obj_path.display()); self.file_set.insert(tar_path, obj_path); } Ok(()) @@ -135,6 +141,7 @@ mod toolchain_imp { { return Ok(()); } + trace!("add_dir {}", dir_path.display()); let tar_path = self.tarify_path(&dir_path)?; self.dir_set.insert(tar_path, dir_path); Ok(()) @@ -148,6 +155,7 @@ mod toolchain_imp { file_path.to_string_lossy() )) } + trace!("add_file {}", file_path.display()); let tar_path = self.tarify_path(&file_path)?; self.file_set.insert(tar_path, file_path); Ok(()) @@ -252,12 +260,18 @@ mod toolchain_imp { // - static + non-PIE = ET_EXEC, ldd stderrs something like "\tnot a dynamic executable" or // "ldd: a.out: Not a valid dynamic program" and exits with code 1 // - fn find_ldd_libraries(executable: &Path) -> Result> { + fn find_ldd_libraries( + env_vars: &[(OsString, OsString)], + executable: &Path, + ) -> Result> { let process::Output { status, stdout, stderr, - } = process::Command::new("ldd").arg(executable).output()?; + } = process::Command::new("ldd") + .envs(env_vars.to_vec()) + .arg(executable) + .output()?; // Not a file ldd can handle. This can be a non-executable, or a static non-PIE if !status.success() {