fix: fail build when Metal compiler header resolution fails#3332
Open
dogukanveziroglu wants to merge 1 commit intoml-explore:mainfrom
Open
fix: fail build when Metal compiler header resolution fails#3332dogukanveziroglu wants to merge 1 commit intoml-explore:mainfrom
dogukanveziroglu wants to merge 1 commit intoml-explore:mainfrom
Conversation
When xcrun metal fails during JIT source generation (e.g. due to misconfigured Xcode CLI tools or missing SDK), the error messages are silently parsed as header file names. This causes critical headers like bf16.h to be omitted from the embedded Metal kernel sources, leading to runtime bfloat16_t type errors that are difficult to diagnose. Add validation after the Metal compiler header resolution step to detect malformed output and fail the build early with a clear error message instead of producing a broken binary.
e8800b1 to
bdd12fc
Compare
zcbenz
approved these changes
Mar 29, 2026
Collaborator
zcbenz
left a comment
There was a problem hiding this comment.
This is a very useful improvement, thanks!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
make_compiled_preamble.shsilently produces broken JIT Metal kernel sources whenxcrun -sdk macosx metalfails during the build (e.g. due to misconfigured Xcode CLI tools or missing SDK path).The script uses
xcrun metal -Hto resolve header dependencies, but never checks whether the command succeeded. When it fails, the error message words (e.g."error:","to","not","utility","or","developer","PATH") are parsed as header file names. This causes critical headers likebf16.h(which definestypedef bfloat bfloat16_t;) to be silently omitted from the embedded Metal kernel sourcesin
libmlx.dylib.The build completes successfully, but at runtime any operation requiring JIT Metal compilation (e.g.
gather_fronton bfloat16 tensors) fails with:RuntimeError: [metal::Device] Unable to build metal library from source
mlx/backend/metal/kernels/utils.h: error: unknown type name 'bfloat16_t'
This is extremely difficult to diagnose because:
bf16.hin the embedded source) is not visible from the error messageFix
Add validation after the
xcrun metal -Hcall to check that the output contains valid header dependency lines (starting with.characters). If invalid lines are detected, the build fails immediately with aclear error message pointing to the Metal toolchain configuration.
Checklist
pre-commit run --all-filesto format my code / installed pre-commit prior to committing changesNo test added — there is no existing test infrastructure for build shell scripts. The fix is a straightforward validation guard that fails early instead of silently continuing.