Skip to content

Commit f79d8fa

Browse files
committed
draft
1 parent b8f0fa6 commit f79d8fa

14 files changed

Lines changed: 699 additions & 44 deletions

File tree

.Package.swift/backend_mlx/dummy.swift

Whitespace-only changes.

.Package.swift/backend_mlx_debug/dummy.swift

Whitespace-only changes.

CMakePresets.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/third-party/ios-cmake/ios.toolchain.cmake",
4646
"EXECUTORCH_BUILD_PRESET_FILE": "${sourceDir}/tools/cmake/preset/macos.cmake",
4747
"PLATFORM": "MAC_ARM64",
48-
"DEPLOYMENT_TARGET": "12.0",
48+
"DEPLOYMENT_TARGET": "14.0",
49+
"CMAKE_OSX_DEPLOYMENT_TARGET": "14.0",
4950
"CMAKE_MACOSX_BUNDLE": "OFF"
5051
},
5152
"condition": {

Package.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ let products = deliverables([
5252
"sqlite3",
5353
],
5454
],
55+
"backend_mlx": [
56+
"frameworks": [
57+
"Metal",
58+
"MetalPerformanceShaders",
59+
],
60+
"forceLoad": true,
61+
],
5562
"backend_mps": [
5663
"frameworks": [
5764
"Metal",
@@ -113,15 +120,20 @@ for (key, value) in products {
113120
name: key,
114121
path: "cmake-out/\(key).xcframework"
115122
))
123+
let forceLoad = value["forceLoad"] as? Bool ?? false
124+
var linkerSettings: [LinkerSetting] =
125+
(value["frameworks"] as? [String] ?? []).map { .linkedFramework($0) } +
126+
(value["libraries"] as? [String] ?? []).map { .linkedLibrary($0) }
127+
if forceLoad {
128+
linkerSettings.append(.unsafeFlags(["-all_load"]))
129+
}
116130
let target: Target = .target(
117131
name: "\(key)\(dependencies_suffix)",
118132
dependencies: ([key] + (value["targets"] as? [String] ?? []).map {
119133
key.hasSuffix(debug_suffix) ? $0 + debug_suffix : $0
120134
}).map { .target(name: $0) },
121135
path: ".Package.swift/\(key)",
122-
linkerSettings:
123-
(value["frameworks"] as? [String] ?? []).map { .linkedFramework($0) } +
124-
(value["libraries"] as? [String] ?? []).map { .linkedLibrary($0) }
136+
linkerSettings: linkerSettings
125137
)
126138
packageTargets.append(target)
127139
}

backends/mlx/CMakeLists.txt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,24 @@ set(MLX_METAL_JIT
212212
CACHE BOOL "Use JIT compiled Metal kernels"
213213
)
214214

215+
# For iOS builds, embed the metallib in the library so apps don't need to
216+
# bundle it separately. This avoids the runtime "metallib not found" issue
217+
# with static xcframeworks.
218+
if(CMAKE_SYSTEM_NAME MATCHES "iOS")
219+
set(MLX_EMBED_METALLIB
220+
ON
221+
CACHE BOOL "Embed metallib in static library for iOS" FORCE
222+
)
223+
message(STATUS "iOS build: embedding metallib in static library")
224+
endif()
225+
215226
# Auto-apply patches to MLX submodule. Each patch is applied idempotently: `git
216227
# apply --check` tests whether the patch is still applicable (i.e. not yet
217228
# applied), and only then applies it.
218-
set(_mlx_patches "${CMAKE_CURRENT_SOURCE_DIR}/patches/mlx_json.patch")
229+
# Note: mlx_ios_metal.patch includes the json changes from mlx_json.patch
230+
set(_mlx_patches
231+
"${CMAKE_CURRENT_SOURCE_DIR}/patches/mlx_ios_metal.patch"
232+
)
219233
foreach(_patch IN LISTS _mlx_patches)
220234
if(EXISTS "${_patch}" AND EXISTS "${MLX_SOURCE_DIR}")
221235
get_filename_component(_patch_name "${_patch}" NAME)

0 commit comments

Comments
 (0)