Skip to content

Commit e78cc4c

Browse files
authored
Fix use of extraCPPFlags (#5793)
We should not use `extraCPPFlags` as a vehicle for specifying linker flags, instead just decide on which C++ library to link based on the target triple in `BuildPlan`. Separately, it seems worthwhile to look into refactoring `Destination` to actually allow specifying linker flags since that seems to have been an accidental feature of `extraCPPFlags` (as long as one didn't pass compiler flags there as well). rdar://100575898
1 parent 17b3ad8 commit e78cc4c

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

Sources/Build/BuildPlan.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2080,7 +2080,13 @@ public class BuildPlan {
20802080
// Note: This will come from build settings in future.
20812081
for target in dependencies.staticTargets {
20822082
if case let target as ClangTarget = target.underlyingTarget, target.isCXX {
2083-
buildProduct.additionalFlags += self.buildParameters.toolchain.extraCPPFlags
2083+
if buildParameters.hostTriple.isDarwin() {
2084+
buildProduct.additionalFlags += ["-lc++"]
2085+
} else if buildParameters.hostTriple.isWindows() {
2086+
// Don't link any C++ library.
2087+
} else {
2088+
buildProduct.additionalFlags += ["-lstdc++"]
2089+
}
20842090
break
20852091
}
20862092
}

Sources/PackageModel/Destination.swift

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,22 +151,13 @@ public struct Destination: Encodable, Equatable {
151151
extraCCFlags += ["-fPIC"]
152152
#endif
153153

154-
var extraCPPFlags: [String] = []
155-
#if os(macOS)
156-
extraCPPFlags += ["-lc++"]
157-
#elseif os(Windows)
158-
extraCPPFlags += []
159-
#else
160-
extraCPPFlags += ["-lstdc++"]
161-
#endif
162-
163154
return Destination(
164155
target: nil,
165156
sdk: sdkPath,
166157
binDir: binDir,
167158
extraCCFlags: extraCCFlags,
168159
extraSwiftCFlags: extraSwiftCFlags,
169-
extraCPPFlags: extraCPPFlags
160+
extraCPPFlags: []
170161
)
171162
}
172163

0 commit comments

Comments
 (0)