Skip to content

Commit 76bee3a

Browse files
committed
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.
1 parent 864339a commit 76bee3a

File tree

2 files changed

+13
-10
lines changed
  • compiler/rustc_codegen_gcc/src
  • src/bootstrap/src/core/build_steps

2 files changed

+13
-10
lines changed

compiler/rustc_codegen_gcc/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,18 +181,18 @@ pub struct GccCodegenBackend {
181181

182182
static LTO_SUPPORTED: AtomicBool = AtomicBool::new(false);
183183

184-
fn libgccjit_path(sysroot_path: &Path) -> PathBuf {
184+
fn libgccjit_path(sysroot_path: &Path, target_triple: &str) -> PathBuf {
185185
let sysroot_lib_dir = sysroot_path.join("lib");
186-
sysroot_lib_dir.join("libgccjit.so")
186+
sysroot_lib_dir.join(target_triple).join("libgccjit.so")
187187
}
188188

189-
fn load_libgccjit_if_needed(sysroot_path: &Path) {
189+
fn load_libgccjit_if_needed(sysroot_path: &Path, target_triple: &str) {
190190
if gccjit::is_loaded() {
191191
// Do not load a libgccjit second time.
192192
return;
193193
}
194194

195-
let libgccjit_target_lib_file = libgccjit_path(sysroot_path);
195+
let libgccjit_target_lib_file = libgccjit_path(sysroot_path, target_triple);
196196
let path = libgccjit_target_lib_file.to_str().expect("libgccjit path");
197197

198198
let string = CString::new(path).expect("string to libgccjit path");
@@ -216,9 +216,9 @@ impl CodegenBackend for GccCodegenBackend {
216216
// invalid.
217217
// This is the case for instance in Rust for Linux where they specify --sysroot=/dev/null.
218218
for path in sess.opts.sysroot.all_paths() {
219-
let libgccjit_target_lib_file = libgccjit_path(path);
219+
let libgccjit_target_lib_file = libgccjit_path(path, &sess.target.llvm_target);
220220
if let Ok(true) = fs::exists(libgccjit_target_lib_file) {
221-
load_libgccjit_if_needed(path);
221+
load_libgccjit_if_needed(path, &sess.target.llvm_target);
222222
break;
223223
}
224224
}

src/bootstrap/src/core/build_steps/gcc.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub struct Gcc {
2727
#[derive(Clone)]
2828
pub struct GccOutput {
2929
pub libgccjit: PathBuf,
30+
target: TargetSelection,
3031
}
3132

3233
impl GccOutput {
@@ -46,7 +47,9 @@ impl GccOutput {
4647
format!("Cannot find libgccjit at {}", self.libgccjit.display())
4748
);
4849

49-
let dst = directory.join(target_filename);
50+
let dest_dir = directory.join(self.target);
51+
t!(fs::create_dir_all(&dest_dir));
52+
let dst = dest_dir.join(target_filename);
5053
builder.copy_link(&actual_libgccjit_path, &dst, FileType::NativeLibrary);
5154
}
5255
}
@@ -70,7 +73,7 @@ impl Step for Gcc {
7073

7174
// If GCC has already been built, we avoid building it again.
7275
let metadata = match get_gcc_build_status(builder, target) {
73-
GccBuildStatus::AlreadyBuilt(path) => return GccOutput { libgccjit: path },
76+
GccBuildStatus::AlreadyBuilt(path) => return GccOutput { libgccjit: path, target },
7477
GccBuildStatus::ShouldBuild(m) => m,
7578
};
7679

@@ -80,14 +83,14 @@ impl Step for Gcc {
8083

8184
let libgccjit_path = libgccjit_built_path(&metadata.install_dir);
8285
if builder.config.dry_run() {
83-
return GccOutput { libgccjit: libgccjit_path };
86+
return GccOutput { libgccjit: libgccjit_path, target };
8487
}
8588

8689
build_gcc(&metadata, builder, target);
8790

8891
t!(metadata.stamp.write());
8992

90-
GccOutput { libgccjit: libgccjit_path }
93+
GccOutput { libgccjit: libgccjit_path, target }
9194
}
9295
}
9396

0 commit comments

Comments
 (0)