Skip to content

Commit a9511b9

Browse files
committed
When we cannot load libgccjit.so, show the paths that were tried
1 parent 95c38b2 commit a9511b9

File tree

1 file changed

+22
-3
lines changed
  • compiler/rustc_codegen_gcc/src

1 file changed

+22
-3
lines changed

compiler/rustc_codegen_gcc/src/lib.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ use rustc_middle::ty::TyCtxt;
9898
use rustc_middle::util::Providers;
9999
use rustc_session::Session;
100100
use rustc_session::config::{OptLevel, OutputFilenames};
101-
use rustc_session::filesearch::make_target_lib_path;
102101
use rustc_span::Symbol;
103102
use rustc_target::spec::{Arch, RelocModel};
104103
use tempfile::TempDir;
@@ -207,18 +206,38 @@ impl CodegenBackend for GccCodegenBackend {
207206
}
208207

209208
fn init(&self, sess: &Session) {
209+
fn file_path(sysroot_path: &Path, sess: &Session) -> PathBuf {
210+
let rustlib_path =
211+
rustc_target::relative_target_rustlib_path(sysroot_path, &sess.host.llvm_target);
212+
sysroot_path
213+
.join(rustlib_path)
214+
.join("codegen-backends")
215+
.join("lib")
216+
.join(sess.target.llvm_target.as_ref())
217+
.join("libgccjit.so")
218+
}
219+
210220
// We use all_paths() instead of only path() in case the path specified by --sysroot is
211221
// invalid.
212222
// This is the case for instance in Rust for Linux where they specify --sysroot=/dev/null.
213223
for path in sess.opts.sysroot.all_paths() {
214-
let libgccjit_target_lib_file =
215-
make_target_lib_path(path, &sess.target.llvm_target).join("libgccjit.so");
224+
let libgccjit_target_lib_file = file_path(path, sess);
216225
if let Ok(true) = fs::exists(&libgccjit_target_lib_file) {
217226
load_libgccjit_if_needed(&libgccjit_target_lib_file);
218227
break;
219228
}
220229
}
221230

231+
if !gccjit::is_loaded() {
232+
let mut paths = vec![];
233+
for path in sess.opts.sysroot.all_paths() {
234+
let libgccjit_target_lib_file = file_path(path, sess);
235+
paths.push(libgccjit_target_lib_file);
236+
}
237+
238+
panic!("Could not load libgccjit.so. Attempted paths: {:#?}", paths);
239+
}
240+
222241
#[cfg(feature = "master")]
223242
{
224243
let target_cpu = target_cpu(sess);

0 commit comments

Comments
 (0)