Skip to content

Symbol graph support for swiftbuild build system #8923

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
merged 10 commits into from
Jul 16, 2025

Conversation

cmcgee1024
Copy link
Member

@cmcgee1024 cmcgee1024 commented Jul 11, 2025

Refactor the build system protocol to make symbol graphs and build plans optional build outputs.
Rewrite the dump-symbol-graph and the plugin delegate to use this new protocol and get support
from the swiftbuild build system.

Refactor the build system protocol to make symbol graphs and build plans optional
build outputs
@cmcgee1024
Copy link
Member Author

@swift-ci please test

outputRedirection: .collect(redirectStderr: true),
outputDirectory: symbolGraphDirectory,
verboseOutput: swiftCommandState.logLevel <= .info
if buildResult.symbolGraph {
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be nice if the BuildResult could include the symbol graph paths themselves so we can compute those at the build system layer instead of in the dump command

@cmcgee1024
Copy link
Member Author

@swift-ci please test

@cmcgee1024
Copy link
Member Author

@swift-ci test Windows

1 similar comment
@cmcgee1024
Copy link
Member Author

@swift-ci test Windows

@cmcgee1024
Copy link
Member Author

@swift-ci please test

@cmcgee1024
Copy link
Member Author

@swift-ci test Windows

@cmcgee1024
Copy link
Member Author

@swift-ci test Windows

@cmcgee1024 cmcgee1024 changed the title DRAFT: Symbol graph support for swiftbuild build system Symbol graph support for swiftbuild build system Jul 14, 2025
/// result for indication that the output was produced.
public enum BuildOutput {
case symbolGraph
// TODO associated values for the following symbol graph options:
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if these extra flags should be captured by the requested outputs or the build parameters. Not sure I have a strong opinion right now but we should come up with a guideline to apply to future output types

@cmcgee1024
Copy link
Member Author

@swift-ci please test

@cmcgee1024
Copy link
Member Author

@swift-ci test Windows

@cmcgee1024
Copy link
Member Author

@swift-ci please test

@cmcgee1024
Copy link
Member Author

@swift-ci test Windows

@cmcgee1024 cmcgee1024 enabled auto-merge (squash) July 16, 2025 00:36
@cmcgee1024 cmcgee1024 merged commit 0181475 into swiftlang:main Jul 16, 2025
6 checks passed
@@ -608,7 +608,7 @@ struct TraitTests {
#expect(symbolGraph.contains("TypeGatedByPackage10Trait1"))
#expect(symbolGraph.contains("TypeGatedByPackage10Trait2"))
} when: {
buildSystem == .swiftbuild
buildSystem == .swiftbuild && ProcessInfo.hostOperatingSystem == .windows
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: does means this test currently fails for all platform with SwiftBuild. This seems like a regression from current behaviour.

Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: consider migrating the test suite to Swift Testing so we can get feedback and test re-enablement once functionality is available.

@@ -571,6 +571,7 @@ class PackageCommandTestCase: CommandsBuildProviderTestCase {
func testDumpSymbolGraphPrettyFormatting() async throws {
// Depending on how the test is running, the `swift-symbolgraph-extract` tool might be unavailable.
try XCTSkipIf((try? UserToolchain.default.getSymbolGraphExtract()) == nil, "skipping test because the `swift-symbolgraph-extract` tools isn't available")
try XCTSkipIf(buildSystemProvider == .swiftbuild, "skipping test because pretty printing isn't yet supported with swiftbuild build system via swift build and the swift compiler")
Copy link
Contributor

Choose a reason for hiding this comment

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

question: Can we reference a GitHub issue in the comment that will address the Swift Build pretty printing integration?

@@ -123,14 +123,17 @@ struct APIDiff: AsyncSwiftCommand {
let apiDigesterTool = SwiftAPIDigester(fileSystem: swiftCommandState.fileSystem, tool: apiDigesterPath)

// Build the current package.
try await buildSystem.build()
let buildResult = try await buildSystem.build(subset: .allExcludingTests, buildOutputs: [.buildPlan])
guard let buildPlan = buildResult.buildPlan else {
Copy link
Contributor

Choose a reason for hiding this comment

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

question: From my understanding, a build plan is a native build system concept, but I believe the API Diff supports SwiftBuild Build System. Should we be aborting here? Also, should the destinationBuildParameter and toolsBuildParameters always be available as "build outputs"?

// We are enabling all traits for dumping the symbol graph.
traitConfiguration: .init(enableAllTraits: true),
cacheBuildManifest: false
)
try await buildSystem.build()
// TODO pass along the various flags as associated values to the symbol graph build output (e.g. includeSPISymbols)
Copy link
Contributor

Choose a reason for hiding this comment

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

question: do we have a GitHub issue tracking this TODO?

continue
}

print("-- Emitting symbol graph for", description.module.name)
Copy link
Contributor

Choose a reason for hiding this comment

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

question: should we be using ObservabilityScope for emitting message to the console?

try buildSystem.buildPlan.buildModules.first {
$0.module.name == moduleName && $0.buildParameters.destination == destination
// Build the target, if needed. We are interested in symbol graph (ideally) or a build plan.
// TODO pass along the options as associated values to the symbol graph build output (e.g. includeSPI)
Copy link
Contributor

Choose a reason for hiding this comment

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

question: Do we have a GitHub issue tracking this TODO?

.split(whereSeparator: \.isNewline)
.first { String($0).hasPrefix("Files written to ") }?
.dropFirst(17)
try await withKnownIssue(isIntermittent: true, {
Copy link
Contributor

Choose a reason for hiding this comment

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

question: The test was previously passing on Windows, but we now marked it as intermittent. do we understand why?

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.

4 participants