File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
223241message (STATUS "Adding MLX from submodule: ${MLX_SOURCE_DIR} " )
Original file line number Diff line number Diff line change 55# LICENSE file in the root directory of this source tree.
66
77set (CMAKE_POLICY_VERSION_MINIMUM 3.5)
8- if (NOT TARGET nlohmann_json)
9- add_subdirectory (json )
10- endif ()
8+ add_subdirectory (json )
119add_subdirectory (gflags )
1210
1311if (EXECUTORCH_BUILD_PYBIND)
You can’t perform that action at this time.
0 commit comments