summary refs log tree commit diff
path: root/pkgs/development/tools/rust/rustup/0001-dynamically-patchelf-binaries.patch
blob: 74da8d6102e7c3ad4548102498835d61ff103cc4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
diff --git a/src/dist/component/package.rs b/src/dist/component/package.rs
index e0fdea28..38d9d0e4 100644
--- a/src/dist/component/package.rs
+++ b/src/dist/component/package.rs
@@ -104,10 +104,11 @@ impl Package for DirectoryPackage {
             match &*part.0 {
                 "file" => {
                     if self.copy {
-                        builder.copy_file(path.clone(), &src_path)?
+                        builder.copy_file(path.clone(), &src_path)?;
                     } else {
-                        builder.move_file(path.clone(), &src_path)?
+                        builder.move_file(path.clone(), &src_path)?;
                     }
+                    nix_patchelf_if_needed(&target.prefix().path().join(path.clone()), &src_path)
                 }
                 "dir" => {
                     if self.copy {
@@ -132,6 +133,22 @@ impl Package for DirectoryPackage {
     }
 }

+fn nix_patchelf_if_needed(dest_path: &Path, src_path: &Path) {
+    let is_bin = if let Some(p) = src_path.parent() {
+        p.ends_with("bin")
+    } else {
+        false
+    };
+
+    if is_bin {
+        let _ = ::std::process::Command::new("@patchelf@/bin/patchelf")
+            .arg("--set-interpreter")
+            .arg("@dynamicLinker@")
+            .arg(dest_path)
+            .output();
+    }
+}
+
 // On Unix we need to set up the file permissions correctly so
 // binaries are executable and directories readable. This shouldn't be
 // necessary: the source files *should* have the right permissions,