elan: wrap embedded linker
This commit is contained in:
parent
d631a73345
commit
f8bbc587eb
2 changed files with 23 additions and 34 deletions
|
@ -1,24 +1,19 @@
|
||||||
diff --git a/src/elan-dist/src/component/package.rs b/src/elan-dist/src/component/package.rs
|
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
|
--- a/src/elan-dist/src/component/package.rs
|
||||||
+++ b/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
|
entry
|
||||||
.unpack(&full_path)
|
.unpack(&full_path)
|
||||||
.chain_err(|| ErrorKind::ExtractingPackage)?;
|
.chain_err(|| ErrorKind::ExtractingPackage)?;
|
||||||
+ nix_patchelf_if_needed(&full_path);
|
+ nix_patch_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)
|
|
||||||
+ };
|
|
||||||
+
|
+
|
||||||
|
+ 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 {
|
+ if is_bin {
|
||||||
+ let _ = ::std::process::Command::new("@patchelf@/bin/patchelf")
|
+ let _ = ::std::process::Command::new("@patchelf@/bin/patchelf")
|
||||||
+ .arg("--set-interpreter")
|
+ .arg("--set-interpreter")
|
||||||
|
@ -26,15 +21,15 @@ index c51e76d..d0a26d7 100644
|
||||||
+ .arg(dest_path)
|
+ .arg(dest_path)
|
||||||
+ .output();
|
+ .output();
|
||||||
+ }
|
+ }
|
||||||
+ else if is_lib {
|
|
||||||
+ let _ = ::std::process::Command::new("@patchelf@/bin/patchelf")
|
|
||||||
+ .arg("--set-rpath")
|
|
||||||
+ .arg("@libPath@")
|
|
||||||
+ .arg(dest_path)
|
|
||||||
+ .output();
|
|
||||||
+ }
|
|
||||||
+}
|
|
||||||
+
|
+
|
||||||
#[derive(Debug)]
|
+ if dest_path.extension() == Some(::std::ffi::OsStr::new("lld")) {
|
||||||
pub struct ZipPackage<'a>(temp::Dir<'a>);
|
+ 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(())
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
{ stdenv, lib, runCommand, patchelf, makeWrapper, pkg-config, curl
|
{ stdenv, lib, runCommand, patchelf, makeWrapper, pkg-config, curl, runtimeShell
|
||||||
, openssl, gmp, zlib, fetchFromGitHub, rustPlatform, libiconv }:
|
, openssl, zlib, fetchFromGitHub, rustPlatform, libiconv }:
|
||||||
|
|
||||||
let
|
|
||||||
libPath = lib.makeLibraryPath [ gmp ];
|
|
||||||
in
|
|
||||||
|
|
||||||
rustPlatform.buildRustPackage rec {
|
rustPlatform.buildRustPackage rec {
|
||||||
pname = "elan";
|
pname = "elan";
|
||||||
|
@ -32,13 +28,13 @@ rustPlatform.buildRustPackage rec {
|
||||||
(runCommand "0001-dynamically-patchelf-binaries.patch" {
|
(runCommand "0001-dynamically-patchelf-binaries.patch" {
|
||||||
CC = stdenv.cc;
|
CC = stdenv.cc;
|
||||||
patchelf = patchelf;
|
patchelf = patchelf;
|
||||||
libPath = "$ORIGIN/../lib:${libPath}";
|
shell = runtimeShell;
|
||||||
} ''
|
} ''
|
||||||
export dynamicLinker=$(cat $CC/nix-support/dynamic-linker)
|
export dynamicLinker=$(cat $CC/nix-support/dynamic-linker)
|
||||||
substitute ${./0001-dynamically-patchelf-binaries.patch} $out \
|
substitute ${./0001-dynamically-patchelf-binaries.patch} $out \
|
||||||
--subst-var patchelf \
|
--subst-var patchelf \
|
||||||
--subst-var dynamicLinker \
|
--subst-var dynamicLinker \
|
||||||
--subst-var libPath
|
--subst-var shell
|
||||||
'')
|
'')
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -50,8 +46,6 @@ rustPlatform.buildRustPackage rec {
|
||||||
done
|
done
|
||||||
popd
|
popd
|
||||||
|
|
||||||
wrapProgram $out/bin/elan --prefix "LD_LIBRARY_PATH" : "${libPath}"
|
|
||||||
|
|
||||||
# tries to create .elan
|
# tries to create .elan
|
||||||
export HOME=$(mktemp -d)
|
export HOME=$(mktemp -d)
|
||||||
mkdir -p "$out/share/"{bash-completion/completions,fish/vendor_completions.d,zsh/site-functions}
|
mkdir -p "$out/share/"{bash-completion/completions,fish/vendor_completions.d,zsh/site-functions}
|
||||||
|
|
Loading…
Reference in a new issue