Move the libgccjit.so file in a target directory

Since GCC is not multi-target, we need multiple libgccjit.so.
Our solution to have a directory per target so that we can have multiple
libgccjit.so.
This commit is contained in:
Antoni Boucher
2025-11-28 14:16:56 -05:00
parent 864339abf9
commit 76bee3a044
2 changed files with 13 additions and 10 deletions
+6 -6
View File
@@ -181,18 +181,18 @@ pub struct GccCodegenBackend {
static LTO_SUPPORTED: AtomicBool = AtomicBool::new(false);
fn libgccjit_path(sysroot_path: &Path) -> PathBuf {
fn libgccjit_path(sysroot_path: &Path, target_triple: &str) -> PathBuf {
let sysroot_lib_dir = sysroot_path.join("lib");
sysroot_lib_dir.join("libgccjit.so")
sysroot_lib_dir.join(target_triple).join("libgccjit.so")
}
fn load_libgccjit_if_needed(sysroot_path: &Path) {
fn load_libgccjit_if_needed(sysroot_path: &Path, target_triple: &str) {
if gccjit::is_loaded() {
// Do not load a libgccjit second time.
return;
}
let libgccjit_target_lib_file = libgccjit_path(sysroot_path);
let libgccjit_target_lib_file = libgccjit_path(sysroot_path, target_triple);
let path = libgccjit_target_lib_file.to_str().expect("libgccjit path");
let string = CString::new(path).expect("string to libgccjit path");
@@ -216,9 +216,9 @@ fn init(&self, sess: &Session) {
// invalid.
// This is the case for instance in Rust for Linux where they specify --sysroot=/dev/null.
for path in sess.opts.sysroot.all_paths() {
let libgccjit_target_lib_file = libgccjit_path(path);
let libgccjit_target_lib_file = libgccjit_path(path, &sess.target.llvm_target);
if let Ok(true) = fs::exists(libgccjit_target_lib_file) {
load_libgccjit_if_needed(path);
load_libgccjit_if_needed(path, &sess.target.llvm_target);
break;
}
}
+7 -4
View File
@@ -27,6 +27,7 @@ pub struct Gcc {
#[derive(Clone)]
pub struct GccOutput {
pub libgccjit: PathBuf,
target: TargetSelection,
}
impl GccOutput {
@@ -46,7 +47,9 @@ pub fn install_to(&self, builder: &Builder<'_>, directory: &Path) {
format!("Cannot find libgccjit at {}", self.libgccjit.display())
);
let dst = directory.join(target_filename);
let dest_dir = directory.join(self.target);
t!(fs::create_dir_all(&dest_dir));
let dst = dest_dir.join(target_filename);
builder.copy_link(&actual_libgccjit_path, &dst, FileType::NativeLibrary);
}
}
@@ -70,7 +73,7 @@ fn run(self, builder: &Builder<'_>) -> Self::Output {
// If GCC has already been built, we avoid building it again.
let metadata = match get_gcc_build_status(builder, target) {
GccBuildStatus::AlreadyBuilt(path) => return GccOutput { libgccjit: path },
GccBuildStatus::AlreadyBuilt(path) => return GccOutput { libgccjit: path, target },
GccBuildStatus::ShouldBuild(m) => m,
};
@@ -80,14 +83,14 @@ fn run(self, builder: &Builder<'_>) -> Self::Output {
let libgccjit_path = libgccjit_built_path(&metadata.install_dir);
if builder.config.dry_run() {
return GccOutput { libgccjit: libgccjit_path };
return GccOutput { libgccjit: libgccjit_path, target };
}
build_gcc(&metadata, builder, target);
t!(metadata.stamp.write());
GccOutput { libgccjit: libgccjit_path }
GccOutput { libgccjit: libgccjit_path, target }
}
}