Skip to content

Commit

Permalink
Fix issue rust-lang#96943
Browse files Browse the repository at this point in the history
  • Loading branch information
adaszko committed May 20, 2022
1 parent cd73afa commit 755e975
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3624,6 +3624,7 @@ dependencies = [
"itertools",
"jobserver",
"libc",
"libloading",
"object 0.28.4",
"pathdiff",
"regex",
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_ssa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pathdiff = "0.2.0"
snap = "1"
smallvec = { version = "1.6.1", features = ["union", "may_dangle"] }
regex = "1.4"
libloading = "0.7.1"

rustc_serialize = { path = "../rustc_serialize" }
rustc_arena = { path = "../rustc_arena" }
Expand Down
12 changes: 12 additions & 0 deletions compiler/rustc_codegen_ssa/src/back/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use rustc_session::Session;
use rustc_span::symbol::Symbol;

use std::io;
use std::ffi::OsStr;
use std::path::{Path, PathBuf};

pub(super) fn find_library(
Expand Down Expand Up @@ -32,6 +33,17 @@ pub(super) fn find_library(
if test.exists() {
return test;
}
if cfg!(target_os = "macos") {
// This is a bit unintuitive: On macOS, a shared library may not be present on the file
// system yet still be loadable. This is due to the fact that there's a global cache of shared libraries being
// maintained by the system on BigSur and newer [1]. Therefore, as a last resort, try loading the library
// instead of just checking for its existence as a file.
// [1]: https://web.archive.org/web/20220317152936/https://developer.apple.com/documentation/macos-release-notes/macos-big-sur-11-beta-release-notes
let path: &OsStr = test.as_ref();
if let Ok(_) = unsafe { libloading::Library::new(path) } {
return test;
}
}
}
}
sess.fatal(&format!(
Expand Down

0 comments on commit 755e975

Please sign in to comment.