Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
Empty file.
3 changes: 2 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/third-party/ios-cmake/ios.toolchain.cmake",
"EXECUTORCH_BUILD_PRESET_FILE": "${sourceDir}/tools/cmake/preset/macos.cmake",
"PLATFORM": "MAC_ARM64",
"DEPLOYMENT_TARGET": "12.0",
"DEPLOYMENT_TARGET": "14.0",
"CMAKE_OSX_DEPLOYMENT_TARGET": "14.0",
"CMAKE_MACOSX_BUNDLE": "OFF"
},
"condition": {
Expand Down
18 changes: 15 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ let products = deliverables([
"sqlite3",
],
],
"backend_mlx": [
"frameworks": [
"Metal",
"MetalPerformanceShaders",
],
"forceLoad": true,
],
"backend_mps": [
"frameworks": [
"Metal",
Expand Down Expand Up @@ -113,15 +120,20 @@ for (key, value) in products {
name: key,
path: "cmake-out/\(key).xcframework"
))
let forceLoad = value["forceLoad"] as? Bool ?? false
var linkerSettings: [LinkerSetting] =
(value["frameworks"] as? [String] ?? []).map { .linkedFramework($0) } +
(value["libraries"] as? [String] ?? []).map { .linkedLibrary($0) }
if forceLoad {
linkerSettings.append(.unsafeFlags(["-all_load"]))
}
let target: Target = .target(
name: "\(key)\(dependencies_suffix)",
dependencies: ([key] + (value["targets"] as? [String] ?? []).map {
key.hasSuffix(debug_suffix) ? $0 + debug_suffix : $0
}).map { .target(name: $0) },
path: ".Package.swift/\(key)",
linkerSettings:
(value["frameworks"] as? [String] ?? []).map { .linkedFramework($0) } +
(value["libraries"] as? [String] ?? []).map { .linkedLibrary($0) }
linkerSettings: linkerSettings
)
packageTargets.append(target)
}
Expand Down
16 changes: 15 additions & 1 deletion backends/mlx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
Expand Down Expand Up @@ -212,10 +212,24 @@
CACHE BOOL "Use JIT compiled Metal kernels"
)

# For iOS builds, embed the metallib in the library so apps don't need to
# bundle it separately. This avoids the runtime "metallib not found" issue
# with static xcframeworks.
if(CMAKE_SYSTEM_NAME MATCHES "iOS")
set(MLX_EMBED_METALLIB
ON
CACHE BOOL "Embed metallib in static library for iOS" FORCE
)
message(STATUS "iOS build: embedding metallib in static library")
endif()

# Auto-apply patches to MLX submodule. Each patch is applied idempotently: `git
# apply --check` tests whether the patch is still applicable (i.e. not yet
# applied), and only then applies it.
set(_mlx_patches "${CMAKE_CURRENT_SOURCE_DIR}/patches/mlx_json.patch")
# Note: mlx_ios_metal.patch includes the json changes from mlx_json.patch
set(_mlx_patches
"${CMAKE_CURRENT_SOURCE_DIR}/patches/mlx_ios_metal.patch"
)
foreach(_patch IN LISTS _mlx_patches)
if(EXISTS "${_patch}" AND EXISTS "${MLX_SOURCE_DIR}")
get_filename_component(_patch_name "${_patch}" NAME)
Expand Down
Loading
Loading