Skip to content

Commit b98831a

Browse files
fix: fail build when Metal compiler header resolution fails (#3332)
1 parent d025111 commit b98831a

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

mlx/backend/metal/make_compiled_preamble.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,22 @@ mkdir -p "$OUTPUT_DIR"
3434
CCC="xcrun -sdk macosx metal -x metal"
3535
HDRS=$( $CCC -I"$SRC_DIR" -I"$JIT_INCLUDES" -DMLX_METAL_JIT -E -P -CC -C -H "$INPUT_FILE" $CFLAGS -w 2>&1 1>/dev/null )
3636

37+
# Fail early if the Metal compiler returned errors instead of header paths.
38+
# Valid lines start with '.' chars (depth indicators); anything else means
39+
# xcrun/metal failed (e.g. missing SDK, misconfigured toolchain).
40+
if [ -n "$HDRS" ]; then
41+
invalid_lines=$(echo "$HDRS" | grep -v '^\.*\.' || true)
42+
if [ -n "$invalid_lines" ]; then
43+
echo "Error: Metal compiler header resolution failed for ${INPUT_FILE}" >&2
44+
echo "Expected lines starting with '.' but got:" >&2
45+
echo "$invalid_lines" >&2
46+
echo "" >&2
47+
echo "This usually means xcrun or the Metal toolchain is not configured correctly." >&2
48+
echo "Try running: xcrun -sdk macosx metal --version" >&2
49+
exit 1
50+
fi
51+
fi
52+
3753
# Remove any included system frameworks (for MetalPerformancePrimitive headers)
3854
HDRS=$(echo "$HDRS" | grep -v "Xcode")
3955

0 commit comments

Comments
 (0)