From 76bee3a0444d67f4e89a5f0e3e713a3dcc1f8ba8 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Fri, 28 Nov 2025 14:16:56 -0500 Subject: [PATCH] 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. --- compiler/rustc_codegen_gcc/src/lib.rs | 12 ++++++------ src/bootstrap/src/core/build_steps/gcc.rs | 11 +++++++---- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_codegen_gcc/src/lib.rs b/compiler/rustc_codegen_gcc/src/lib.rs index c1506ee6176f..1bdc62f7f29c 100644 --- a/compiler/rustc_codegen_gcc/src/lib.rs +++ b/compiler/rustc_codegen_gcc/src/lib.rs @@ -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; } } diff --git a/src/bootstrap/src/core/build_steps/gcc.rs b/src/bootstrap/src/core/build_steps/gcc.rs index def794c98a41..d638dd45f3ac 100644 --- a/src/bootstrap/src/core/build_steps/gcc.rs +++ b/src/bootstrap/src/core/build_steps/gcc.rs @@ -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 } } }