Skip to content

Commit

Permalink
rustup: Patch rustup to patchelf binaries
Browse files Browse the repository at this point in the history
(cherry picked from commit cbe326f)
  • Loading branch information
ljli authored and Mic92 committed Feb 8, 2018
1 parent 3e349a2 commit b1be17c
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 78 deletions.
@@ -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

This file was deleted.

8 changes: 5 additions & 3 deletions pkgs/development/tools/rust/rustup/default.nix
@@ -1,4 +1,4 @@
{ stdenv, lib, runCommand
{ stdenv, lib, runCommand, patchelf
, fetchFromGitHub, rustPlatform
, pkgconfig, curl, Security }:

Expand All @@ -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
'')
];

Expand Down

0 comments on commit b1be17c

Please sign in to comment.