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

Create an alternate SwiftPM build system called Swift Build #8271

Merged
merged 3 commits into from
Mar 3, 2025

Conversation

cmcgee1024
Copy link
Member

Add basic test coverage for the new build system for the supported platforms: Linux, macOS, and Windows. Provide basic progress reporting, and an option for "very verbose" mode so that that individual build tasks and the arguments can be inspected for correctness.

Build a package with the new build system like this:

swift build --build-system=swiftbuild

Enable very verbose task outputs with their flags, options, and arguments:

swift build --build-system=swiftbuild --vv

jakepetroules added a commit to swiftlang/swift-build that referenced this pull request Feb 1, 2025
It was only active on macOS and Linux but not other platforms due to existing dependency complexities, and just isn't that useful overall. This will help unblock swiftlang/swift-package-manager#8271 without having to add new dependencies to the Swift Docker images.
@rauhul
Copy link
Member

rauhul commented Feb 1, 2025

Not a review comment, but I can't wait for this to land :D this is awesome!

jakepetroules added a commit to swiftlang/swift-build that referenced this pull request Feb 1, 2025
It was only active on macOS and Linux but not other platforms due to existing dependency complexities, and just isn't that useful overall. This will help unblock swiftlang/swift-package-manager#8271 without having to add new dependencies to the Swift Docker images.
jakepetroules added a commit to swiftlang/swift-build that referenced this pull request Feb 1, 2025
It was only active on macOS and Linux but not other platforms due to existing dependency complexities, and just isn't that useful overall. This will help unblock swiftlang/swift-package-manager#8271 without having to add new dependencies to the Swift Docker images.
@dschaefer2
Copy link
Member

I just tried this out and get:

error: Dependencies could not be resolved because root depends on 'swift-argument-parser' 1.4.0..<1.5.0 and 'swift-driver' depends on 'swift-argument-parser' 1.2.2..<1.3.0.

@dschaefer2
Copy link
Member

Never mind, had a really old version of the deps. Did a swift package update and it's going now.

@dschaefer2
Copy link
Member

Build works on my Mac. A few weird warnings. Also looks like swift-test has hardcoded the location of the xctest bundle to the old scratch dir (.build) layout. Lots of work to do indeed :).

Thanks @cmcgee1024. This is a great start!

@swiftlang swiftlang deleted a comment from jakepetroules Feb 1, 2025
@swiftlang swiftlang deleted a comment from jakepetroules Feb 1, 2025
Copy link
Contributor

@bkhouri bkhouri left a comment

Choose a reason for hiding this comment

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

I have not reviewed this extensively, however there are a few minor comments.

Xswiftc: Xswiftc,
buildSystem: buildSystem
)
let buildArgs = getBuildSystemArgs(for: buildSystem)
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (non-blocking): this call is not needed as the build system argument is handled in swiftArgs()

@@ -230,6 +230,8 @@ public final class XcodeBuildSystem: SPMBuildCore.BuildSystem {

throw Diagnostics.fatalError
}

print("Build complete!")
Copy link
Contributor

Choose a reason for hiding this comment

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

question: are changes to this file necessary?

Copy link
Contributor

@MaxDesiatov MaxDesiatov Feb 5, 2025

Choose a reason for hiding this comment

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

Also, this should use existing logging facilities that respect -v/-q settings.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've converted this over to use an observability scope emit. One problem though, is that we probably want this output to be emitted in all log levels, but I don't want to indicate that it is an error.

if report {
progressAnimation.complete(success: false)
// FIXME: a whole range of pretty printed location, context, and fixups
print("\(info.kind): \(info.location) \(info.message) \(info.fixIts)")
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (possibly-blocking): Instead of a print call, can we use the observabilityScope.emit(...) calls?

This comment applies to everywhere we are using print calls.

Copy link
Contributor

@MaxDesiatov MaxDesiatov Feb 5, 2025

Choose a reason for hiding this comment

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

I agree, we should avoid using print and rely on existing logging facilities instead, especially since those can propagate diagnostic information like message level and location already.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've converted the print calls to observability scopes. See my note above about what to do about certain kinds of messages like "Build complete!"

Copy link
Contributor

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

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

I am concerned by uses of print here. We have commands like swift-run that are supposed to only print freshly-built product's output. The rest of diagnostic messages even successful ones like "Build complete" should go to stderr, since there is an existing body of scripts and utilities that read from swift-run invocations stdout via a pipe. Stray print polluting such output with diagnostics will break those scripts.

@cmcgee1024
Copy link
Member Author

@swift-ci please test

Copy link
Contributor

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

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

IMO removing existing expectations for cross-compilation for existing build systems is a significant regression in the test suite. I'm totally ok with merging Swift Build support if it can't cross-compile yet, but it shouldn't come at the expense of reducing the test coverage for other build systems.

@cmcgee1024
Copy link
Member Author

IMO removing existing expectations for cross-compilation for existing build systems is a significant regression in the test suite. I'm totally ok with merging Swift Build support if it can't cross-compile yet, but it shouldn't come at the expense of reducing the test coverage for other build systems.

This is an issue with the CI infrastructure using an old Xcode that can't handle Swift 6, which is required by the SwiftBuild code. I will ask about getting the CI updated with a newer version.

@cmcgee1024
Copy link
Member Author

Please test with following pull request:
apple/swift-crypto#326
apple/swift-asn1#88

@swift-ci test windows

bkhouri added a commit to bkhouri/swift-package-manager that referenced this pull request Feb 19, 2025
There are a few places that check the BuildSystemProvider.Kind is Xcode
to determine the build directory structure.  With the upcoming Swift
Build integration, which uses the "Xcode path" structure, we would need
to update all instances to check the two build system provider kinds.

Add an extension on the BuildSystemProvider.Kind that create a boolean
variable `useXcodeBuildSystemPath`, which determines whether the build
system should use the xcode path structure or not.  In addition, update
the code that requires a  "isXcodeBuildSystemEnabled" to return this
build system provider variable.

This will hopefully help address swiftlang#8272 when swiftlang#8271, where it adds
`case .swiftbuild: return true` to the `useXcodeBuildSystemPath`
bkhouri added a commit to bkhouri/swift-package-manager that referenced this pull request Feb 20, 2025
There are a few places that check the BuildSystemProvider.Kind is Xcode
to determine the build directory structure.  With the upcoming Swift
Build integration, which uses the "Xcode path" structure, we would need
to update all instances to check the two build system provider kinds.

Add an extension on the BuildSystemProvider.Kind that create a boolean
variable `useXcodeBuildEngine`, which determines whether the build
system should use the xcode path structure or not.  In addition, update
the code that requires a  "isXcodeBuildSystemEnabled" to return this
build system provider variable.

This will hopefully help address swiftlang#8272 when swiftlang#8271, where it adds
`case .swiftbuild: return true` to the `useXcodeBuildEngine`
@cmcgee1024
Copy link
Member Author

Please test with following pull request:
apple/swift-crypto#326

@swift-ci please test

bkhouri added a commit to bkhouri/swift-package-manager that referenced this pull request Feb 25, 2025
There are a few places that check the BuildSystemProvider.Kind is Xcode
to determine the build directory structure.  With the upcoming Swift
Build integration, which uses the "Xcode path" structure, we would need
to update all instances to check the two build system provider kinds.

Add an extension on the BuildSystemProvider.Kind that create a boolean
variable `useXcodeBuildEngine`, which determines whether the build
system should use the xcode path structure or not.  In addition, update
the code that requires a  "isXcodeBuildSystemEnabled" to return this
build system provider variable.

This will hopefully help address swiftlang#8272 when swiftlang#8271, where it adds
`case .swiftbuild: return true` to the `useXcodeBuildEngine`
@dschaefer2
Copy link
Member

@swift-ci please test

bkhouri added a commit that referenced this pull request Feb 26, 2025
There are a few places that check the BuildSystemProvider.Kind is Xcode
to determine the build directory structure. With the upcoming Swift
Build integration, which uses the "Xcode path" structure, we would need
to update all instances to check the two build system provider kinds.

Add an extension on the BuildSystemProvider.Kind that create a boolean
variable `useXcodeBuildEngine`, which determines whether the build
system should use the xcode path structure or not. In addition, update
the code that requires a "isXcodeBuildSystemEnabled" to return this
build system provider variable.

This will hopefully help address #8272 when #8271 is merged and added
`case .swiftbuild: return true` to the `useXcodeBuildEngine `

Fixes #8272
rdar://144023142
@dschaefer2
Copy link
Member

DriverSupport needs swift-driver always independent of swift-build.

@@ -560,7 +560,12 @@ extension ResolvedPackagesStore.ResolvedPackage {
let location = mirrors.effective(for: pin.location)
switch pin.kind {
case .localSourceControl:
packageRef = try .localSourceControl(identity: identity, path: AbsolutePath(validating: location))
// FIXME investigate why local source control packages resolve to a non-local URL location
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 change intended to be part of the PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

This could be an artifact of one of the previous approaches to getting the CI working. I will try disable it and see if everything continues to succeed.

Package.swift Outdated
.package(url: "https://github.com/apple/swift-crypto.git", .upToNextMinor(from: "3.0.0")),
.package(url: "https://github.com/swiftlang/swift-syntax.git", branch: relatedDependenciesBranch),
.package(url: "https://github.com/apple/swift-system.git", from: "1.1.1"),
.package(url: "https://github.com/apple/swift-collections.git", "1.0.1" ..< "1.2.0"),
.package(url: "https://github.com/apple/swift-certificates.git", "1.0.1" ..< "1.6.0"),
.package(url: "https://github.com/swiftlang/swift-toolchain-sqlite.git", from: "1.0.0"),
.package(url: "https://github.com/apple/swift-driver.git", branch: relatedDependenciesBranch),
Copy link
Member

Choose a reason for hiding this comment

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

This should come from swiftlang.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've basically undone this diff, so it is the same as what is currently in main.

@cmcgee1024
Copy link
Member Author

@swift-ci test windows

@cmcgee1024
Copy link
Member Author

@swift-ci test macOS

@owenv
Copy link
Contributor

owenv commented Feb 28, 2025

@swift-ci build toolchain

Add basic test coverage for the new build system for the supported platforms:
Linux, macOS, and Windows. Provide basic progress reporting, and an option
for "very verbose" mode so that that individual build tasks and the arguments
can be inspected for correctness.

Build a package with the new build system like this:

    swift build --build-system=swiftbuild

Enable very verbose task outputs with their flags, options, and arguments:

    swift build --build-system=swiftbuild --vv
@cmcgee1024 cmcgee1024 force-pushed the swiftbuild_integration branch from e069aa4 to 60b1702 Compare February 28, 2025 14:56
@cmcgee1024
Copy link
Member Author

@swift-ci please test

@@ -138,6 +138,9 @@ def main() -> None:
shlex.split("swift --version"),
)

call(
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, why was this added it? Are previous CI builds impacting the current PR build?

Copy link
Member Author

Choose a reason for hiding this comment

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

This was added because the package may have been built earlier using the bootstrap with the environment variable set to exclude swift-build as a dependency. This is one of the issues with using environment variables in packages. If you flip them then SwiftPM may not be aware of the change and produce inconsistent build results since its build graph is not obviously out of sync with the current package state.

I believe that adding this will force the package to be entirely reset, and cleaned before building it again with swift-build support.

bripeticca pushed a commit to bripeticca/swift-package-manager that referenced this pull request Feb 28, 2025
…lang#8298)

There are a few places that check the BuildSystemProvider.Kind is Xcode
to determine the build directory structure. With the upcoming Swift
Build integration, which uses the "Xcode path" structure, we would need
to update all instances to check the two build system provider kinds.

Add an extension on the BuildSystemProvider.Kind that create a boolean
variable `useXcodeBuildEngine`, which determines whether the build
system should use the xcode path structure or not. In addition, update
the code that requires a "isXcodeBuildSystemEnabled" to return this
build system provider variable.

This will hopefully help address swiftlang#8272 when swiftlang#8271 is merged and added
`case .swiftbuild: return true` to the `useXcodeBuildEngine `

Fixes swiftlang#8272
rdar://144023142
@cmcgee1024
Copy link
Member Author

@swift-ci please test

@cmcgee1024
Copy link
Member Author

@swift-ci test Linux

@cmcgee1024
Copy link
Member Author

@swift-ci test Windows

bkhouri
bkhouri previously requested changes Mar 2, 2025
@@ -172,6 +173,7 @@ extension BuildSystemProvider.Kind {
public var usesXcodeBuildEngine: Bool {
switch self {
case .native: return false
case .swiftbuild: return false
Copy link
Contributor

Choose a reason for hiding this comment

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

Chore (blocking): this should return "true"

Copy link
Member Author

Choose a reason for hiding this comment

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

SwiftBuild isn't using any Xcode or its build engine. It's unclear what this check is for.

Copy link
Contributor

@bkhouri bkhouri Mar 3, 2025

Choose a reason for hiding this comment

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

The variable name may be incorrect, but this is meant to determine if the underlying build engine uses the same "build output directory structure" as Xcode.

Setting this to true will likely resolve #8272

Copy link
Member

Choose a reason for hiding this comment

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

SwiftBuild doesn't use the same directory structure.

extension BuildConfiguration {
public var swiftbuildName: String {
switch self {
case .debug: "Debug"
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: can we have the build configuration confirm to "ConvertibleString" ?

@bkhouri bkhouri dismissed their stale review March 3, 2025 14:44

We can fix the swift test in a subsequent change

@dschaefer2 dschaefer2 merged commit af93a3c into swiftlang:main Mar 3, 2025
5 checks passed
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.

7 participants