Skip to content

Sever TSC/Driver dependencies if using SwiftBuild Framework #8442

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ if ProcessInfo.processInfo.environment["SWIFTCI_INSTALL_RPATH_OS"] == "android"
*/
let autoProducts = [swiftPMProduct, swiftPMDataModelProduct]

let shoudUseSwiftBuildFramework = (ProcessInfo.processInfo.environment["SWIFTPM_SWBUILD_FRAMEWORK"] != nil)

let swiftDriverDep: [Target.Dependency]
let swiftToolsCoreSupportAutoDep: [Target.Dependency]

if shoudUseSwiftBuildFramework {
swiftDriverDep = []
swiftToolsCoreSupportAutoDep = []
} else {
swiftDriverDep = [
.product(name: "SwiftDriver", package: "swift-driver")
]
swiftToolsCoreSupportAutoDep = [
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core")
]
}
let package = Package(
name: "SwiftPM",
platforms: [
Expand Down Expand Up @@ -231,9 +247,8 @@ let package = Package(
.product(name: "SwiftToolchainCSQLite", package: "swift-toolchain-sqlite", condition: .when(platforms: [.windows, .android])),
.product(name: "DequeModule", package: "swift-collections"),
.product(name: "OrderedCollections", package: "swift-collections"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
.product(name: "SystemPackage", package: "swift-system"),
],
] + swiftToolsCoreSupportAutoDep,
exclude: ["CMakeLists.txt", "Vendor/README.md"],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency"),
Expand Down Expand Up @@ -440,10 +455,9 @@ let package = Package(
"PackageGraph",
"SPMBuildCore",
"SPMLLBuild",
.product(name: "SwiftDriver", package: "swift-driver"),
.product(name: "OrderedCollections", package: "swift-collections"),
"DriverSupport",
],
] + swiftDriverDep,
exclude: ["CMakeLists.txt"],
swiftSettings: [
.unsafeFlags(["-static"]),
Expand All @@ -454,8 +468,7 @@ let package = Package(
dependencies: [
"Basics",
"PackageModel",
.product(name: "SwiftDriver", package: "swift-driver"),
],
] + swiftDriverDep,
exclude: ["CMakeLists.txt"],
swiftSettings: [
.unsafeFlags(["-static"]),
Expand Down Expand Up @@ -1050,8 +1063,7 @@ if ProcessInfo.processInfo.environment["ENABLE_APPLE_PRODUCT_TYPES"] == "1" {
}
}

if ProcessInfo.processInfo.environment["SWIFTPM_SWBUILD_FRAMEWORK"] == nil &&
ProcessInfo.processInfo.environment["SWIFTPM_NO_SWBUILD_DEPENDENCY"] == nil {
if !shoudUseSwiftBuildFramework {
Copy link
Contributor

Choose a reason for hiding this comment

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

Recovering && ProcessInfo.processInfo.environment["SWIFTPM_NO_SWBUILD_DEPENDENCY"] == nil seems to allow the previous behaviour of disabling swift-build completely from SwiftPM.

Copy link
Contributor Author

@bkhouri bkhouri Apr 7, 2025

Choose a reason for hiding this comment

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

The SWIFTPM_NO_SWBUILD_DEPENDENCY was a temporary workaround until we were able to properly integrate SwiftBuild in the toolchain build. I don't believe it's required anymore since #8373 was merged

Copy link
Contributor

Choose a reason for hiding this comment

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

That's unfortunate. It was really helpful for workflows that did not want to use SwiftBuild just yet until all the dust settled. The SwiftPM code seems prepared to work without it, and as the small modification proves, it doesn't seem really necessary for SPM to work.

Copy link
Member

Choose a reason for hiding this comment

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

That code should be dormant until we make it the default build system and that will likely take quite a while yet.


let swiftbuildsupport: Target = package.targets.first(where: { $0.name == "SwiftBuildSupport" } )!
swiftbuildsupport.dependencies += [
Expand Down
4 changes: 0 additions & 4 deletions Tests/CommandsTests/BuildCommandTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -932,10 +932,6 @@ class BuildCommandSwiftBuildTests: BuildCommandTestCases {
}
#endif

if ProcessInfo.processInfo.environment["SWIFTPM_NO_SWBUILD_DEPENDENCY"] != nil {
throw XCTSkip("SWIFTPM_NO_SWBUILD_DEPENDENCY is set so skipping because SwiftPM doesn't have the swift-build capability built inside.")
}

try await super.testBuildSystemDefaultSettings()
}

Expand Down
16 changes: 0 additions & 16 deletions Tests/CommandsTests/TestCommandTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -624,22 +624,6 @@ class TestCommandSwiftBuildTests: TestCommandTestCase {
try await super.testUsage()
}

override func testFatalErrorDisplayedCorrectNumberOfTimesWhenSingleXCTestHasFatalErrorInBuildCompilation() async throws {
guard ProcessInfo.processInfo.environment["SWIFTPM_NO_SWBUILD_DEPENDENCY"] == nil else {
throw XCTSkip("Skipping test because SwiftBuild is not linked in.")
}

try await super.testFatalErrorDisplayedCorrectNumberOfTimesWhenSingleXCTestHasFatalErrorInBuildCompilation()
}

override func testListWithSkipBuildAndNoBuildArtifacts() async throws {
guard ProcessInfo.processInfo.environment["SWIFTPM_NO_SWBUILD_DEPENDENCY"] == nil else {
throw XCTSkip("Skipping test because SwiftBuild is not linked in.")
}

try await super.testListWithSkipBuildAndNoBuildArtifacts()
}

override func testList() async throws {
throw XCTSkip("SWBINTTODO: Test currently fails due to 'error: build failed'")
}
Expand Down