-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Provide the downloadable metal toolchain to swiftbuild #9434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+241
−12
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
309c61a
Provide the downloadable metal toolchain to swiftbuild
rconnell9 a142508
Register metal toolchain using EXTERNAL_TOOLCHAINS_DIR
rconnell9 ca6ff3d
Update metal tests to only run on macOS
rconnell9 2aa9f96
Fix missing initializer
rconnell9 971c316
Use xcrun --find to discover metal toolchain
rconnell9 7a94da3
Clean up how we update the TOOLCHAINS build setting
rconnell9 f8cf09d
Clean up how we update the TOOLCHAINS build setting
rconnell9 7ed2c5c
Require downloadable Metal toolchain in CI in order to enable Metal t…
rconnell9 d2e70e8
Use #require when creating the MTLCreateSystemDefaultDevice
rconnell9 66e402a
import Metal only on macOS
rconnell9 9ffbb30
Merge remote-tracking branch 'source/main' into rconnell/metal-toolchain
rconnell9 45da289
Merge remote-tracking branch 'source/main' into rconnell/metal-toolchain
rconnell9 c003381
Merge remote-tracking branch 'source/main' into rconnell/metal-toolchain
rconnell9 3b8bbee
Merge remote-tracking branch 'source/main' into rconnell/metal-toolchain
rconnell9 3448806
Merge remote-tracking branch 'source/main' into rconnell/metal-toolchain
rconnell9 b94d9d0
Merge remote-tracking branch 'source/main' into rconnell/metal-toolchain
rconnell9 e1def1f
Resolve merge conflict
rconnell9 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // swift-tools-version: 6.2 | ||
| // The swift-tools-version declares the minimum version of Swift required to build this package. | ||
| import PackageDescription | ||
|
|
||
| let package = Package( | ||
| name: "MyRenderer", | ||
| products: [ | ||
| .library( | ||
| name: "MyRenderer", | ||
| targets: ["MyRenderer"]), | ||
| ], | ||
| targets: [ | ||
| .target( | ||
| name: "MyRenderer", | ||
| dependencies: ["MySharedTypes"]), | ||
|
|
||
| .target(name: "MySharedTypes") | ||
| ] | ||
| ) |
4 changes: 4 additions & 0 deletions
4
Fixtures/Metal/SimpleLibrary/Sources/MyRenderer/Renderer.swift
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| import MySharedTypes | ||
|
|
||
|
|
||
| let vertex = AAPLVertex(position: .init(250, -250), color: .init(1, 0, 0, 1)) |
12 changes: 12 additions & 0 deletions
12
Fixtures/Metal/SimpleLibrary/Sources/MyRenderer/Shaders.metal
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // A relative path to SharedTypes.h. | ||
| #import "../MySharedTypes/include/SharedTypes.h" | ||
|
|
||
| #include <metal_stdlib> | ||
| using namespace metal; | ||
|
|
||
| vertex float4 simpleVertexShader(const device AAPLVertex *vertices [[buffer(0)]], | ||
| uint vertexID [[vertex_id]]) { | ||
| AAPLVertex in = vertices[vertexID]; | ||
| return float4(in.position.x, in.position.y, 0.0, 1.0); | ||
| } | ||
|
|
14 changes: 14 additions & 0 deletions
14
Fixtures/Metal/SimpleLibrary/Sources/MySharedTypes/include/SharedTypes.h
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #ifndef SharedTypes_h | ||
| #define SharedTypes_h | ||
|
|
||
|
|
||
| #import <simd/simd.h> | ||
|
|
||
|
|
||
| typedef struct { | ||
| vector_float2 position; | ||
| vector_float4 color; | ||
| } AAPLVertex; | ||
|
|
||
|
|
||
| #endif /* SharedTypes_h */ |
6 changes: 6 additions & 0 deletions
6
Fixtures/Metal/SimpleLibrary/Tests/MyRendererTests/MyRendererTests.swift
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import Testing | ||
| @testable import MyRenderer | ||
|
|
||
| @Test func example() async throws { | ||
| // Write your test here and use APIs like `#expect(...)` to check expected conditions. | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the Swift open source project | ||
| // | ||
| // Copyright (c) 2025 Apple Inc. and the Swift project authors | ||
| // Licensed under Apache License v2.0 with Runtime Library Exception | ||
| // | ||
| // See http://swift.org/LICENSE.txt for license information | ||
| // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| import _InternalTestSupport | ||
| import Testing | ||
| import Basics | ||
| import Foundation | ||
| #if os(macOS) | ||
| import Metal | ||
| #endif | ||
|
|
||
| @Suite | ||
| struct BuildMetalTests { | ||
|
|
||
| #if os(macOS) | ||
| @Test( | ||
| .disabled("Require downloadable Metal toolchain"), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (non-blocking): is it possible to detect the location of the metal toolchain and enable the test if it's detected? |
||
| .tags(.TestSize.large), | ||
| .requireHostOS(.macOS), | ||
| arguments: getBuildData(for: [.swiftbuild]) | ||
| ) | ||
| func simpleLibrary(data: BuildData) async throws { | ||
| let buildSystem = data.buildSystem | ||
| let configuration = data.config | ||
|
|
||
| try await fixture(name: "Metal/SimpleLibrary") { fixturePath in | ||
|
|
||
| // Build the package | ||
| let (_, _) = try await executeSwiftBuild( | ||
| fixturePath, | ||
| configuration: configuration, | ||
| buildSystem: buildSystem, | ||
| throwIfCommandFails: true | ||
| ) | ||
|
|
||
| // Get the bin path | ||
| let (binPathOutput, _) = try await executeSwiftBuild( | ||
| fixturePath, | ||
| configuration: configuration, | ||
| extraArgs: ["--show-bin-path"], | ||
| buildSystem: buildSystem, | ||
| throwIfCommandFails: true | ||
| ) | ||
|
|
||
| let binPath = try AbsolutePath(validating: binPathOutput.trimmingCharacters(in: .whitespacesAndNewlines)) | ||
|
|
||
| // Check that default.metallib exists | ||
| let metallibPath = binPath.appending(components:["MyRenderer_MyRenderer.bundle", "Contents", "Resources", "default.metallib"]) | ||
| #expect( | ||
| localFileSystem.exists(metallibPath), | ||
| "Expected default.metallib to exist at \(metallibPath)" | ||
| ) | ||
|
|
||
| // Verify we can load the metal library | ||
| let device = try #require(MTLCreateSystemDefaultDevice()) | ||
| let library = try device.makeLibrary(URL: URL(fileURLWithPath: metallibPath.pathString)) | ||
|
|
||
| #expect(library.functionNames.contains("simpleVertexShader")) | ||
| } | ||
| } | ||
| #endif | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should consider putting the new test in SwiftBuildSupportTests instead of creating a whole new test target since this is a fairly specific test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll include a follow-up