mlx icon indicating copy to clipboard operation
mlx copied to clipboard

[BUG] Building MLX from source fails on macOS with SDK 26.2+

Open elamribadrayour opened this issue 11 months ago • 20 comments

Describe the bug Building MLX from source fails on macOS with SDK 26.2+ because the build system attempts to compile the JACCL (RDMA over Thunderbolt) backend without checking if the required infiniband/verbs.h header is available.

To Reproduce

  1. Use a system with macOS SDK 26.2 (Sequoia/Internal)
  2. Run the build command:
pip install -e .
  1. Error output:
/mlx/mlx/distributed/jaccl/jaccl.cpp:4:10: fatal error: 'infiniband/verbs.h' file not found
    4 | #include <infiniband/verbs.h>
      |          ^~~~~~~~~~~~~~~~~~~~
1 error generated.

Expected behavior The build should succeed even if InfiniBand headers are missing. The build system should detect the missing header and fall back to the no_jaccl implementation or disable the JACCL backend gracefully.

Desktop:

  • OS Version: MacOS 15/16 (Darwin 25.1.0 / SDK 26.2)
  • Version: 0.30.1 / 0.30.3 (main branch)

Additional context The issue is located in mlx/mlx/distributed/jaccl/CMakeLists.txt. It currently enables JACCL compilation based solely on the SDK version:

if(MLX_BUILD_CPU
   AND ${CMAKE_SYSTEM_NAME} MATCHES "Darwin"
   AND MACOS_SDK_VERSION GREATER_EQUAL 26.2)
  target_sources(mlx PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/jaccl.cpp)

elamribadrayour avatar Dec 28 '25 08:12 elamribadrayour

Hmm - did you install a beta Xcode? If so you probably need to update. The headers should be in the 26.2 macos SDK.

awni avatar Dec 29 '25 14:12 awni

I tried to reproduce and I also get a failure but interestingly I see this:

  CMake Error at CMakeLists.txt:62 (message):
    Building for x86_64 on macOS is not supported.  If you are on an Apple
    silicon system, check the build documentation for possible fixes:
    https://ml-explore.github.io/mlx/build/html/install.html#build-from-source

Is it possible that the issue is that you are using pip?

I don't see this clearly in the documentation, perhaps it's a documentation issue?

MillaFleurs avatar Jan 04 '26 02:01 MillaFleurs

Closing this as inactive.. if you are still encountering issues comment and we can reopen.

awni avatar Jan 05 '26 20:01 awni

I am still seeing this with 26.2:

             -- Building MLX for arm64 processor on Darwin
             -- Found CCache: /opt/homebrew/bin/ccache
             -- Metal found /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Metal.framework
             -- Building with macOS SDK version 26.2
             [stderr]
             /Users/morbo/.cache/uv/git-v0/checkouts/de1ab1497d110129/50373172/mlx/distributed/jaccl/jaccl.cpp:4:10: fatal error: 'infiniband/verbs.h' file not found
                 4 | #include <infiniband/verbs.h>
                   |          ^~~~~~~~~~~~~~~~~~~~
             1 error generated.

gcp avatar Jan 06 '26 18:01 gcp

Can you share your macOS version and xcode versions? E.g. the output of:

sw_vers
xcodebuild -version

awni avatar Jan 06 '26 18:01 awni

morbo@MacBook-Pro-3:~/git/firefox % sw_vers
ProductName:		macOS
ProductVersion:		26.1
BuildVersion:		25B78
morbo@MacBook-Pro-3:~/git/firefox % xcodebuild -version
Xcode 26.2
Build version 17C52

gcp avatar Jan 06 '26 18:01 gcp

Just to be sure, can you check if this directory exists: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/infiniband/verbs.h ?

It should be there with your xcode so I'm scratching my head as to why it isn't..

awni avatar Jan 06 '26 18:01 awni

It does exist: -rw-r--r-- 1 root wheel 42086 nov. 9 03:07 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/infiniband/verbs.h

gcp avatar Jan 06 '26 19:01 gcp

I am doing uv tool update --all when this error happens.

   Building mlx @ git+https://github.com/ml-explore/mlx@503731727df0fb8223db0f5137dcc426a7d96ad1
⠙ Preparing packages... (0/1)

gcp avatar Jan 06 '26 19:01 gcp

Huh.. maybe uv has a build cache or something and it's using a stale environment. Maybe try:

