Skip to content

PlatformFilter support for SwiftPM prebuilts.#1317

Merged
dschaefer2 merged 18 commits into
swiftlang:mainfrom
dschaefer2:prebuiltsHost
May 13, 2026
Merged

PlatformFilter support for SwiftPM prebuilts.#1317
dschaefer2 merged 18 commits into
swiftlang:mainfrom
dschaefer2:prebuiltsHost

Conversation

@dschaefer2
Copy link
Copy Markdown
Member

@dschaefer2 dschaefer2 commented Apr 16, 2026

SwiftPM Prebuilts are only supported currently for the host. For other platforms we need to be able to build from the source of the prebuilts. To model this in the PIF, we need to be able to add platform filters on dependencies to select the prebuilt targets for host and the source targets for not host.

This adds an exclude flag to the PlatformFilter to signal to filter out dependencies for the given platform, as opposed to filtering in for the given platform which is the current semantics.

We'll reach a point with SwiftPM that we'll need a more advanced expression model for platform filtering, but this should enable us for now with the prebuilt requirements and add support for host tools along with our current support for macros.

The matching SwiftPM PR is here. swiftlang/swift-package-manager#9905

SwiftPM Prebuilts are only supported currently for the host.
For other platforms we need to be able to build from the source
of the prebuilts. To model this in the PIF, we need to be able
to add platform filters on dependencies to select the prebuilt
targets for host and the source targets for not host.

This adds an exclude flag to the PlatformFilter to signal to
filter out dependencies for the given platform, as opposed to
filtering in for the given platform which is the current semantics.

We'll reach a point with SwiftPM that we'll need a more advanced
expression model for platform filtering, but this should enable
us for now with the prebuilt requirements and add support for
host tools along with our current support for macros.
Comment thread Sources/SWBCore/ProjectModel/PlatformFilter.swift
@jakepetroules
Copy link
Copy Markdown
Collaborator

Can you add some tests for this?

@dschaefer2
Copy link
Copy Markdown
Member Author

Definitely. That's the [WIP] part in the title :). I need to do some more manual testing as well.

Comment thread Sources/SwiftBuild/ProjectModel/PlatformFilter.swift Outdated
@dschaefer2 dschaefer2 changed the title [WIP] PlatformFilter support for SwiftPM prebuilts. PlatformFilter support for SwiftPM prebuilts. Apr 29, 2026
@dschaefer2
Copy link
Copy Markdown
Member Author

@swift-ci please test

Comment thread Sources/SWBCore/ProjectModel/PlatformFilter.swift
Comment thread Sources/SWBCore/ProjectModel/ProjectModelItem.swift Outdated
@dschaefer2
Copy link
Copy Markdown
Member Author

dschaefer2 commented May 4, 2026

One more set of tests incoming. I'm working on some tests to make sure the exclusions affect the build graph like I need for prebuilts.

@dschaefer2
Copy link
Copy Markdown
Member Author

One more tweak to the test and it'll be ready.

@dschaefer2
Copy link
Copy Markdown
Member Author

This is ready for review.

Copy link
Copy Markdown
Collaborator

@owenv owenv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm


/// Task construction tests related to prebuilts from SwiftPM.
@Suite fileprivate struct PrebuiltsTaskConstructionTests: CoreBasedTests {
@Test func prebuiltsAreHostOnly() async throws {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should specify .requireSDKs(.host)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering if I should. I'll do that.

/// Task construction tests related to prebuilts from SwiftPM.
@Suite fileprivate struct PrebuiltsTaskConstructionTests: CoreBasedTests {
@Test func prebuiltsAreHostOnly() async throws {
let prebuiltsDir = Path.root.join("tmp").join("Test").join("prebuiltsProject").join("build").join("prebuilts")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We prefer to use withTemporaryDirectory for tests instead of /tmp so it gets cleaned up afterwards

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, you're using PseudoFS, this should be alright

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. I was actually disappointed I had to use a temporary directory for the Swift SDK manifest. SwiftPM has FileSystem plumbed throughout and am able to use the InMemoryFileSystem for pretty much everything. Apparently Core does not.

@dschaefer2
Copy link
Copy Markdown
Member Author

@swift-ci please test

@dschaefer2 dschaefer2 merged commit c324386 into swiftlang:main May 13, 2026
119 of 126 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants