Skip to content

Commit 66076fc

Browse files
juntaoclaude
andcommitted
Link libclang_rt.osx.a for ___isPlatformVersionAtLeast symbol
Rust passes -nodefaultlibs to the linker, which excludes the compiler runtime that provides ___isPlatformVersionAtLeast. MLX C++ code uses @available() checks that reference this symbol. Explicitly find and link libclang_rt.osx.a via clang --print-file-name. Signed-off-by: Michael Yuan <michael@secondstate.io> Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Michael Yuan <michael@secondstate.io>
1 parent 5a4f545 commit 66076fc

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

build.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,22 @@ fn build_mlx() {
8888
// C++ standard library (MLX is C++)
8989
println!("cargo:rustc-link-lib=c++");
9090

91+
// MLX C++ code uses @available() checks that reference ___isPlatformVersionAtLeast
92+
// from the compiler runtime. Rust passes -nodefaultlibs to the linker, so the
93+
// compiler runtime is not automatically linked. We must explicitly link it.
94+
// Find the clang resource directory to locate libclang_rt.osx.a.
95+
let clang_rt = std::process::Command::new("clang")
96+
.args(["--print-file-name", "libclang_rt.osx.a"])
97+
.output()
98+
.expect("failed to run clang --print-file-name");
99+
let clang_rt_path = String::from_utf8(clang_rt.stdout)
100+
.expect("non-utf8 clang output")
101+
.trim()
102+
.to_string();
103+
if std::path::Path::new(&clang_rt_path).exists() {
104+
println!("cargo:rustc-link-arg={}", clang_rt_path);
105+
}
106+
91107
// Rerun if mlx-c sources change
92108
println!("cargo:rerun-if-changed=mlx-c/CMakeLists.txt");
93109
println!("cargo:rerun-if-changed=build.rs");

0 commit comments

Comments
 (0)