uv tool update --all --no-cache

and/or remove the cache:

uv cache clean

awni avatar Jan 06 '26 19:01 awni

Fails in the same way (note the lack of cache in the path now):

             /private/var/folders/nl/fzthj2pn19z4sx2m4yh3_7c00000gp/T/.tmpnsnhiJ/git-v0/checkouts/de1ab1497d110129/50373172/mlx/distributed/jaccl/jaccl.cpp:4:10: fatal error: 'infiniband/verbs.h' file not found
                 4 | #include <infiniband/verbs.h>

I had guessed something similar and emptied the ccache cache, but no dice.

gcp avatar Jan 06 '26 20:01 gcp

What's the best way to log the full compiler commandline invocation?

gcp avatar Jan 06 '26 20:01 gcp

Something like that:

VERBOSE=1 pip install -e . --verbose

awni avatar Jan 06 '26 20:01 awni

    [ 63%] Building CXX object CMakeFiles/mlx.dir/mlx/distributed/jaccl/jaccl.cpp.o
     /opt/homebrew/bin/ccache /usr/bin/c++ -DACCELERATE_NEW_LAPACK -DFMT_HEADER_ONLY=1
     -DMETAL_PATH=\"/private/var/folders/nl/fzthj2pn19z4sx2m4yh3_7c00000gp/T/tmp40bbrh5l.build-temp/mlx.core/mlx/backend/metal/kernels//mlx.metallib\"
     -DMLX_USE_ACCELERATE
     -I/private/var/folders/nl/fzthj2pn19z4sx2m4yh3_7c00000gp/T/tmp40bbrh5l.build-temp/mlx.core/_deps/metal_cpp-src
     -I/private/var/folders/nl/fzthj2pn19z4sx2m4yh3_7c00000gp/T/tmp40bbrh5l.build-temp/mlx.core/_deps/json-src/single_include/nlohmann
     -I/private/var/folders/nl/fzthj2pn19z4sx2m4yh3_7c00000gp/T/tmp40bbrh5l.build-temp/mlx.core/_deps/gguflib-src
     -I/Users/morbo/git/mlx
     -I/private/var/folders/nl/fzthj2pn19z4sx2m4yh3_7c00000gp/T/tmp40bbrh5l.build-temp/mlx.core/_deps/fmt-src/include
     -F/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks -O3 -DNDEBUG -std=gnu++17
     -arch arm64 -fPIC -Wno-psabi -MD -MT CMakeFiles/mlx.dir/mlx/distributed/jaccl/jaccl.cpp.o -MF
     CMakeFiles/mlx.dir/mlx/distributed/jaccl/jaccl.cpp.o.d -o CMakeFiles/mlx.dir/mlx/distributed/jaccl/jaccl.cpp.o -c
     /Users/morbo/git/mlx/mlx/distributed/jaccl/jaccl.cpp
     [ 63%] Building CXX object CMakeFiles/mlx.dir/mlx/io/load.cpp.o
     /opt/homebrew/bin/ccache /usr/bin/c++ -DACCELERATE_NEW_LAPACK -DFMT_HEADER_ONLY=1
     -DMETAL_PATH=\"/private/var/folders/nl/fzthj2pn19z4sx2m4yh3_7c00000gp/T/tmp40bbrh5l.build-temp/mlx.core/mlx/backend/metal/kernels//mlx.metallib\"
     -DMLX_USE_ACCELERATE
     -I/private/var/folders/nl/fzthj2pn19z4sx2m4yh3_7c00000gp/T/tmp40bbrh5l.build-temp/mlx.core/_deps/metal_cpp-src
     -I/private/var/folders/nl/fzthj2pn19z4sx2m4yh3_7c00000gp/T/tmp40bbrh5l.build-temp/mlx.core/_deps/json-src/single_include/nlohmann
     -I/private/var/folders/nl/fzthj2pn19z4sx2m4yh3_7c00000gp/T/tmp40bbrh5l.build-temp/mlx.core/_deps/gguflib-src
     -I/Users/morbo/git/mlx
     -I/private/var/folders/nl/fzthj2pn19z4sx2m4yh3_7c00000gp/T/tmp40bbrh5l.build-temp/mlx.core/_deps/fmt-src/include
     -F/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks -O3 -DNDEBUG -std=gnu++17 -arch
     arm64 -fPIC -Wno-psabi -MD -MT CMakeFiles/mlx.dir/mlx/io/load.cpp.o -MF CMakeFiles/mlx.dir/mlx/io/load.cpp.o.d -o
     CMakeFiles/mlx.dir/mlx/io/load.cpp.o -c /Users/morbo/git/mlx/mlx/io/load.cpp
     [ 64%] Building CXX object CMakeFiles/mlx.dir/mlx/io/safetensors.cpp.o
     /opt/homebrew/bin/ccache /usr/bin/c++ -DACCELERATE_NEW_LAPACK -DFMT_HEADER_ONLY=1
     -DMETAL_PATH=\"/private/var/folders/nl/fzthj2pn19z4sx2m4yh3_7c00000gp/T/tmp40bbrh5l.build-temp/mlx.core/mlx/backend/metal/kernels//mlx.metallib\"
     -DMLX_USE_ACCELERATE
     -I/private/var/folders/nl/fzthj2pn19z4sx2m4yh3_7c00000gp/T/tmp40bbrh5l.build-temp/mlx.core/_deps/metal_cpp-src
     -I/private/var/folders/nl/fzthj2pn19z4sx2m4yh3_7c00000gp/T/tmp40bbrh5l.build-temp/mlx.core/_deps/json-src/single_include/nlohmann
     -I/private/var/folders/nl/fzthj2pn19z4sx2m4yh3_7c00000gp/T/tmp40bbrh5l.build-temp/mlx.core/_deps/gguflib-src
     -I/Users/morbo/git/mlx
     -I/private/var/folders/nl/fzthj2pn19z4sx2m4yh3_7c00000gp/T/tmp40bbrh5l.build-temp/mlx.core/_deps/fmt-src/include
     -F/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks -O3 -DNDEBUG
     -std=gnu++17 -arch arm64 -fPIC -Wno-psabi -MD -MT CMakeFiles/mlx.dir/mlx/io/safetensors.cpp.o -MF
     CMakeFiles/mlx.dir/mlx/io/safetensors.cpp.o.d -o CMakeFiles/mlx.dir/mlx/io/safetensors.cpp.o -c
     /Users/morbo/git/mlx/mlx/io/safetensors.cpp
     [ 64%] Building CXX object CMakeFiles/mlx.dir/mlx/io/gguf.cpp.o
     /opt/homebrew/bin/ccache /usr/bin/c++ -DACCELERATE_NEW_LAPACK -DFMT_HEADER_ONLY=1
     -DMETAL_PATH=\"/private/var/folders/nl/fzthj2pn19z4sx2m4yh3_7c00000gp/T/tmp40bbrh5l.build-temp/mlx.core/mlx/backend/metal/kernels//mlx.metallib\"
     -DMLX_USE_ACCELERATE
     -I/private/var/folders/nl/fzthj2pn19z4sx2m4yh3_7c00000gp/T/tmp40bbrh5l.build-temp/mlx.core/_deps/metal_cpp-src
     -I/private/var/folders/nl/fzthj2pn19z4sx2m4yh3_7c00000gp/T/tmp40bbrh5l.build-temp/mlx.core/_deps/json-src/single_include/nlohmann
     -I/private/var/folders/nl/fzthj2pn19z4sx2m4yh3_7c00000gp/T/tmp40bbrh5l.build-temp/mlx.core/_deps/gguflib-src
     -I/Users/morbo/git/mlx
     -I/private/var/folders/nl/fzthj2pn19z4sx2m4yh3_7c00000gp/T/tmp40bbrh5l.build-temp/mlx.core/_deps/fmt-src/include
     -F/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks -O3 -DNDEBUG -std=gnu++17 -arch
     arm64 -fPIC -Wno-psabi -MD -MT CMakeFiles/mlx.dir/mlx/io/gguf.cpp.o -MF CMakeFiles/mlx.dir/mlx/io/gguf.cpp.o.d -o
     CMakeFiles/mlx.dir/mlx/io/gguf.cpp.o -c /Users/morbo/git/mlx/mlx/io/gguf.cpp


     [stderr]
     /Users/morbo/git/mlx/mlx/distributed/jaccl/jaccl.cpp:4:10: fatal error: 'infiniband/verbs.h' file not found
         4 | #include <infiniband/verbs.h>
           |          ^~~~~~~~~~~~~~~~~~~~
     1 error generated.
     make[2]: *** [CMakeFiles/mlx.dir/mlx/distributed/jaccl/jaccl.cpp.o] Error 1
     make[2]: *** Waiting for unfinished jobs....
     make[1]: *** [CMakeFiles/mlx.dir/all] Error 2
     make: *** [all] Error 2
     Traceback (most recent call last):
       File "<string>", line 11, in <module>
       File "/Users/morbo/.cache/uv/builds-v0/.tmp1iLGy2/lib/python3.12/site-packages/setuptools/build_meta.py", line
     468, in build_editable
         return self._build_with_temp_dir(
                ^^^^^^^^^^^^^^^^^^^^^^^^^^
       File "/Users/morbo/.cache/uv/builds-v0/.tmp1iLGy2/lib/python3.12/site-packages/setuptools/build_meta.py", line
     404, in _build_with_temp_dir
         self.run_setup()
       File "/Users/morbo/.cache/uv/builds-v0/.tmp1iLGy2/lib/python3.12/site-packages/setuptools/build_meta.py", line
     317, in run_setup
         exec(code, locals())
       File "<string>", line 278, in <module>
       File "/Users/morbo/.cache/uv/builds-v0/.tmp1iLGy2/lib/python3.12/site-packages/setuptools/__init__.py", line
     115, in setup
         return distutils.core.setup(**attrs)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       File "/Users/morbo/.cache/uv/builds-v0/.tmp1iLGy2/lib/python3.12/site-packages/setuptools/_distutils/core.py",
     line 186, in setup
         return run_commands(dist)
                ^^^^^^^^^^^^^^^^^^
       File "/Users/morbo/.cache/uv/builds-v0/.tmp1iLGy2/lib/python3.12/site-packages/setuptools/_distutils/core.py",
     line 202, in run_commands
         dist.run_commands()
       File "/Users/morbo/.cache/uv/builds-v0/.tmp1iLGy2/lib/python3.12/site-packages/setuptools/_distutils/dist.py",
     line 1002, in run_commands
         self.run_command(cmd)
       File "/Users/morbo/.cache/uv/builds-v0/.tmp1iLGy2/lib/python3.12/site-packages/setuptools/dist.py", line 1102,
     in run_command
         super().run_command(command)
       File "/Users/morbo/.cache/uv/builds-v0/.tmp1iLGy2/lib/python3.12/site-packages/setuptools/_distutils/dist.py",
     line 1021, in run_command
         cmd_obj.run()
       File "/Users/morbo/.cache/uv/builds-v0/.tmp1iLGy2/lib/python3.12/site-packages/setuptools/command/editable_wheel.py",
     line 139, in run
         self._create_wheel_file(bdist_wheel)
       File "/Users/morbo/.cache/uv/builds-v0/.tmp1iLGy2/lib/python3.12/site-packages/setuptools/command/editable_wheel.py",
     line 349, in _create_wheel_file
         files, mapping = self._run_build_commands(dist_name, unpacked, lib, tmp)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       File "/Users/morbo/.cache/uv/builds-v0/.tmp1iLGy2/lib/python3.12/site-packages/setuptools/command/editable_wheel.py",
     line 272, in _run_build_commands
         self._run_build_subcommands()
       File "/Users/morbo/.cache/uv/builds-v0/.tmp1iLGy2/lib/python3.12/site-packages/setuptools/command/editable_wheel.py",
     line 299, in _run_build_subcommands
         self.run_command(name)
       File "/Users/morbo/.cache/uv/builds-v0/.tmp1iLGy2/lib/python3.12/site-packages/setuptools/_distutils/cmd.py",
     line 357, in run_command
         self.distribution.run_command(command)
       File "/Users/morbo/.cache/uv/builds-v0/.tmp1iLGy2/lib/python3.12/site-packages/setuptools/dist.py", line 1102,
     in run_command
         super().run_command(command)
       File "/Users/morbo/.cache/uv/builds-v0/.tmp1iLGy2/lib/python3.12/site-packages/setuptools/_distutils/dist.py",
     line 1021, in run_command
         cmd_obj.run()
       File "<string>", line 156, in run
       File "/Users/morbo/.cache/uv/builds-v0/.tmp1iLGy2/lib/python3.12/site-packages/setuptools/command/build_ext.py",
     line 96, in run
         _build_ext.run(self)
       File
     "/Users/morbo/.cache/uv/builds-v0/.tmp1iLGy2/lib/python3.12/site-packages/setuptools/_distutils/command/build_ext.py",
     line 368, in run
         self.build_extensions()
       File
     "/Users/morbo/.cache/uv/builds-v0/.tmp1iLGy2/lib/python3.12/site-packages/setuptools/_distutils/command/build_ext.py",
     line 484, in build_extensions
         self._build_extensions_serial()
       File
     "/Users/morbo/.cache/uv/builds-v0/.tmp1iLGy2/lib/python3.12/site-packages/setuptools/_distutils/command/build_ext.py",
     line 510, in _build_extensions_serial
         self.build_extension(ext)
       File "<string>", line 148, in build_extension
       File "/Users/morbo/.local/share/uv/python/cpython-3.12.0-macos-aarch64-none/lib/python3.12/subprocess.py", line
     571, in run
         raise CalledProcessError(retcode, process.args,
     subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--target', 'install', '--config', 'Release',
     '-j14']' returned non-zero exit status 2.
     An error occurred when building editable wheel for mlx.
     See debugging tips in: https://setuptools.pypa.io/en/latest/userguide/development_mode.html#debugging-tips

gcp avatar Jan 06 '26 20:01 gcp

My recommendation would be to try building a fresh clone of MLX in a fresh environment following the build from source instructions.

If that works then the issue is likely something in your environment (not the OS, xcode, or MLX) and then it's a matter of fixing that (or start from scratch if easier).

awni avatar Jan 06 '26 21:01 awni

That fails in exactly the same way, i.e. I do git clone, python3 -m venv venv, source bin/activate, VERBOSE=1 pip install -e . --verbose and it fails as above.

The compiler invocation is: /opt/homebrew/bin/ccache /usr/bin/c++ -DACCELERATE_NEW_LAPACK -DFMT_HEADER_ONLY=1 -DMETAL_PATH=\"/private/var/folders/nl/fzthj2pn19z4sx2m4yh3_7c00000gp/T/tmpqcwji5i6.build-temp/mlx.core/mlx/backend/metal/kernels//mlx.metallib\" -DMLX_USE_ACCELERATE -I/private/var/folders/nl/fzthj2pn19z4sx2m4yh3_7c00000gp/T/tmpqcwji5i6.build-temp/mlx.core/_deps/metal_cpp-src -I/private/var/folders/nl/fzthj2pn19z4sx2m4yh3_7c00000gp/T/tmpqcwji5i6.build-temp/mlx.core/_deps/json-src/single_include/nlohmann -I/private/var/folders/nl/fzthj2pn19z4sx2m4yh3_7c00000gp/T/tmpqcwji5i6.build-temp/mlx.core/_deps/gguflib-src -I/Users/morbo/git/mlx -I/private/var/folders/nl/fzthj2pn19z4sx2m4yh3_7c00000gp/T/tmpqcwji5i6.build-temp/mlx.core/_deps/fmt-src/include -F/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks -O3 -DNDEBUG -std=gnu++17 -arch arm64 -fPIC -Wno-psabi -MD -MT CMakeFiles/mlx.dir/mlx/distributed/jaccl/jaccl.cpp.o -MF CMakeFiles/mlx.dir/mlx/distributed/jaccl/jaccl.cpp.o.d -o CMakeFiles/mlx.dir/mlx/distributed/jaccl/jaccl.cpp.o -c /Users/morbo/git/mlx/mlx/distributed/jaccl/jaccl.cpp

gcp avatar Jan 06 '26 21:01 gcp

Can you check echo $CC $CXX? I see it's still building with ccache and it would be good to turn that off to be sure.

If those variables are set, unset them unset CC CXX.

awni avatar Jan 06 '26 21:01 awni

I had the same thought, and uninstalled ccache, but no, same error.

gcp avatar Jan 06 '26 21:01 gcp

echo $CC $CXX returns empty

gcp avatar Jan 06 '26 21:01 gcp

Okay, I found the problem I think: The Xcode command line tools are at version 26.1, so they have the 26.1 SDK in the include paths (/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/), which doesn't have that file. The macOS SDK is at 26.2 (/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include). The configure for mlx checks the macOS SDK, so it thinks the header is there, even though it won't be when actually building.

Confirmed softwareupdate --install "Command Line Tools for Xcode 26.2-26.2" works around this issue, but I think this is really a bug in your configure check.

gcp avatar Jan 06 '26 21:01 gcp