Skip to content

Commit 755e975

Browse files
committed
Fix issue rust-lang#96943
1 parent cd73afa commit 755e975

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3624,6 +3624,7 @@ dependencies = [
36243624
"itertools",
36253625
"jobserver",
36263626
"libc",
3627+
"libloading",
36273628
"object 0.28.4",
36283629
"pathdiff",
36293630
"regex",

compiler/rustc_codegen_ssa/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pathdiff = "0.2.0"
1919
snap = "1"
2020
smallvec = { version = "1.6.1", features = ["union", "may_dangle"] }
2121
regex = "1.4"
22+
libloading = "0.7.1"
2223

2324
rustc_serialize = { path = "../rustc_serialize" }
2425
rustc_arena = { path = "../rustc_arena" }

compiler/rustc_codegen_ssa/src/back/archive.rs

+12
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use rustc_session::Session;
44
use rustc_span::symbol::Symbol;
55

66
use std::io;
7+
use std::ffi::OsStr;
78
use std::path::{Path, PathBuf};
89

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

0 commit comments

Comments
 (0)