2021-03-20 04:20:00 +00:00
|
|
|
diff --git a/src/elan-dist/src/component/package.rs b/src/elan-dist/src/component/package.rs
|
2021-12-06 16:07:01 +00:00
|
|
|
index c51e76d..ae8159e 100644
|
2021-03-20 04:20:00 +00:00
|
|
|
--- a/src/elan-dist/src/component/package.rs
|
|
|
|
+++ b/src/elan-dist/src/component/package.rs
|
2021-12-06 16:07:01 +00:00
|
|
|
@@ -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_patch_if_needed(&full_path)?;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Ok(())
|
|
|
|
+}
|
2021-03-20 04:20:00 +00:00
|
|
|
+
|
2021-12-06 16:07:01 +00:00
|
|
|
+fn nix_patch_if_needed(dest_path: &Path) -> Result<()> {
|
|
|
|
+ let is_bin = matches!(dest_path.parent(), Some(p) if p.ends_with("bin"));
|
2021-03-20 04:20:00 +00:00
|
|
|
+ if is_bin {
|
|
|
|
+ let _ = ::std::process::Command::new("@patchelf@/bin/patchelf")
|
|
|
|
+ .arg("--set-interpreter")
|
|
|
|
+ .arg("@dynamicLinker@")
|
|
|
|
+ .arg(dest_path)
|
|
|
|
+ .output();
|
|
|
|
+ }
|
|
|
|
+
|
2021-12-21 02:18:32 +00:00
|
|
|
+ if dest_path.file_name() == Some(::std::ffi::OsStr::new("leanc")) {
|
2021-12-06 16:07:01 +00:00
|
|
|
+ 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@
|
2021-12-21 02:18:32 +00:00
|
|
|
+LEAN_CC="${{LEAN_CC:-@cc@}}" exec -a "$0" {} "$@" -L {}/lib # use bundled libraries, but not bundled compiler that doesn't know about NIX_LDFLAGS
|
|
|
|
+"#, new_path.to_str().unwrap(), dest_path.parent().unwrap().parent().unwrap().to_str().unwrap()))?;
|
2021-12-06 16:07:01 +00:00
|
|
|
+ ::std::fs::set_permissions(dest_path, ::std::fs::Permissions::from_mode(0o755))?;
|
|
|
|
}
|
2021-03-20 04:20:00 +00:00
|
|
|
|
2021-12-06 16:07:01 +00:00
|
|
|
Ok(())
|