biome: 1.9.2 -> 1.9.3
[NixPkgs.git] / pkgs / applications / science / logic / elan / 0001-dynamically-patchelf-binaries.patch
blob0b33d4242eb7e7c1b955c79198a06408106d2ccf
1 diff --git a/src/elan-dist/src/component/package.rs b/src/elan-dist/src/component/package.rs
2 index c51e76d..ae8159e 100644
3 --- a/src/elan-dist/src/component/package.rs
4 +++ b/src/elan-dist/src/component/package.rs
5 @@ -56,6 +56,37 @@ fn unpack_without_first_dir<R: Read>(archive: &mut tar::Archive<R>, path: &Path)
6 entry
7 .unpack(&full_path)
8 .chain_err(|| ErrorKind::ExtractingPackage)?;
9 + nix_patch_if_needed(&full_path)?;
10 + }
12 + Ok(())
15 +fn nix_patch_if_needed(dest_path: &Path) -> Result<()> {
16 + let is_bin = matches!(dest_path.parent(), Some(p) if p.ends_with("bin"));
17 + if is_bin {
18 + let _ = ::std::process::Command::new("@patchelf@/bin/patchelf")
19 + .arg("--set-interpreter")
20 + .arg("@dynamicLinker@")
21 + .arg(dest_path)
22 + .output();
23 + }
25 + if dest_path.file_name() == Some(::std::ffi::OsStr::new("leanc")) {
26 + use std::os::unix::fs::PermissionsExt;
27 + let new_path = dest_path.with_extension("orig");
28 + ::std::fs::rename(dest_path, &new_path)?;
29 + ::std::fs::write(dest_path, r#"#! @shell@
30 +dir="$(dirname "${BASH_SOURCE[0]}")"
31 +# use bundled libraries, but not bundled compiler that doesn't know about NIX_LDFLAGS
32 +LEAN_CC="${LEAN_CC:-@cc@}" exec -a "$0" "$dir/leanc.orig" "$@" -L"$dir/../lib"
33 +"#)?;
34 + ::std::fs::set_permissions(dest_path, ::std::fs::Permissions::from_mode(0o755))?;
35 + }
37 + if dest_path.file_name() == Some(::std::ffi::OsStr::new("llvm-ar")) {
38 + ::std::fs::remove_file(dest_path)?;
39 + ::std::os::unix::fs::symlink("@ar@", dest_path)?;
42 Ok(())