Generate symbolic link to libgccjit.so as well

This commit is contained in:
Guillaume Gomez 2024-02-12 20:09:54 +01:00
parent eee04a48d9
commit 0a4b0af141
2 changed files with 31 additions and 2 deletions

View File

@ -1,4 +1,6 @@
use crate::utils::{get_os_name, run_command_with_output, rustc_version_info, split_args};
use crate::utils::{
create_symlink, get_os_name, run_command_with_output, rustc_version_info, split_args,
};
use std::collections::HashMap;
use std::env as std_env;
use std::ffi::OsStr;
@ -215,7 +217,8 @@ fn download_gccjit_if_needed(&mut self) -> Result<(), String> {
)
})?;
}
let libgccjit_so = output_dir.join("libgccjit.so");
let libgccjit_so_name = "libgccjit.so";
let libgccjit_so = output_dir.join(libgccjit_so_name);
if !libgccjit_so.is_file() {
// Download time!
let tempfile_name = "libgccjit.so.download";
@ -279,6 +282,16 @@ fn download_gccjit_if_needed(&mut self) -> Result<(), String> {
})?;
println!("Downloaded libgccjit.so version {} successfully!", commit);
create_symlink(
&libgccjit_so.canonicalize().map_err(|err| {
format!(
"Failed to get absolute path of `{}`: {:?}",
libgccjit_so.display(),
err,
)
})?,
output_dir.join(&format!("{}.0", libgccjit_so_name)),
)?;
}
self.gcc_path = output_dir

View File

@ -374,6 +374,22 @@ pub fn remove_file<P: AsRef<Path> + ?Sized>(file_path: &P) -> Result<(), String>
})
}
pub fn create_symlink<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) -> Result<(), String> {
#[cfg(windows)]
let symlink = std::os::windows::fs::symlink_file;
#[cfg(not(windows))]
let symlink = std::os::unix::fs::symlink;
symlink(&original, &link).map_err(|err| {
format!(
"failed to create a symlink `{}` to `{}`: {:?}",
original.as_ref().display(),
link.as_ref().display(),
err,
)
})
}
#[cfg(test)]
mod tests {
use super::*;