Skip to content

Commit cc0a110

Browse files
committed
up
1 parent 89f202d commit cc0a110

2 files changed

Lines changed: 25 additions & 9 deletions

File tree

backends/mlx/CMakeLists.txt

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,30 @@ set(MLX_METAL_JIT
212212
CACHE BOOL "Use JIT compiled Metal kernels"
213213
)
214214

215-
# Pre-populate json FetchContent to use ET's copy. MLX unconditionally calls
216-
# FetchContent_MakeAvailable(json) which would conflict with ET's
217-
# third-party/json. By pre-populating, CMake skips MLX's download.
218-
include(FetchContent)
219-
FetchContent_Declare(json SOURCE_DIR ${EXECUTORCH_ROOT}/third-party/json)
220-
FetchContent_MakeAvailable(json)
215+
# Auto-apply json patch so MLX reuses executorch's nlohmann_json instead of
216+
# downloading its own copy via FetchContent. TODO: upstream a patch to MLX
217+
set(MLX_JSON_PATCH "${CMAKE_CURRENT_SOURCE_DIR}/patches/mlx_json.patch")
218+
if(EXISTS "${MLX_JSON_PATCH}" AND EXISTS "${MLX_SOURCE_DIR}")
219+
execute_process(
220+
COMMAND git apply --check ${MLX_JSON_PATCH}
221+
WORKING_DIRECTORY ${MLX_SOURCE_DIR}
222+
RESULT_VARIABLE _mlx_json_patch_check
223+
OUTPUT_QUIET ERROR_QUIET
224+
)
225+
if(_mlx_json_patch_check EQUAL 0)
226+
execute_process(
227+
COMMAND git apply ${MLX_JSON_PATCH} WORKING_DIRECTORY ${MLX_SOURCE_DIR}
228+
)
229+
message(STATUS "Applied mlx_json.patch to MLX submodule")
230+
else()
231+
message(STATUS "mlx_json.patch already applied or not applicable")
232+
endif()
233+
endif()
234+
235+
# Provide executorch's nlohmann_json so the patched MLX skips its own download
236+
add_subdirectory(
237+
${EXECUTORCH_ROOT}/third-party/json ${CMAKE_CURRENT_BINARY_DIR}/nlohmann_json
238+
)
221239

222240
# Add MLX subdirectory
223241
message(STATUS "Adding MLX from submodule: ${MLX_SOURCE_DIR}")

third-party/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
# LICENSE file in the root directory of this source tree.
66

77
set(CMAKE_POLICY_VERSION_MINIMUM 3.5)
8-
if(NOT TARGET nlohmann_json)
9-
add_subdirectory(json)
10-
endif()
8+
add_subdirectory(json)
119
add_subdirectory(gflags)
1210

1311
if(EXECUTORCH_BUILD_PYBIND)

0 commit comments

Comments
 (0)