Skip to content

Commit cfc5782

Browse files
Create new CG_LIBGCCJIT_PATH env variable to specify the path for libgccjit.so
1 parent 74bcdd6 commit cfc5782

2 files changed

Lines changed: 22 additions & 11 deletions

File tree

build_system/src/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,9 @@ impl ConfigInfo {
397397
} else {
398398
if !self.use_llvm_sysroot {
399399
rustflags.extend_from_slice(&["--sysroot".to_string(), self.sysroot_path.clone()]);
400+
} else {
401+
let libgccjit_path = self.gcc_path.as_ref().unwrap().join("libgccjit.so");
402+
env.insert("CG_LIBGCCJIT_PATH".into(), libgccjit_path.display().to_string());
400403
}
401404
rustflags.push(format!("-Zcodegen-backend={}", self.cg_backend_path));
402405
}

src/lib.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -207,25 +207,33 @@ impl CodegenBackend for GccCodegenBackend {
207207
.join("libgccjit.so")
208208
}
209209

210-
// We use all_paths() instead of only path() in case the path specified by --sysroot is
211-
// invalid.
212-
// This is the case for instance in Rust for Linux where they specify --sysroot=/dev/null.
213-
for path in sess.opts.sysroot.all_paths() {
214-
let libgccjit_target_lib_file = file_path(path, sess);
215-
if let Ok(true) = fs::exists(&libgccjit_target_lib_file) {
216-
load_libgccjit_if_needed(&libgccjit_target_lib_file);
217-
break;
210+
let mut attempted_paths = Vec::new();
211+
if let Ok(libgccjit_path) = std::env::var("CG_LIBGCCJIT_PATH") {
212+
let libgccjit_path = PathBuf::from(libgccjit_path);
213+
if let Ok(true) = fs::exists(&libgccjit_path) {
214+
load_libgccjit_if_needed(&libgccjit_path);
215+
} else {
216+
attempted_paths.push(libgccjit_path);
218217
}
219218
}
220219

221220
if !gccjit::is_loaded() {
222-
let mut paths = vec![];
221+
// We use all_paths() instead of only path() in case the path specified by --sysroot is
222+
// invalid.
223+
// This is the case for instance in Rust for Linux where they specify --sysroot=/dev/null.
223224
for path in sess.opts.sysroot.all_paths() {
224225
let libgccjit_target_lib_file = file_path(path, sess);
225-
paths.push(libgccjit_target_lib_file);
226+
if let Ok(true) = fs::exists(&libgccjit_target_lib_file) {
227+
load_libgccjit_if_needed(&libgccjit_target_lib_file);
228+
break;
229+
} else {
230+
attempted_paths.push(libgccjit_target_lib_file);
231+
}
226232
}
233+
}
227234

228-
panic!("Could not load libgccjit.so. Attempted paths: {:#?}", paths);
235+
if !gccjit::is_loaded() {
236+
panic!("Could not load libgccjit.so. Attempted paths: {:#?}", attempted_paths);
229237
}
230238

231239
#[cfg(feature = "master")]

0 commit comments

Comments
 (0)