mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-11-15 13:37:21 +03:00
rustup: Patch rustup to patchelf binaries
This commit is contained in:
parent
af65f13e68
commit
cbe326feb8
@ -0,0 +1,54 @@
|
||||
From c21cc756b69a5f33c8a7758b746a816f40f55932 Mon Sep 17 00:00:00 2001
|
||||
From: Leon Isenberg <ljli@users.noreply.github.com>
|
||||
Date: Sat, 28 Oct 2017 17:58:17 +0200
|
||||
Subject: [PATCH] nix customization: patchelf installed binaries
|
||||
|
||||
---
|
||||
src/rustup-dist/src/component/package.rs | 24 +++++++++++++++++++++++-
|
||||
1 file changed, 23 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/src/rustup-dist/src/component/package.rs b/src/rustup-dist/src/component/package.rs
|
||||
index 8aa63db9..4d219826 100644
|
||||
--- a/src/rustup-dist/src/component/package.rs
|
||||
+++ b/src/rustup-dist/src/component/package.rs
|
||||
@@ -99,7 +99,13 @@ impl Package for DirectoryPackage {
|
||||
let src_path = root.join(&path);
|
||||
|
||||
match &*part.0 {
|
||||
- "file" => try!(builder.copy_file(path.clone(), &src_path)),
|
||||
+ "file" => {
|
||||
+ try!(builder.copy_file(path.clone(), &src_path));
|
||||
+ nix_patchelf_if_needed(
|
||||
+ &target.prefix().path().join(path.clone()),
|
||||
+ &src_path,
|
||||
+ )
|
||||
+ }
|
||||
"dir" => try!(builder.copy_dir(path.clone(), &src_path)),
|
||||
_ => return Err(ErrorKind::CorruptComponent(name.to_owned()).into()),
|
||||
}
|
||||
@@ -117,6 +123,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,
|
||||
--
|
||||
2.14.1
|
||||
|
@ -1,75 +0,0 @@
|
||||
From 36c053f37670c6003f9e8dc001741f7c49e9526a Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= <joerg@thalheim.io>
|
||||
Date: Sat, 15 Apr 2017 20:42:10 +0200
|
||||
Subject: [PATCH] use hardcoded dynamic-linker
|
||||
MIME-Version: 1.0
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
Content-Transfer-Encoding: 8bit
|
||||
|
||||
Signed-off-by: Jörg Thalheim <joerg@thalheim.io>
|
||||
---
|
||||
src/rustup-cli/common.rs | 3 ++-
|
||||
src/rustup/toolchain.rs | 22 ++++++++++++++++++++--
|
||||
2 files changed, 22 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/src/rustup-cli/common.rs b/src/rustup-cli/common.rs
|
||||
index 1abf345..21096e7 100644
|
||||
--- a/src/rustup-cli/common.rs
|
||||
+++ b/src/rustup-cli/common.rs
|
||||
@@ -220,7 +220,8 @@ pub fn rustc_version(toolchain: &Toolchain) -> String {
|
||||
if toolchain.exists() {
|
||||
let rustc_path = toolchain.binary_file("rustc");
|
||||
if utils::is_file(&rustc_path) {
|
||||
- let mut cmd = Command::new(&rustc_path);
|
||||
+ let mut cmd = Command::new("@dynamicLinker@");
|
||||
+ cmd.arg(&rustc_path);
|
||||
cmd.arg("--version");
|
||||
toolchain.set_ldpath(&mut cmd);
|
||||
|
||||
diff --git a/src/rustup/toolchain.rs b/src/rustup/toolchain.rs
|
||||
index dc29c32..212a4ab 100644
|
||||
--- a/src/rustup/toolchain.rs
|
||||
+++ b/src/rustup/toolchain.rs
|
||||
@@ -315,7 +315,7 @@ impl<'a> Toolchain<'a> {
|
||||
}
|
||||
Path::new(&binary)
|
||||
};
|
||||
- let mut cmd = Command::new(&path);
|
||||
+ let mut cmd = wrap_elf_interpreter(&path);
|
||||
self.set_env(&mut cmd);
|
||||
Ok(cmd)
|
||||
}
|
||||
@@ -363,7 +363,7 @@ impl<'a> Toolchain<'a> {
|
||||
} else {
|
||||
src_file
|
||||
};
|
||||
- let mut cmd = Command::new(exe_path);
|
||||
+ let mut cmd = wrap_elf_interpreter(exe_path);
|
||||
self.set_env(&mut cmd);
|
||||
cmd.env("RUSTUP_TOOLCHAIN", &primary_toolchain.name);
|
||||
Ok(cmd)
|
||||
@@ -648,3 +648,21 @@ impl<'a> Toolchain<'a> {
|
||||
path
|
||||
}
|
||||
}
|
||||
+
|
||||
+fn wrap_elf_interpreter<S: AsRef<OsStr>>(p: S) -> Command {
|
||||
+ use std::fs::File;
|
||||
+ use std::io::Read;
|
||||
+ let path = Path::new(&p);
|
||||
+ let is_elf = File::open(path).map(|mut f| {
|
||||
+ let mut buf = [0; 4];
|
||||
+ let _ = f.read(&mut buf);
|
||||
+ buf == b"\x7fELF"[..]
|
||||
+ }).unwrap_or(false);
|
||||
+ if is_elf {
|
||||
+ let mut cmd = Command::new("@dynamicLinker@");
|
||||
+ cmd.arg(&path);
|
||||
+ cmd
|
||||
+ } else {
|
||||
+ Command::new(&path)
|
||||
+ }
|
||||
+}
|
||||
--
|
||||
2.12.2
|
||||
|
@ -1,4 +1,4 @@
|
||||
{ stdenv, lib, runCommand
|
||||
{ stdenv, lib, runCommand, patchelf
|
||||
, fetchFromGitHub, rustPlatform
|
||||
, pkgconfig, curl, Security }:
|
||||
|
||||
@ -24,9 +24,11 @@ rustPlatform.buildRustPackage rec {
|
||||
cargoBuildFlags = [ "--features no-self-update" ];
|
||||
|
||||
patches = lib.optionals stdenv.isLinux [
|
||||
(runCommand "0001-use-hardcoded-dynamic-linker.patch" { CC=stdenv.cc; } ''
|
||||
(runCommand "0001-dynamically-patchelf-binaries.patch" { CC=stdenv.cc; patchelf = patchelf; } ''
|
||||
export dynamicLinker=$(cat $CC/nix-support/dynamic-linker)
|
||||
substituteAll ${./0001-use-hardcoded-dynamic-linker.patch} $out
|
||||
substitute ${./0001-dynamically-patchelf-binaries.patch} $out \
|
||||
--subst-var patchelf \
|
||||
--subst-var dynamicLinker
|
||||
'')
|
||||
];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user