Skip to content

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Aug 30, 2025

The design of these requests closely resemble the BSP requests required by SourceKit-LSP and should be useful to implement a BSP server based on swift-build.

Follow-up task:

  • The new requests currently assume that the build description with the given ID hasn’t been purged from the BuildDescriptionManager but there’s no way to ensure that. I was thinking to add a request to retain or release a build description. As long as the build description has a retain count greater than 0, it won’t be purged from the BuildDescriptionManager. But I’d like to hear feedback about this idea before implementing it.

@ahoppen ahoppen marked this pull request as ready for review August 30, 2025 09:39
@owenv
Copy link
Collaborator

owenv commented Aug 30, 2025

The new requests currently assume that the build description with the given ID hasn’t been purged from the BuildDescriptionManager but there’s no way to ensure that. I was thinking to add a request to retain or release a build description. As long as the build description has a retain count greater than 0, it won’t be purged from the BuildDescriptionManager. But I’d like to hear feedback about this idea before implementing it.

Right now we will never evict the most recent index workspace description from the cache, but it would be nice to have something better. Being able to treat the build description ID as a handle clients can retain makes sense to me

@owenv
Copy link
Collaborator

owenv commented Aug 30, 2025

I didn’t find a way to test my new code in SWBBuildService. If there is a way to test it, I’d appreciate some guidance

I think e can put a test for the new API in the SwiftBuildTests target. IndexingInfoTests.indexingInfoDetailed is a good example of an existing test that stands up a test session with a mock project. I think it should be possible to copy that and adapt it to call into the new API you've added here

…t-builds build description

The design of these requests closely resemble the BSP requests required by SourceKit-LSP and should be useful to implement a BSP server based on swift-build.
@ahoppen
Copy link
Member Author

ahoppen commented Sep 1, 2025

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Sep 1, 2025

I added a few tests now. Before being able to use this in production, I think we need a way to create build descriptions and keep them in memory without evicting them from the cache but I’d like to make that a follow-up change.

@ahoppen ahoppen merged commit 0f72152 into swiftlang:main Sep 2, 2025
36 checks passed
@ahoppen ahoppen deleted the bsp-requests branch September 2, 2025 18:40
if let toolchainID = toolchainIDs(in: configuredTarget, of: buildDescription)?.first {
toolchain = session.core.toolchainRegistry.lookup(toolchainID)?.path
if toolchain == nil {
log("Unable to find path for toolchain with identifier \(toolchainID)", isError: true)
Copy link
Collaborator

Choose a reason for hiding this comment

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

@ahoppen We don't conventionally have this level of logging in the product; it seems like debug printing that should've been removed.

let configuredTargetsByID = Dictionary(
buildDescription.allConfiguredTargets.map { ($0.guid, $0) }
) { lhs, rhs in
log("Found conflicting targets for the same ID: \(lhs.guid)", isError: true)
Copy link
Collaborator

Choose a reason for hiding this comment

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

@ahoppen These type of scenarios should throw an error, not "pick one and log"; it tends to lead to unpredictable and nondeterministic behavior

@jakepetroules
Copy link
Collaborator

Why is it the right approach to add more low-level requests at the Swift Build layer for a higher level layer to implement the BSP, versus Swift Build itself hosting the BSP server?

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