Skip to content

Conversation

bkhouri
Copy link
Contributor

@bkhouri bkhouri commented Sep 4, 2025

Snippets are treated as executable targets with the native build system.

This change updates the PIF Builder to support snippet, giving Snippet support with the Swift Build build system.

Depends on: swiftlang/swift-build#775
Depends on: #9115
Fixes: #9040
issue: rdar://158630024
issue: rdar://147705448

@bkhouri
Copy link
Contributor Author

bkhouri commented Sep 4, 2025

@swift-ci test

@bkhouri bkhouri marked this pull request as ready for review September 4, 2025 18:39
@owenv
Copy link
Contributor

owenv commented Sep 4, 2025

What's here looks good, I just have a few follow up questions

The proposal says:

Snippet targets automatically depend on any library targets declared in their host package, so snippets are free to import those modules.
Are those dependencies getting captured in the PIF right now? Would be good to have a test that imports of API from the package works

It also says:

Snippet targets will be built by default when running swift build --build-snippets. This is consistent with how building tests is an explicit choice, like when running swift test or swift build --build-tests.

Right now, PIFBuilder.buildAggregateProject is adding snippets to the "all-including-tests" target AFAICT, which will cause the snippets to build with just swift test. We might need to add a new aggregate which pulls in snippets that clients can opt into

@bkhouri
Copy link
Contributor Author

bkhouri commented Sep 8, 2025

With the current implementation, Snippets are build when running swift build command. I'll augment the testBasicBuildSnippets to verify the expected Snippet executables existing the build output directory.

Also, the --build-snippets option is not available with swift build

❯ swift --version               
Apple Swift version 6.2-dev (LLVM fa1f889407fc8ca, Swift 687e09da65c8813)
Target: arm64-apple-macosx26.0
Build config: +assertions

❯ swift build --help | grep snip 

❯
Build Snippets sample

``` ++ swift run swift-build --package-path Fixtures/Miscellaneous/Plugins/PluginsAndSnippets --build-system swiftbuild --show-bin-path Building for debugging... [1/1] Write swift-version-7F702FD1CBFC1C8A.txt Build of product 'swift-build' complete! (0.51s) + BIN_DIR=/Users/bkhouri/Documents/git/public/swiftlang/swift-package-manager/Fixtures/Miscellaneous/Plugins/PluginsAndSnippets/.build/arm64-apple-macosx/Products/Debug + echo 'Binary Directory: /Users/bkhouri/Documents/git/public/swiftlang/swift-package-manager/Fixtures/Miscellaneous/Plugins/PluginsAndSnippets/.build/arm64-apple-macosx/Products/Debug' Binary Directory: /Users/bkhouri/Documents/git/public/swiftlang/swift-package-manager/Fixtures/Miscellaneous/Plugins/PluginsAndSnippets/.build/arm64-apple-macosx/Products/Debug + swift run swift-package --package-path Fixtures/Miscellaneous/Plugins/PluginsAndSnippets --build-system swiftbuild completion-tool list-snippets Building for debugging... [1/1] Write swift-version-7F702FD1CBFC1C8A.txt Build of product 'swift-package' complete! (0.48s) ContainsMain MySnippet main + swift run swift-package reset --package-path Fixtures/Miscellaneous/Plugins/PluginsAndSnippets Building for debugging... [1/1] Write swift-version-7F702FD1CBFC1C8A.txt Build of product 'swift-package' complete! (0.46s) + ls -lh /Users/bkhouri/Documents/git/public/swiftlang/swift-package-manager/Fixtures/Miscellaneous/Plugins/PluginsAndSnippets/.build/arm64-apple-macosx/Products/Debug ls: /Users/bkhouri/Documents/git/public/swiftlang/swift-package-manager/Fixtures/Miscellaneous/Plugins/PluginsAndSnippets/.build/arm64-apple-macosx/Products/Debug: No such file or directory + swift run swift-build --package-path Fixtures/Miscellaneous/Plugins/PluginsAndSnippets --build-system swiftbuild Building for debugging... [1/1] Write swift-version-7F702FD1CBFC1C8A.txt Build of product 'swift-build' complete! (0.48s) Building for debugging...

95% [===============================================================================================================================================================================================================-----------]
main-product 53 / 55
100% [=========================================================================================================================================================================================================================]

Build complete! (2.37 secs.)

  • ls -lh /Users/bkhouri/Documents/git/public/swiftlang/swift-package-manager/Fixtures/Miscellaneous/Plugins/PluginsAndSnippets/.build/arm64-apple-macosx/Products/Debug
    total 240
    -rwxr-xr-x 1 bkhouri staff 37K Sep 8 10:41 ContainsMain
    drwxr-xr-x 6 bkhouri staff 192B Sep 8 10:41 ContainsMain.swiftmodule
    -rwxr-xr-x 1 bkhouri staff 36K Sep 8 10:41 MySnippet
    drwxr-xr-x 6 bkhouri staff 192B Sep 8 10:41 MySnippet.swiftmodule
    drwxr-xr-x@ 2 bkhouri staff 64B Sep 8 10:41 PackageFrameworks
    -rwxr-xr-x 1 bkhouri staff 36K Sep 8 10:41 main
    drwxr-xr-x 6 bkhouri staff 192B Sep 8 10:41 main.swiftmodule
</p>
</details> 

@bkhouri bkhouri force-pushed the t/main/gh9040_snippets branch from 02f2f9f to 4431162 Compare September 8, 2025 17:07
@bkhouri
Copy link
Contributor Author

bkhouri commented Sep 8, 2025

@swift-ci test

@bkhouri
Copy link
Contributor Author

bkhouri commented Sep 8, 2025

@swift-ci test macOS

@bkhouri
Copy link
Contributor Author

bkhouri commented Sep 8, 2025

@swift-ci test windows

Copy link
Contributor

@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.

@bkhouri and I discussed a bit offline. It looks like --build-snippets wasn't implemented as proposed, so the swift build behavior here mirrors the native build system correctly, we just want to ensure we have test coverage that snippets' dependencies on library targets are being wired up correctly

@bkhouri
Copy link
Contributor Author

bkhouri commented Sep 8, 2025

  • : Augment the tests to ensure a Snippet can import a library target.

@bkhouri bkhouri force-pushed the t/main/gh9040_snippets branch from 4431162 to 6eb953c Compare September 8, 2025 22:23
@bkhouri
Copy link
Contributor Author

bkhouri commented Sep 8, 2025

The linux self hosted pipeline failed as a result of a build timeout during test execution

13:39:06  ◇ Passing 2 arguments buildSystem → .swiftbuild, configuration → .debug to generatedMainIsExistentialAnyClean(buildSystem:configuration:)
16:21:13  Cancelling nested steps due to timeout

The windows self-hosted pipeline failed due to known issues. They have been marked withKnownIssue.

@swift-ci test

@bkhouri
Copy link
Contributor Author

bkhouri commented Sep 8, 2025

@swift-ci test windows

@bkhouri bkhouri self-assigned this Sep 9, 2025
@bkhouri bkhouri added swift build Changes impacting `swift build` swiftbuild backend labels Sep 9, 2025
@bkhouri bkhouri force-pushed the t/main/gh9040_snippets branch from 6eb953c to ecaddca Compare September 9, 2025 13:14
@bkhouri
Copy link
Contributor Author

bkhouri commented Sep 9, 2025

@swift-ci test self hosted

@bkhouri bkhouri marked this pull request as draft September 9, 2025 13:14
@bkhouri bkhouri force-pushed the t/main/gh9040_snippets branch from ecaddca to ad15784 Compare September 9, 2025 18:45
@bkhouri
Copy link
Contributor Author

bkhouri commented Sep 9, 2025

@swift-ci test self hosted

@bkhouri bkhouri force-pushed the t/main/gh9040_snippets branch from ad15784 to f944f47 Compare September 9, 2025 18:59
@bkhouri
Copy link
Contributor Author

bkhouri commented Sep 9, 2025

@swift-ci test self hosted

1 similar comment
@bkhouri
Copy link
Contributor Author

bkhouri commented Sep 10, 2025

@swift-ci test self hosted

.target(
name: "SwiftBuildSupport",
dependencies: [
"Build",
Copy link
Member

Choose a reason for hiding this comment

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

Just taking a quick look, and I see it's still in draft. The "Build" target is the native build system. We shouldn't have SwiftBuildSupport depending on it since it'll be removed eventually. Common things should go in SPMBuildCore.

Snippets are treated as executable targets with the native build system.

This change updates the PIF Builder to support snippet, giving Snippet
support with the Swift Build build system.

Also update the `testCommandPluginCancellation` in PluginTests as it was
not properly handling the task cancellations.

Depends on: swiftlang/swift-build#775
Fixes: swiftlang#9040
issue: rdar://158630024
issue: rdar://147705448
@bkhouri bkhouri force-pushed the t/main/gh9040_snippets branch from f944f47 to 8533c40 Compare September 15, 2025 15:05
@bkhouri
Copy link
Contributor Author

bkhouri commented Sep 15, 2025

@swift-ci test

@bkhouri
Copy link
Contributor Author

bkhouri commented Sep 15, 2025

@swift-ci test windows

@bkhouri bkhouri marked this pull request as ready for review September 15, 2025 19:16
@bkhouri bkhouri enabled auto-merge (squash) September 15, 2025 19:16
@bkhouri bkhouri merged commit a9e72ad into swiftlang:main Sep 15, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

swift build Changes impacting `swift build` swiftbuild backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Snippet support for the SwiftBuild Integration

3 participants