Skip to content

Compute correct compiler arguments for build plugins#9583

Merged
ahoppen merged 1 commit into
swiftlang:mainfrom
ahoppen:plugin-args-lsp
Apr 12, 2026
Merged

Compute correct compiler arguments for build plugins#9583
ahoppen merged 1 commit into
swiftlang:mainfrom
ahoppen:plugin-args-lsp

Conversation

@ahoppen
Copy link
Copy Markdown
Member

@ahoppen ahoppen commented Jan 10, 2026

The computation of compiler arguments for package plugins was plain out broken and didn’t even include the search path to lib/swift/pm/PluginAPI. Call into the same logic with which we compute the build settings during building from SourceKitLSPAPI.

Tested as part of swiftlang/sourcekit-lsp#2446.

Fixes swiftlang/sourcekit-lsp#2115

@ahoppen
Copy link
Copy Markdown
Member Author

ahoppen commented Jan 10, 2026

swiftlang/sourcekit-lsp#2446

@swift-ci Please test

@ahoppen ahoppen force-pushed the plugin-args-lsp branch 2 times, most recently from 457ec8a to f2f69db Compare January 16, 2026 07:05
@ahoppen
Copy link
Copy Markdown
Member Author

ahoppen commented Jan 16, 2026

swiftlang/sourcekit-lsp#2446

@swift-ci Please test

@ahoppen ahoppen requested a review from daveinglis as a code owner March 16, 2026 07:43
ahoppen added a commit to ahoppen/sourcekit-lsp that referenced this pull request Mar 16, 2026
@ahoppen
Copy link
Copy Markdown
Member Author

ahoppen commented Mar 16, 2026

swiftlang/sourcekit-lsp#2446

@swift-ci Please test

@jakepetroules
Copy link
Copy Markdown
Contributor

What about Swift Build? Is it already correct when using that backend?

@ahoppen
Copy link
Copy Markdown
Member Author

ahoppen commented Mar 23, 2026

I haven’t been able to test it. The following test in SourceKit-LSP fails with issues from the BSP server. Regardless, I think it’s worth fixing this in the native build system and having a test for it that will catch any similar issues as we qualify the swiftbuild build system for SourceKit-LSP. So, I don’t think that fixing this in swiftbuild should be a blocker for this PR anyway.

Details

  func testPackagePlugin() async throws {
    var options = try await SourceKitLSPOptions.testDefault()
    options.swiftPMOrDefault.buildSystem = .swiftbuild
    let project = try await SwiftPMTestProject(
      files: [
        "Test.swift": "",
        "Plugins/PrintMessage/Plugin.swift": """
        import PackagePlugin

        @main
        struct PrintMessagePlugin: CommandPlugin {
          func performCommand(context: PluginContext, arguments: [String]) throws {
            print("Message")
            let x: String = 1
          }
        }
        """,
      ],
      manifest: """
        import PackageDescription

        let package = Package(
          name: "PrintMessage",
          platforms: [.macOS(.v14)],
          products: [
            .plugin(
              name: "PrintMessage",
              targets: ["PrintMessage"]
            )
          ],
          targets: [
            .target(name: "MyLibrary"),
            .plugin(
              name: "PrintMessage",
              capability: .command(
                intent: .custom(
                  verb: "print-message",
                  description: "Prints message"
                )
              )
            )
          ]
        )
        """,
      options: options
    )
    let (uri, _) = try! project.openDocument("Plugin.swift")
    let diags = try await project.testClient.send(DocumentDiagnosticsRequest(textDocument: TextDocumentIdentifier(uri)))
    XCTAssertEqual(
      diags.fullReport?.items.map(\.message),
      ["Cannot convert value of type 'Int' to specified type 'String'"]
    )
  }
[org.swift.sourcekit-lsp.tests:default] info 2026-03-23 12:05:48.0630 +0100
Sending notification to client
window/logMessage
{
  "logName" : "SourceKit-LSP: Indexing",
  "message" : "Error generating build description: No such file or directory (2)",
  "type" : 4
}
…
[org.swift.sourcekit-lsp.tests:default] info 2026-03-23 12:05:48.0630 +0100
Sending notification to client
window/logMessage
{
  "logName" : "SourceKit-LSP: Indexing",
  "message" : "Computing targets list",
  "type" : 4
}
...
[org.swift.sourcekit-lsp.tests:default] error 2026-03-23 12:05:48.0650 +0100
Received error for request "sk-2" from BSP-Server
workspace/buildTargets
ResponseError(code: LanguageServerProtocol.ErrorCode(rawValue: -32001), message: "No build description", data: nil)

@ahoppen
Copy link
Copy Markdown
Member Author

ahoppen commented Mar 24, 2026

@swift-ci Please test

ahoppen added a commit to ahoppen/sourcekit-lsp that referenced this pull request Apr 2, 2026
… in SwiftPMBuildServer

To stage in swiftlang/swift-package-manager#9583 because SwiftPM doesn’t support cross-PR testing.
ahoppen added a commit to ahoppen/sourcekit-lsp that referenced this pull request Apr 2, 2026
@ahoppen
Copy link
Copy Markdown
Member Author

ahoppen commented Apr 3, 2026

@swift-ci Please test

ahoppen added a commit to ahoppen/swift-package-manager that referenced this pull request Apr 4, 2026
…ion`

To stage in swiftlang#9583.

Steps:
1. Merge this PR
2. Change SourceKit-LSP to pass a `pluginConfiguration`
3. Merge swiftlang#9583
4. Merge swiftlang/sourcekit-lsp#2446 for a test in SourceKit-LSP
@ahoppen
Copy link
Copy Markdown
Member Author

ahoppen commented Apr 8, 2026

@swift-ci Please test

@ahoppen
Copy link
Copy Markdown
Member Author

ahoppen commented Apr 8, 2026

@swift-ci Please test Windows

The computation of compiler arguments for package plugins was plain out broken and didn’t even include the search path to `lib/swift/pm/PluginAPI`. Call into the same logic with with we compute the build settings during building from `SourceKitLSPAPI`.

Fixes swiftlang/sourcekit-lsp#2115
@ahoppen
Copy link
Copy Markdown
Member Author

ahoppen commented Apr 8, 2026

@swift-ci Please test

@ahoppen
Copy link
Copy Markdown
Member Author

ahoppen commented Apr 8, 2026

@swift-ci Please test Windows

@ahoppen ahoppen merged commit e19bcd0 into swiftlang:main Apr 12, 2026
61 checks passed
@ahoppen ahoppen deleted the plugin-args-lsp branch April 12, 2026 05:47
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.

No such module 'PackagePlugin' while editing package plugins

4 participants