Skip to content

Commit

Permalink
Fix testable executables once more
Browse files Browse the repository at this point in the history
A previous problem here was fixed in #6723, this new fix is attempting to resolve issues where macros are used transitively by a product that a test is depending on. It seems to me that those transitively available macros should not be statically linked into tests and in fact doing so can cause various issues such as linker errors on non-Darwin platforms.

It does feel like eventually we need to get away from `computeDependencies(of:)` being a computation on the entire package graph and instead let each package produce separate products which we can then just use transitively, but that is a much bigger change to SwiftPM's build system.

rdar://115071012
  • Loading branch information
neonichu committed Sep 6, 2023
1 parent 92e0e8f commit 0917f65
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Sources/Build/BuildPlan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,9 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
if product.targets.contains(target) {
staticTargets.append(target)
} else if product.type == .test && (target.underlyingTarget as? SwiftTarget)?.supportsTestableExecutablesFeature == true {
if let toolsVersion = graph.package(for: product)?.manifest.toolsVersion, toolsVersion >= .v5_5 {
// Only "top-level" targets should really be considered here, not transitive ones.
let isTopLevel = topLevelDependencies.contains(target.underlyingTarget) || product.targets.contains(target)
if let toolsVersion = graph.package(for: product)?.manifest.toolsVersion, toolsVersion >= .v5_5, isTopLevel {
staticTargets.append(target)
}
}
Expand Down

0 comments on commit 0917f65

Please sign in to comment.