Skip to content

Commit afb677c

Browse files
committed
fix(ci): compile default.metallib from .metal sources instead of searching for binary
The .metal shader sources are tracked in git but default.metallib is gitignored (*.metallib rule). Previous approach searched for a pre-built binary that CI never has. Now compiles fresh from the 39 tracked .metal source files using xcrun metal + metallib — guaranteed version-matched to the Swift binary by construction since it uses the same source files.
1 parent 33e1511 commit afb677c

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

.github/workflows/release.yml

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,32 @@ jobs:
6969
file .build/release/SwiftLM
7070
.build/release/SwiftLM --help || true
7171
72-
- name: Find and copy default.metallib
72+
- name: Compile default.metallib from source
7373
run: |
74-
# default.metallib is a pre-built artifact shipped inside the
75-
# mlx-swift submodule — it is NOT produced by `swift build`.
76-
# Search the submodule tree for it (fallback to anywhere in repo).
77-
METALLIB=$(find LocalPackages -name "default.metallib" | head -1)
78-
if [ -z "$METALLIB" ]; then
79-
METALLIB=$(find . -name "default.metallib" -not -path "./.git/*" | head -1)
80-
fi
81-
if [ -z "$METALLIB" ]; then
82-
echo "ERROR: default.metallib not found — is mlx-swift submodule checked out?"
83-
exit 1
84-
fi
85-
echo "Found metallib: $METALLIB"
86-
cp "$METALLIB" default.metallib
74+
# The .metal shader sources are committed to git but the binary
75+
# output (default.metallib) is gitignored. Compile fresh from the
76+
# tracked sources so the metallib is version-matched to the Swift
77+
# binary by construction.
78+
KERNELS="LocalPackages/mlx-swift/Source/Cmlx/mlx/mlx/backend/metal/kernels"
79+
MLX_ROOT="LocalPackages/mlx-swift/Source/Cmlx/mlx"
80+
81+
echo "Compiling $(find "$KERNELS" -name '*.metal' | wc -l | tr -d ' ') Metal shaders..."
82+
mkdir -p /tmp/mlx_air
83+
84+
find "$KERNELS" -name "*.metal" | while read -r f; do
85+
name=$(basename "$f" .metal)
86+
xcrun -sdk macosx metal \
87+
-I "$KERNELS" \
88+
-I "$MLX_ROOT" \
89+
-c "$f" \
90+
-o "/tmp/mlx_air/${name}.air" 2>&1 || echo "WARN: failed to compile $f"
91+
done
92+
93+
AIR_COUNT=$(ls /tmp/mlx_air/*.air 2>/dev/null | wc -l | tr -d ' ')
94+
echo "Linking $AIR_COUNT .air files into default.metallib..."
95+
xcrun -sdk macosx metallib /tmp/mlx_air/*.air -o default.metallib
8796
file default.metallib
97+
ls -lh default.metallib
8898
8999
- name: Package binary
90100
run: |

0 commit comments

Comments
 (0)