Skip to content

Introduce a notion of ConfiguredTargets into the build system #1249

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 3 commits into from
May 9, 2024

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented May 8, 2024

Instead of asking for build settings of a file, the build system manager asks for the targets of a file and then asks for the build settings of that file in a specific target. This has two advantages:

  • We know about targets and can prepare the targets for background indexing
  • Once we support build systems in which a single file can be part of multiple targets, we can have a centralized place that picks preferred targets for a file, eg. based on user configuration

Depends on swiftlang/swift-package-manager#7540

ahoppen added 3 commits May 8, 2024 10:40
Instead of asking for build settings of a file, the build system manager asks for the targets of a file and then asks for the build settings of that file in a specific target. This has two advantages:
- We know about targets and can prepare the targets for background indexing
- Once we support build systems in which a single file can be part of multiple targets, we can have a centralized place that picks preferred targets for a file, eg. based on user configuration
@ahoppen ahoppen requested a review from bnbarham May 8, 2024 23:44
@ahoppen ahoppen requested a review from benlangmuir as a code owner May 8, 2024 23:44
@ahoppen
Copy link
Member Author

ahoppen commented May 8, 2024

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented May 8, 2024

@ahoppen ahoppen merged commit 4d93848 into swiftlang:main May 9, 2024
3 checks passed
@ahoppen ahoppen deleted the configured-targets branch May 9, 2024 19:02
Copy link
Contributor

@hamishknight hamishknight left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +48 to +65
public struct ConfiguredTarget: Hashable, Sendable {
/// An opaque string that represents the target.
///
/// The target's ID should be generated by the build system that handles the target and only interpreted by that
/// build system.
public let targetID: String

/// An opaque string that represents the run destination.
///
/// The run destination's ID should be generated by the build system that handles the target and only interpreted by
/// that build system.
public let runDestinationID: String

public init(targetID: String, runDestinationID: String) {
self.targetID = targetID
self.runDestinationID = runDestinationID
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I was going to suggest modeling this as associated type on BuildSystem, which would allow e.g the Package.swift and header cases to be better represented for SwiftPM, but it looks like that would make things more awkward for things like BuildSystemManager. So I guess this is fine 🤷

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like we had similar thought. I tried that as well, had too many issues in BuildSystemManager and then decided to just go with strings.

///
/// The run destination's ID should be generated by the build system that handles the target and only interpreted by
/// that build system.
public let runDestinationID: String
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need a "configuration" as well, eg. debug/release/etc? Run destination is fairly general, so you could definitely include platform/sdk/architecture/etc in that, but I'm not sure configuration makes much sense there.

Copy link
Member Author

Choose a reason for hiding this comment

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

Discussed offline that we don’t need it for now because the configuration is picked globally when launching sourcekit-lsp. If we do allow changing the configuration while sourcekit-lsp is running, we’ll need to re-consider whether to add configuration here.

return [ConfiguredTarget(targetID: "", runDestinationID: "dummy")]
}

if url.pathExtension == "h", let target = try? target(forHeader: path) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could use defaultLanguage here too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Same here, just assume that a file is a header if it’s not part of the sources. Even if the file is not a header, I think this gives reasonable results.

Say, there was a new .cpp file in a target and for some reason the SwiftPMBuildSystem doesn’t know about it. Then we would infer the target based on the file’s location on disk and generate compiler arguments for it by picking a source file in that target, getting its compiler arguments and then patching up the compiler arguments by replacing the substitute file with the .cpp file.

Copy link
Contributor

Choose a reason for hiding this comment

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

Did you also rename target(forHeader:)? Maybe inferTarget(for:)?

ahoppen added a commit to ahoppen/sourcekit-lsp that referenced this pull request May 16, 2024
ahoppen added a commit to ahoppen/sourcekit-lsp that referenced this pull request May 17, 2024
ahoppen added a commit that referenced this pull request May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants