about summary refs log tree commit diff
path: root/pkgs/applications/science
diff options
context:
space:
mode:
authorGabriel Ebner <gebner@gebner.org>2021-11-15 18:07:14 +0100
committerGitHub <noreply@github.com>2021-11-15 18:07:14 +0100
commitf4e3542f5d71d7ac1b8fc8ddf0c84f1bbb0de099 (patch)
treec296b03b4afc6343775ef58eb80a1344ad885d48 /pkgs/applications/science
parent5d668532817efe26c693479b14076b7f3a6c40d4 (diff)
parentf8bbc587eb2dbd1e7168b59cd0bb0d5aef89d2da (diff)
Merge pull request #146162 from Kha/elan-wrap-lld
elan: wrap embedded linker
Diffstat (limited to 'pkgs/applications/science')
-rw-r--r--pkgs/applications/science/logic/elan/0001-dynamically-patchelf-binaries.patch43
-rw-r--r--pkgs/applications/science/logic/elan/default.nix14
2 files changed, 23 insertions, 34 deletions
diff --git a/pkgs/applications/science/logic/elan/0001-dynamically-patchelf-binaries.patch b/pkgs/applications/science/logic/elan/0001-dynamically-patchelf-binaries.patch
index 48b1263e7961a..dc76305bd7499 100644
--- a/pkgs/applications/science/logic/elan/0001-dynamically-patchelf-binaries.patch
+++ b/pkgs/applications/science/logic/elan/0001-dynamically-patchelf-binaries.patch
@@ -1,24 +1,19 @@
 diff --git a/src/elan-dist/src/component/package.rs b/src/elan-dist/src/component/package.rs
-index c51e76d..d0a26d7 100644
+index c51e76d..ae8159e 100644
 --- a/src/elan-dist/src/component/package.rs
 +++ b/src/elan-dist/src/component/package.rs
-@@ -56,11 +56,35 @@ fn unpack_without_first_dir<R: Read>(archive: &mut tar::Archive<R>, path: &Path)
+@@ -56,6 +56,30 @@ fn unpack_without_first_dir<R: Read>(archive: &mut tar::Archive<R>, path: &Path)
          entry
              .unpack(&full_path)
              .chain_err(|| ErrorKind::ExtractingPackage)?;
-+        nix_patchelf_if_needed(&full_path);
-     }
- 
-     Ok(())
- }
- 
-+fn nix_patchelf_if_needed(dest_path: &Path) {
-+    let (is_bin, is_lib) = if let Some(p) = dest_path.parent() {
-+        (p.ends_with("bin"), p.ends_with("lib"))
-+    } else {
-+        (false, false)
-+    };
++        nix_patch_if_needed(&full_path)?;
++    }
++
++    Ok(())
++}
 +
++fn nix_patch_if_needed(dest_path: &Path) -> Result<()> {
++    let is_bin = matches!(dest_path.parent(), Some(p) if p.ends_with("bin"));
 +    if is_bin {
 +        let _ = ::std::process::Command::new("@patchelf@/bin/patchelf")
 +            .arg("--set-interpreter")
@@ -26,15 +21,15 @@ index c51e76d..d0a26d7 100644
 +            .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 ZipPackage<'a>(temp::Dir<'a>);
++    if dest_path.extension() == Some(::std::ffi::OsStr::new("lld")) {
++        use std::os::unix::fs::PermissionsExt;
++        let new_path = dest_path.with_extension("orig");
++        ::std::fs::rename(dest_path, &new_path)?;
++        ::std::fs::write(dest_path, format!(r#"#! @shell@
++exec -a "$0" {} "$@" --dynamic-linker=@dynamicLinker@
++"#, new_path.to_str().unwrap()))?;
++        ::std::fs::set_permissions(dest_path, ::std::fs::Permissions::from_mode(0o755))?;
+     }
  
+     Ok(())
diff --git a/pkgs/applications/science/logic/elan/default.nix b/pkgs/applications/science/logic/elan/default.nix
index a5709b69fbb84..cc4f0680de3ed 100644
--- a/pkgs/applications/science/logic/elan/default.nix
+++ b/pkgs/applications/science/logic/elan/default.nix
@@ -1,9 +1,5 @@
-{ stdenv, lib, runCommand, patchelf, makeWrapper, pkg-config, curl
-, openssl, gmp, zlib, fetchFromGitHub, rustPlatform, libiconv }:
-
-let
-  libPath = lib.makeLibraryPath [ gmp ];
-in
+{ stdenv, lib, runCommand, patchelf, makeWrapper, pkg-config, curl, runtimeShell
+, openssl, zlib, fetchFromGitHub, rustPlatform, libiconv }:
 
 rustPlatform.buildRustPackage rec {
   pname = "elan";
@@ -32,13 +28,13 @@ rustPlatform.buildRustPackage rec {
     (runCommand "0001-dynamically-patchelf-binaries.patch" {
         CC = stdenv.cc;
         patchelf = patchelf;
-        libPath = "$ORIGIN/../lib:${libPath}";
+        shell = runtimeShell;
       } ''
      export dynamicLinker=$(cat $CC/nix-support/dynamic-linker)
      substitute ${./0001-dynamically-patchelf-binaries.patch} $out \
        --subst-var patchelf \
        --subst-var dynamicLinker \
-       --subst-var libPath
+       --subst-var shell
     '')
   ];
 
@@ -50,8 +46,6 @@ rustPlatform.buildRustPackage rec {
     done
     popd
 
-    wrapProgram $out/bin/elan --prefix "LD_LIBRARY_PATH" : "${libPath}"
-
     # tries to create .elan
     export HOME=$(mktemp -d)
     mkdir -p "$out/share/"{bash-completion/completions,fish/vendor_completions.d,zsh/site-functions}