Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)

rustup: Patch rustup to patchelf binaries

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