Skip to content

Commit 48ea70c

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 9050733 commit 48ea70c

File tree

2 files changed

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

2 files changed

+10
-7
lines changed

compiler/rustc_codegen_gcc/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,14 @@ pub struct GccCodegenBackend {
180180

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

183-
fn load_libgccjit_if_needed(sysroot_path: &Path) {
183+
fn load_libgccjit_if_needed(sysroot_path: &Path, target_triple: &str) {
184184
if gccjit::is_loaded() {
185185
// Do not load a libgccjit second time.
186186
return;
187187
}
188188

189189
let sysroot_lib_dir = sysroot_path.join("lib");
190-
let libgccjit_target_lib_file = sysroot_lib_dir.join("libgccjit.so");
190+
let libgccjit_target_lib_file = sysroot_lib_dir.join(target_triple).join("libgccjit.so");
191191
let path = libgccjit_target_lib_file.to_str().expect("libgccjit path");
192192

193193
let string = CString::new(path).expect("string to libgccjit path");
@@ -207,7 +207,7 @@ impl CodegenBackend for GccCodegenBackend {
207207
}
208208

209209
fn init(&self, sess: &Session) {
210-
load_libgccjit_if_needed(sess.opts.sysroot.path());
210+
load_libgccjit_if_needed(sess.opts.sysroot.path(), &sess.target.llvm_target);
211211

212212
#[cfg(feature = "master")]
213213
{

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)