@@ -5,9 +5,10 @@ enum MetalCompiler {
55 /// Compiles any metal shaders present in a directory into a `default.metallib` file (in the same directory).
66 /// - Parameters:
77 /// - directory: The directory to compile shaders from.
8+ /// - minimumMacOSVersion: The macOS version that the built shaders should target.
89 /// - keepSources: If `false`, the sources will get deleted after compilation.
910 /// - Returns: If an error occurs, a failure is returned.
10- static func compileMetalShaders( in directory: URL , keepSources: Bool ) -> Result < Void , MetalCompilerError > {
11+ static func compileMetalShaders( in directory: URL , minimumMacOSVersion : String , keepSources: Bool ) -> Result < Void , MetalCompilerError > {
1112 guard let enumerator = FileManager . default. enumerator ( at: directory, includingPropertiesForKeys: [ ] ) else {
1213 return . failure( . failedToEnumerateShaders( directory: directory) )
1314 }
@@ -24,7 +25,7 @@ enum MetalCompiler {
2425 log. info ( " Compiling metal shaders " )
2526
2627 // Compile metal shaders, and if successful, delete all shader sources
27- return compileMetalShaders ( shaderSources, destination: directory)
28+ return compileMetalShaders ( shaderSources, destination: directory, minimumMacOSVersion : minimumMacOSVersion )
2829 . flatMap { _ in
2930 if keepSources {
3031 return . success( )
@@ -46,8 +47,9 @@ enum MetalCompiler {
4647 /// - Parameters:
4748 /// - sources: The source files to comile.
4849 /// - destination: The directory to output `default.metallib` to.
50+ /// - minimumMacOSVersion: The macOS version that the built shaders should target.
4951 /// - Returns: Returns the location of the resulting `metallib`. If an error occurs, a failure is returned.
50- static func compileMetalShaders( _ sources: [ URL ] , destination: URL ) -> Result < URL , MetalCompilerError > {
52+ static func compileMetalShaders( _ sources: [ URL ] , destination: URL , minimumMacOSVersion : String ) -> Result < URL , MetalCompilerError > {
5153 // Create a temporary directory for compilation
5254 let tempDirectory = FileManager . default. temporaryDirectory
5355 . appendingPathComponent ( " metal_compilation- \( UUID ( ) . uuidString) " )
@@ -62,7 +64,7 @@ enum MetalCompiler {
6264 for shaderSource in sources {
6365 let outputFileName = shaderSource. deletingPathExtension ( ) . appendingPathExtension ( " air " ) . lastPathComponent
6466 let outputFile = tempDirectory. appendingPathComponent ( outputFileName)
65- if case let . failure( error) = compileShader ( shaderSource, to: outputFile) {
67+ if case let . failure( error) = compileShader ( shaderSource, to: outputFile, minimumMacOSVersion : minimumMacOSVersion ) {
6668 return . failure( error)
6769 }
6870 airFiles. append ( outputFile)
@@ -89,12 +91,14 @@ enum MetalCompiler {
8991 /// - Parameters:
9092 /// - shader: The shader file to compile.
9193 /// - outputFile: The resulting `air` file.
94+ /// - minimumMacOSVersion: The macOS version that the built shader should target.
9295 /// - Returns: If an error occurs, a failure is returned.
93- static func compileShader( _ shader: URL , to outputFile: URL ) -> Result < Void , MetalCompilerError > {
96+ static func compileShader( _ shader: URL , to outputFile: URL , minimumMacOSVersion : String ) -> Result < Void , MetalCompilerError > {
9497 let process = Process . create (
9598 " /usr/bin/xcrun " ,
9699 arguments: [
97100 " -sdk " , " macosx " , " metal " ,
101+ " -mmacosx-version-min= \( minimumMacOSVersion) " ,
98102 " -o " , outputFile. path,
99103 " -c " , shader. path
100104 ] )
0 commit comments