tangled
alpha
login
or
join now
tjh.dev
/
nixpkgs
Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
0
fork
atom
overview
issues
pulls
pipelines
rustup: Patch rustup to patchelf binaries
Leon Isenberg
8 years ago
cbe326fe
af65f13e
+59
-78
3 changed files
expand all
collapse all
unified
split
pkgs
development
tools
rust
rustup
0001-dynamically-patchelf-binaries.patch
0001-use-hardcoded-dynamic-linker.patch
default.nix
+54
pkgs/development/tools/rust/rustup/0001-dynamically-patchelf-binaries.patch
···
1
1
+
From c21cc756b69a5f33c8a7758b746a816f40f55932 Mon Sep 17 00:00:00 2001
2
2
+
From: Leon Isenberg <ljli@users.noreply.github.com>
3
3
+
Date: Sat, 28 Oct 2017 17:58:17 +0200
4
4
+
Subject: [PATCH] nix customization: patchelf installed binaries
5
5
+
6
6
+
---
7
7
+
src/rustup-dist/src/component/package.rs | 24 +++++++++++++++++++++++-
8
8
+
1 file changed, 23 insertions(+), 1 deletion(-)
9
9
+
10
10
+
diff --git a/src/rustup-dist/src/component/package.rs b/src/rustup-dist/src/component/package.rs
11
11
+
index 8aa63db9..4d219826 100644
12
12
+
--- a/src/rustup-dist/src/component/package.rs
13
13
+
+++ b/src/rustup-dist/src/component/package.rs
14
14
+
@@ -99,7 +99,13 @@ impl Package for DirectoryPackage {
15
15
+
let src_path = root.join(&path);
16
16
+
17
17
+
match &*part.0 {
18
18
+
- "file" => try!(builder.copy_file(path.clone(), &src_path)),
19
19
+
+ "file" => {
20
20
+
+ try!(builder.copy_file(path.clone(), &src_path));
21
21
+
+ nix_patchelf_if_needed(
22
22
+
+ &target.prefix().path().join(path.clone()),
23
23
+
+ &src_path,
24
24
+
+ )
25
25
+
+ }
26
26
+
"dir" => try!(builder.copy_dir(path.clone(), &src_path)),
27
27
+
_ => return Err(ErrorKind::CorruptComponent(name.to_owned()).into()),
28
28
+
}
29
29
+
@@ -117,6 +123,22 @@ impl Package for DirectoryPackage {
30
30
+
}
31
31
+
}
32
32
+
33
33
+
+fn nix_patchelf_if_needed(dest_path: &Path, src_path: &Path) {
34
34
+
+ let is_bin = if let Some(p) = src_path.parent() {
35
35
+
+ p.ends_with("bin")
36
36
+
+ } else {
37
37
+
+ false
38
38
+
+ };
39
39
+
+
40
40
+
+ if is_bin {
41
41
+
+ let _ = ::std::process::Command::new("@patchelf@/bin/patchelf")
42
42
+
+ .arg("--set-interpreter")
43
43
+
+ .arg("@dynamicLinker@")
44
44
+
+ .arg(dest_path)
45
45
+
+ .output();
46
46
+
+ }
47
47
+
+}
48
48
+
+
49
49
+
// On Unix we need to set up the file permissions correctly so
50
50
+
// binaries are executable and directories readable. This shouldn't be
51
51
+
// necessary: the source files *should* have the right permissions,
52
52
+
--
53
53
+
2.14.1
54
54
+
-75
pkgs/development/tools/rust/rustup/0001-use-hardcoded-dynamic-linker.patch
···
1
1
-
From 36c053f37670c6003f9e8dc001741f7c49e9526a Mon Sep 17 00:00:00 2001
2
2
-
From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= <joerg@thalheim.io>
3
3
-
Date: Sat, 15 Apr 2017 20:42:10 +0200
4
4
-
Subject: [PATCH] use hardcoded dynamic-linker
5
5
-
MIME-Version: 1.0
6
6
-
Content-Type: text/plain; charset=UTF-8
7
7
-
Content-Transfer-Encoding: 8bit
8
8
-
9
9
-
Signed-off-by: Jörg Thalheim <joerg@thalheim.io>
10
10
-
---
11
11
-
src/rustup-cli/common.rs | 3 ++-
12
12
-
src/rustup/toolchain.rs | 22 ++++++++++++++++++++--
13
13
-
2 files changed, 22 insertions(+), 3 deletions(-)
14
14
-
15
15
-
diff --git a/src/rustup-cli/common.rs b/src/rustup-cli/common.rs
16
16
-
index 1abf345..21096e7 100644
17
17
-
--- a/src/rustup-cli/common.rs
18
18
-
+++ b/src/rustup-cli/common.rs
19
19
-
@@ -220,7 +220,8 @@ pub fn rustc_version(toolchain: &Toolchain) -> String {
20
20
-
if toolchain.exists() {
21
21
-
let rustc_path = toolchain.binary_file("rustc");
22
22
-
if utils::is_file(&rustc_path) {
23
23
-
- let mut cmd = Command::new(&rustc_path);
24
24
-
+ let mut cmd = Command::new("@dynamicLinker@");
25
25
-
+ cmd.arg(&rustc_path);
26
26
-
cmd.arg("--version");
27
27
-
toolchain.set_ldpath(&mut cmd);
28
28
-
29
29
-
diff --git a/src/rustup/toolchain.rs b/src/rustup/toolchain.rs
30
30
-
index dc29c32..212a4ab 100644
31
31
-
--- a/src/rustup/toolchain.rs
32
32
-
+++ b/src/rustup/toolchain.rs
33
33
-
@@ -315,7 +315,7 @@ impl<'a> Toolchain<'a> {
34
34
-
}
35
35
-
Path::new(&binary)
36
36
-
};
37
37
-
- let mut cmd = Command::new(&path);
38
38
-
+ let mut cmd = wrap_elf_interpreter(&path);
39
39
-
self.set_env(&mut cmd);
40
40
-
Ok(cmd)
41
41
-
}
42
42
-
@@ -363,7 +363,7 @@ impl<'a> Toolchain<'a> {
43
43
-
} else {
44
44
-
src_file
45
45
-
};
46
46
-
- let mut cmd = Command::new(exe_path);
47
47
-
+ let mut cmd = wrap_elf_interpreter(exe_path);
48
48
-
self.set_env(&mut cmd);
49
49
-
cmd.env("RUSTUP_TOOLCHAIN", &primary_toolchain.name);
50
50
-
Ok(cmd)
51
51
-
@@ -648,3 +648,21 @@ impl<'a> Toolchain<'a> {
52
52
-
path
53
53
-
}
54
54
-
}
55
55
-
+
56
56
-
+fn wrap_elf_interpreter<S: AsRef<OsStr>>(p: S) -> Command {
57
57
-
+ use std::fs::File;
58
58
-
+ use std::io::Read;
59
59
-
+ let path = Path::new(&p);
60
60
-
+ let is_elf = File::open(path).map(|mut f| {
61
61
-
+ let mut buf = [0; 4];
62
62
-
+ let _ = f.read(&mut buf);
63
63
-
+ buf == b"\x7fELF"[..]
64
64
-
+ }).unwrap_or(false);
65
65
-
+ if is_elf {
66
66
-
+ let mut cmd = Command::new("@dynamicLinker@");
67
67
-
+ cmd.arg(&path);
68
68
-
+ cmd
69
69
-
+ } else {
70
70
-
+ Command::new(&path)
71
71
-
+ }
72
72
-
+}
73
73
-
--
74
74
-
2.12.2
75
75
-
+5
-3
pkgs/development/tools/rust/rustup/default.nix
···
1
1
-
{ stdenv, lib, runCommand
1
1
+
{ stdenv, lib, runCommand, patchelf
2
2
, fetchFromGitHub, rustPlatform
3
3
, pkgconfig, curl, Security }:
4
4
···
24
24
cargoBuildFlags = [ "--features no-self-update" ];
25
25
26
26
patches = lib.optionals stdenv.isLinux [
27
27
-
(runCommand "0001-use-hardcoded-dynamic-linker.patch" { CC=stdenv.cc; } ''
27
27
+
(runCommand "0001-dynamically-patchelf-binaries.patch" { CC=stdenv.cc; patchelf = patchelf; } ''
28
28
export dynamicLinker=$(cat $CC/nix-support/dynamic-linker)
29
29
-
substituteAll ${./0001-use-hardcoded-dynamic-linker.patch} $out
29
29
+
substitute ${./0001-dynamically-patchelf-binaries.patch} $out \
30
30
+
--subst-var patchelf \
31
31
+
--subst-var dynamicLinker
30
32
'')
31
33
];
32
34