Skip to content

Wire up the plugin script runner to the PIF Builder for build tool plugins #8728

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

cmcgee1024
Copy link
Member

@cmcgee1024 cmcgee1024 commented May 27, 2025

This will activate build tool plugins and enables more plugin testing with the new build system.

Add a plugin test case to verify plugins with swift build build
system.
@cmcgee1024 cmcgee1024 force-pushed the build_tool_plugins branch from 12768d5 to 561322a Compare May 27, 2025 14:17
@cmcgee1024 cmcgee1024 changed the title DNM: Wire up the script runner to the PIF Builder DNM: Wire up the plugin script runner to the PIF Builder May 27, 2025
@cmcgee1024
Copy link
Member Author

@swift-ci please test

@@ -130,9 +202,51 @@ public final class PIFBuilder {

private var cachedPIF: PIF.TopLevelObject?

private func buildPluginTools(
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I find this name a little confusing since this function is not actually performing the build of the tools, might be worth a comment

@cmcgee1024
Copy link
Member Author

@swift-ci test macOS

@cmcgee1024
Copy link
Member Author

@swift-ci test Windows

@cmcgee1024 cmcgee1024 changed the title DNM: Wire up the plugin script runner to the PIF Builder Wire up the plugin script runner to the PIF Builder for build tool plugins May 28, 2025
@cmcgee1024
Copy link
Member Author

@swift-ci please test

@cmcgee1024 cmcgee1024 marked this pull request as ready for review May 28, 2025 13:58
@cmcgee1024
Copy link
Member Author

@swift-ci test Linux

@cmcgee1024
Copy link
Member Author

@swift-ci test Windows

import func TSCBasic.topologicalSort
import var TSCBasic.stdoutStream

import enum SwiftBuild.ProjectModel

public func memoize<T>(to cache: inout T?, build: () async throws -> T) async rethrows -> T {
Copy link
Contributor

@pmattos pmattos May 28, 2025

Choose a reason for hiding this comment

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

Does this function really need to be public?

pluginScriptRunner: PluginScriptRunner,
pluginWorkingDirectory: AbsolutePath,
pkgConfigDirectories: [Basics.AbsolutePath],
additionalFileRules: [FileRuleDescription]
) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider moving pluginWorkingDirectory, pkgConfigDirectories, and additionalFileRules to PIFBuilderParameters instead. Assuming that doesn't wreak havoc on the calling code ;)

PS. The PluginScriptRunner seems like should be passed on the init directly as you just did.

observabilityScope: observabilityScope
)
let pluginDerivedResources = derivedResources
derivedSources.forEach { absPath in
Copy link
Contributor

@pmattos pmattos May 28, 2025

Choose a reason for hiding this comment

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

Nitpick: According to the code review we did in Swift Build, the Swift folks suggested we use plain for loops for such cases.

}

extension ModulesGraph {
public static func computePluginGeneratedFiles(
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't this extension be fileprivate instead?


let pluginWorkingDirectory: AbsolutePath

let pkgConfigDirectories: [Basics.AbsolutePath]
Copy link
Contributor

Choose a reason for hiding this comment

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

Drop the Basisc prefix.


// Add a BuildToolPluginInvocationResult to the mapping.
buildToolPluginResults.append(result2)
buildtoolPluginResults[module.name] = result2
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: the close naming here seems tricky to parse 😬.

Maybe rename buildtoolPluginResults to buildToolPluginResultsByModuleName?

@@ -241,16 +274,14 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
}

let pifBuilder = try await getPIFBuilder()
let pif = try pifBuilder.generatePIF(
let pif = try await pifBuilder.generatePIF(
Copy link
Contributor

Choose a reason for hiding this comment

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

Praise: Great to see this code path slowly becoming async! 👏

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