@@ -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