Skip to content

Commit 0a4b0af

Browse files
Generate symbolic link to libgccjit.so as well
1 parent eee04a4 commit 0a4b0af

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

build_system/src/config.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use crate::utils::{get_os_name, run_command_with_output, rustc_version_info, split_args};
1+
use crate::utils::{
2+
create_symlink, get_os_name, run_command_with_output, rustc_version_info, split_args,
3+
};
24
use std::collections::HashMap;
35
use std::env as std_env;
46
use std::ffi::OsStr;
@@ -215,7 +217,8 @@ impl ConfigInfo {
215217
)
216218
})?;
217219
}
218-
let libgccjit_so = output_dir.join("libgccjit.so");
220+
let libgccjit_so_name = "libgccjit.so";
221+
let libgccjit_so = output_dir.join(libgccjit_so_name);
219222
if !libgccjit_so.is_file() {
220223
// Download time!
221224
let tempfile_name = "libgccjit.so.download";
@@ -279,6 +282,16 @@ impl ConfigInfo {
279282
})?;
280283

281284
println!("Downloaded libgccjit.so version {} successfully!", commit);
285+
create_symlink(
286+
&libgccjit_so.canonicalize().map_err(|err| {
287+
format!(
288+
"Failed to get absolute path of `{}`: {:?}",
289+
libgccjit_so.display(),
290+
err,
291+
)
292+
})?,
293+
output_dir.join(&format!("{}.0", libgccjit_so_name)),
294+
)?;
282295
}
283296

284297
self.gcc_path = output_dir

build_system/src/utils.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,22 @@ pub fn remove_file<P: AsRef<Path> + ?Sized>(file_path: &P) -> Result<(), String>
374374
})
375375
}
376376

377+
pub fn create_symlink<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) -> Result<(), String> {
378+
#[cfg(windows)]
379+
let symlink = std::os::windows::fs::symlink_file;
380+
#[cfg(not(windows))]
381+
let symlink = std::os::unix::fs::symlink;
382+
383+
symlink(&original, &link).map_err(|err| {
384+
format!(
385+
"failed to create a symlink `{}` to `{}`: {:?}",
386+
original.as_ref().display(),
387+
link.as_ref().display(),
388+
err,
389+
)
390+
})
391+
}
392+
377393
#[cfg(test)]
378394
mod tests {
379395
use super::*;

0 commit comments

Comments
 (0)