1From c21cc756b69a5f33c8a7758b746a816f40f55932 Mon Sep 17 00:00:00 2001
2From: Leon Isenberg <ljli@users.noreply.github.com>
3Date: Sat, 28 Oct 2017 17:58:17 +0200
4Subject: [PATCH] nix customization: patchelf installed binaries
5
6---
7 src/rustup-dist/src/component/package.rs | 21 ++++++++++++++++++++-
8 1 file changed, 20 insertions(+), 1 deletion(-)
9
10diff --git a/src/rustup-dist/src/component/package.rs b/src/rustup-dist/src/component/package.rs
11index 70c54dcd..f0318986 100644
12--- a/src/rustup-dist/src/component/package.rs
13+++ b/src/rustup-dist/src/component/package.rs
14@@ -100,7 +100,10 @@ impl Package for DirectoryPackage {
15 let src_path = root.join(&path);
16
17 match &*part.0 {
18- "file" => builder.copy_file(path.clone(), &src_path)?,
19+ "file" => {
20+ builder.copy_file(path.clone(), &src_path)?;
21+ nix_patchelf_if_needed(&target.prefix().path().join(path.clone()), &src_path)
22+ }
23 "dir" => builder.copy_dir(path.clone(), &src_path)?,
24 _ => return Err(ErrorKind::CorruptComponent(name.to_owned()).into()),
25 }
26@@ -118,6 +121,22 @@ impl Package for DirectoryPackage {
27 }
28 }
29
30+fn nix_patchelf_if_needed(dest_path: &Path, src_path: &Path) {
31+ let is_bin = if let Some(p) = src_path.parent() {
32+ p.ends_with("bin")
33+ } else {
34+ false
35+ };
36+
37+ if is_bin {
38+ let _ = ::std::process::Command::new("@patchelf@/bin/patchelf")
39+ .arg("--set-interpreter")
40+ .arg("@dynamicLinker@")
41+ .arg(dest_path)
42+ .output();
43+ }
44+}
45+
46 // On Unix we need to set up the file permissions correctly so
47 // binaries are executable and directories readable. This shouldn't be
48 // necessary: the source files *should* have the right permissions,
49--
502.17.1
51