Skip to content

Commit d6e114a

Browse files
Create new CG_LIBGCCJIT_PATH env variable to specify the path for libgccjit.so
1 parent b12c20c commit d6e114a

2 files changed

Lines changed: 20 additions & 18 deletions

File tree

build_system/src/config.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -402,13 +402,7 @@ impl ConfigInfo {
402402
} else {
403403
let commit = self.get_gcc_commit()?;
404404
let libgccjit_path = self.output_dir(&commit)?.join("libgccjit.so");
405-
let library_path = match env.get("LD_LIBRARY_PATH") {
406-
Some(library_path) if !library_path.is_empty() => {
407-
format!("{}:{library_path}", libgccjit_path.display())
408-
}
409-
_ => libgccjit_path.display().to_string(),
410-
};
411-
env.insert("LD_LIBRARY_PATH".into(), library_path);
405+
env.insert("CG_LIBGCCJIT_PATH".into(), libgccjit_path.display().to_string());
412406
}
413407
rustflags.push(format!("-Zcodegen-backend={}", self.cg_backend_path));
414408
}

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)