Last active
June 18, 2022 16:07
-
-
Save petertretyakov/3fe54fc12d7f585f27610841616e8b5f to your computer and use it in GitHub Desktop.
Build Metal Library from Shell
This file contains 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
#!/bin/bash | |
# This is a gist from | |
# mtldoc.com | |
# | |
# If you want to know what the hell is happening here check | |
# https://mtldoc.com/metal/2022/06/18/build-swift-executable-with-metal-library.html | |
# Create intermediate representation from Metal files | |
METAL_FILES=`ls /path/to/metal/files/*.metal` | |
for path in $METAL_FILES | |
do | |
FILE_NAME=${path%%.*} | |
xcrun -sdk macosx metal -c $path -o ${FILE_NAME}.air | |
done | |
# Archive AIR files to single MetalAR file | |
AIR_FILES=`ls /path/to/air/files/*.air` | |
for path in $AIR_FILES | |
do | |
xcrun metal-ar r default.metalar $path | |
done | |
# Build Metal Library from MetalAR archive | |
xcrun -sdk macosx metallib default.metalar -o default.metallib | |
# Clean up | |
rm default.metalar | |
for path in $AIR_FILES | |
do | |
rm $path | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment