Skip to content

Instantly share code, notes, and snippets.

@pixelmatrix
Created October 9, 2025 18:05
Show Gist options
  • Select an option

  • Save pixelmatrix/86f8816c68fa1435e1a0124af894e651 to your computer and use it in GitHub Desktop.

Select an option

Save pixelmatrix/86f8816c68fa1435e1a0124af894e651 to your computer and use it in GitHub Desktop.
Pre-compile Metal shaders to avoid Xcode 26 CI issues
# Compile for device
xcrun -sdk iphoneos metal -o One.ir -c One.metal
xcrun -sdk iphoneos metal -o Two.ir -c Two.metal
xcrun -sdk iphoneos metallib -o Shaders-iphoneos.metallib One.ir Two.ir
rm One.ir
rm Two.ir
# Compile for simulator
xcrun -sdk iphonesimulator metal -o One.ir -c One.metal
xcrun -sdk iphonesimulator metal -o Two.ir -c Two.metal
xcrun -sdk iphonesimulator metallib -o Shaders-iphonesimulator.metallib One.ir Two.ir
rm One.ir
rm Two.ir
# Include the .metallib files in your app / package's bundle
import SwiftUI
extension ShaderLibrary {
// Important: Cache this instance. Initializing it is expensive.
static let library: ShaderLibrary = {
// Make sure to use the right binary based on the target
#if targetEnvironment(simulator)
let filename = "Shaders-iphonesimulator"
#else
let filename = "Shaders-iphoneos"
#endif
// Bundle.module is for Swift packages. Use whatever bundle contains your shader files.
guard let url = Bundle.module.url(forResource: filename, withExtension: "metallib") else {
fatalError("Missing shader library")
}
return ShaderLibrary(url: url)
}()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment