Skip to content

Commit af169d7

Browse files
fix: consistent macOS deployment target for Metal compatibility
- Respects MACOSX_DEPLOYMENT_TARGET env var (defaults to 14.0) - Sets CMAKE_OSX_DEPLOYMENT_TARGET to match - Passes matching -mmacosx-version-min to linker - Adds cargo:rerun-if-env-changed for proper rebuilds Fixes ___isPlatformVersionAtLeast linking errors by ensuring all components (cmake, C++ compiler, Rust linker) use consistent target. Ref: ml-explore/mlx#1602
1 parent af21d79 commit af169d7

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

mlx-sys/build.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,20 @@ fn build_and_link_mlx_c() {
5353
config.define("CMAKE_C_COMPILER", "/usr/bin/cc");
5454
config.define("CMAKE_CXX_COMPILER", "/usr/bin/c++");
5555

56+
// Set macOS deployment target for Metal/MLX compatibility
57+
// Uses MACOSX_DEPLOYMENT_TARGET env var if set, otherwise defaults to 14.0
58+
// This avoids linking errors with ___isPlatformVersionAtLeast
59+
// See: https://github.com/ml-explore/mlx/issues/1602
60+
#[cfg(target_os = "macos")]
61+
{
62+
let deployment_target =
63+
env::var("MACOSX_DEPLOYMENT_TARGET").unwrap_or_else(|_| "14.0".to_string());
64+
config.define("CMAKE_OSX_DEPLOYMENT_TARGET", &deployment_target);
65+
// Ensure environment is set for compiler-rt symbols
66+
std::env::set_var("MACOSX_DEPLOYMENT_TARGET", &deployment_target);
67+
println!("cargo:rerun-if-env-changed=MACOSX_DEPLOYMENT_TARGET");
68+
}
69+
5670
#[cfg(debug_assertions)]
5771
{
5872
config.define("CMAKE_BUILD_TYPE", "Debug");
@@ -97,6 +111,18 @@ fn build_and_link_mlx_c() {
97111
println!("cargo:rustc-link-lib=framework=Accelerate");
98112
}
99113

114+
// Set minimum macOS version for linker to match compiled objects
115+
// Must match CMAKE_OSX_DEPLOYMENT_TARGET to avoid ___isPlatformVersionAtLeast errors
116+
#[cfg(target_os = "macos")]
117+
{
118+
let deployment_target =
119+
env::var("MACOSX_DEPLOYMENT_TARGET").unwrap_or_else(|_| "14.0".to_string());
120+
println!(
121+
"cargo:rustc-link-arg=-mmacosx-version-min={}",
122+
deployment_target
123+
);
124+
}
125+
100126
// Link against Xcode's clang runtime for ___isPlatformVersionAtLeast symbol
101127
// This is needed on macOS 26+ where the bundled LLVM runtime may be outdated
102128
// See: https://github.com/conda-forge/llvmdev-feedstock/issues/244

0 commit comments

Comments
 (0)