aboutsummaryrefslogtreecommitdiff
path: root/nixpkgs/pkgs/development/tools/rust/rustup/0001-dynamically-patchelf-binaries.patch
blob: 13649b387a3ec2c35814db27723063cf2bf5922c (plain)
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
42
diff --git a/src/dist/component/package.rs b/src/dist/component/package.rs
index 3beddf54..0f859b8d 100644
--- a/src/dist/component/package.rs
+++ b/src/dist/component/package.rs
@@ -113,6 +113,7 @@ impl Package for DirectoryPackage {
                     } else {
                         builder.move_file(path.clone(), &src_path)?
                     }
+                    nix_patchelf_if_needed(&target.prefix().path().join(path.clone()), &src_path)
                 }
                 "dir" => {
                     if self.copy {
@@ -135,6 +136,29 @@ impl Package for DirectoryPackage {
     }
 }
 
+fn nix_patchelf_if_needed(dest_path: &Path, src_path: &Path) {
+    let (is_bin, is_lib) = if let Some(p) = src_path.parent() {
+        (p.ends_with("bin"), p.ends_with("lib"))
+    } else {
+        (false, false)
+    };
+
+    if is_bin {
+        let _ = ::std::process::Command::new("@patchelf@/bin/patchelf")
+            .arg("--set-interpreter")
+            .arg("@dynamicLinker@")
+            .arg(dest_path)
+            .output();
+    }
+    else if is_lib {
+        let _ = ::std::process::Command::new("@patchelf@/bin/patchelf")
+            .arg("--set-rpath")
+            .arg("@libPath@")
+            .arg(dest_path)
+            .output();
+    }
+}
+
 #[derive(Debug)]
 pub struct TarPackage<'a>(DirectoryPackage, temp::Dir<'a>);