Skip to content
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

Adopt SwiftBuild.ProjectModel API in the new PIF builder in SwiftBuildSupport #8441

Merged
merged 12 commits into from
Apr 5, 2025

Conversation

pmattos
Copy link
Contributor

@pmattos pmattos commented Apr 2, 2025

Motivation:

The goal is to adopt the new SwiftBuild.ProjectModel API. This new API provides a typesafer and modern way of building PIFs programmatically.

This continues the work I started in PR #8405, introducing now our new PIF builder for packages.

Modifications:

Replaces all SwiftBuild.PIF (aka, SWBProjectModel.PIF) API usage, in PackagePIFBuilder, with the new SwiftBuild.ProjectModel API instead.

PS. I did run swiftformat in all new/changed code, as indicated by the contributors guide.

Result:

PackagePIFBuilder is now modernized... but still not actually used. This will come in my next pull request.

Tracked by rdar://147526957.

@pmattos pmattos marked this pull request as draft April 2, 2025 05:35
@pmattos pmattos changed the title Adopt the SwiftBuild.ProjectModel API in the new PIF builder at SwiftBuildSupport Adopt SwiftBuild.ProjectModel API in the new PIF builder in SwiftBuildSupport Apr 2, 2025
@pmattos
Copy link
Contributor Author

pmattos commented Apr 2, 2025

This is almost ready... I just want to do another pass tomorrow ;)

@pmattos pmattos force-pushed the pmattos/pif-with-project-model-API branch from 1be51a2 to efeb5e2 Compare April 2, 2025 19:55
@@ -1641,7 +1641,7 @@ private struct PIFBuildSettingAssignment {
let platforms: [PIF.BuildSettings.Platform]?
}

extension BuildSettings.AssignmentTable {
extension PackageModel.BuildSettings.AssignmentTable {
fileprivate var pifAssignments: [PIF.BuildSettings.MultipleValueSetting: [PIFBuildSettingAssignment]] {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just fixing naming clashes.

var packageBaseBuildSettings: ProjectModel.BuildSettings {
var settings = BuildSettings()
settings[.SDKROOT] = "auto"
settings[.SDK_VARIANT] = "auto"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is basically how we change build settings now (i.e., using a subscript).

Brace for this exact same code everywhere...

/// Helpers for building custom PIF targets by `PIFPackageBuilder` clients.
extension SwiftBuild.PIF.Project {
extension ProjectModel.BuildSettings {
subscript(_ setting: MultipleValueSetting, default defaultValue: [String]) -> [String] {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now I'm no longer sure if this syntax sugar is such a great idea.... note that it doesn't make it explicit if the default value is prepended or appended (it's the former).

var settings = ProjectModel.BuildSettings() 
settings[.PATH, default: "/bin"] + ["/foo/bar"]
// PATH is now "/bin:/foo/bar"

Copy link
Contributor

Choose a reason for hiding this comment

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

This seems OK to me, I think the syntax here reads as if it implies appending

.OTHER_SWIFT_FLAGS,
.SWIFT_ACTIVE_COMPILATION_CONDITIONS:
let multipleSetting = MultipleValueSetting(from: setting)!
self[multipleSetting, default: ["$(inherited)"]].append(contentsOf: values)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

See my #8441 (comment).


return project
}

public func buildPlaceholderPIF(id: String, path: String, projectDir: String, name: String) -> ModuleOrProduct {
let project = SwiftBuild.PIF.Project(
id: id,
var project = ProjectModel.Project(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All PIF objects are value types now!

@pmattos pmattos marked this pull request as ready for review April 2, 2025 23:03
@jakepetroules
Copy link
Contributor

@swift-ci test

) -> Bool

/// Should we set the install path for a dynamic library/framework?
func shouldSetInstallPathForDynamicLib(productName: String) -> Bool

// FIXME: Let's try to replace `WritableKeyPath><_, Foo>` with `inout Foo` —— Paulo
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a note for future work in a later PR?

@jakepetroules
Copy link
Contributor

@swift-ci test

@pmattos
Copy link
Contributor Author

pmattos commented Apr 3, 2025

@swift-ci test

1 similar comment
@pmattos
Copy link
Contributor Author

pmattos commented Apr 3, 2025

@swift-ci test

@pmattos
Copy link
Contributor Author

pmattos commented Apr 3, 2025

@swift-ci please test self hosted macos

1 similar comment
@jakepetroules
Copy link
Contributor

@swift-ci please test self hosted macos

@jakepetroules
Copy link
Contributor

@swift-ci test

@jakepetroules
Copy link
Contributor

@swift-ci test self hosted windows

@jakepetroules
Copy link
Contributor

@swift-ci smoke test macos

2 similar comments
@jakepetroules
Copy link
Contributor

@swift-ci smoke test macos

@pmattos
Copy link
Contributor Author

pmattos commented Apr 4, 2025

@swift-ci smoke test macos

@bkhouri
Copy link
Contributor

bkhouri commented Apr 4, 2025

@swift-ci test macOS

@pmattos pmattos merged commit c8d439a into main Apr 5, 2025
6 checks passed
@pmattos pmattos deleted the pmattos/pif-with-project-model-API branch April 5, 2025 03:31
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