Skip to content

Sever the package dependency if using SwiftBuild Framework #8434

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
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
32 changes: 24 additions & 8 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,26 @@ if ProcessInfo.processInfo.environment["SWIFTCI_INSTALL_RPATH_OS"] == "android"
*/
let autoProducts = [swiftPMProduct, swiftPMDataModelProduct]

private func useSwiftBuildPackageDependency() -> Bool {
return (ProcessInfo.processInfo.environment["SWIFTPM_SWBUILD_FRAMEWORK"] == nil &&
ProcessInfo.processInfo.environment["SWIFTPM_NO_SWBUILD_DEPENDENCY"] == nil)
}
Comment on lines +90 to +93
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a particular reason this uses a function instead of a simple let binding? I also don't think private is needed here, there's no chance this function could be used accidentally elsewhere, since multi-file package manifest is not a thing.

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 used in two places, so instead of duplicating the logic, I opted to put it in a function call.

Copy link
Contributor

@MaxDesiatov MaxDesiatov Apr 1, 2025

Choose a reason for hiding this comment

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

But is there a need to duplicate the logic with a let binding? With a function the computation is duplicated since the function is invoked twice, while with a let binding it would be computed only once.


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

if useSwiftBuildPackageDependency() {
swiftDriverDep = [
.product(name: "SwiftDriver", package: "swift-driver")
]
swiftToolsCoreSupportAutoDep = [
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core")
]
} else {
swiftDriverDep = []
swiftToolsCoreSupportAutoDep = []
}
let package = Package(
name: "SwiftPM",
platforms: [
Expand Down Expand Up @@ -231,9 +251,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 +459,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 +472,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 +1067,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 useSwiftBuildPackageDependency() {

let swiftbuildsupport: Target = package.targets.first(where: { $0.name == "SwiftBuildSupport" } )!
swiftbuildsupport.dependencies += [
Expand Down