@@ -104,4 +104,135 @@ fileprivate struct StaticLinuxSDKIntegrationTests: CoreBasedTests {
104104 }
105105 }
106106 }
107+
108+ // Regression test for https://github.com/swiftlang/swift-package-manager/issues/10237
109+ @Test ( . requireSDKs( . host) , . requiresStaticLinuxSwiftSDK, . skipXcodeToolchain)
110+ func cxxabiStaticLinking( ) async throws {
111+ try await withTemporaryDirectory { ( tmpDir: Path ) in
112+ let testProject = try await TestProject (
113+ " TestProject " ,
114+ sourceRoot: tmpDir,
115+ groupTree: TestGroup (
116+ " SomeFiles " ,
117+ children: [
118+ TestFile ( " main.swift " ) ,
119+ TestFile ( " bridging.h " ) ,
120+ TestFile ( " cxx1.cpp " ) ,
121+ TestFile ( " cxx2.cpp " ) ,
122+ ] ) ,
123+ buildConfigurations: [
124+ TestBuildConfiguration ( " Debug " , buildSettings: [
125+ " PRODUCT_NAME " : " $(TARGET_NAME) " ,
126+ " SDKROOT " : " auto " ,
127+ " SUPPORTED_PLATFORMS " : " $(AVAILABLE_PLATFORMS) " ,
128+ " SWIFT_VERSION " : swiftVersion,
129+ " LINKER_DRIVER " : " auto " ,
130+ ] )
131+ ] ,
132+ targets: [
133+ TestStandardTarget (
134+ " tool " ,
135+ type: . commandLineTool,
136+ buildConfigurations: [
137+ TestBuildConfiguration ( " Debug " , buildSettings: [
138+ " SWIFT_OBJC_BRIDGING_HEADER " : " $(SRCROOT)/bridging.h " ,
139+ ] )
140+ ] ,
141+ buildPhases: [
142+ TestSourcesBuildPhase ( [ " main.swift " ] ) ,
143+ TestFrameworksBuildPhase ( [
144+ TestBuildFile ( . target( " cxx1 " ) ) ,
145+ TestBuildFile ( . target( " cxx2 " ) ) ,
146+ ] )
147+ ] ,
148+ dependencies: [
149+ " cxx1 " ,
150+ " cxx2 " ,
151+ ]
152+ ) ,
153+ TestStandardTarget (
154+ " cxx1 " ,
155+ type: . commonObject,
156+ buildConfigurations: [
157+ TestBuildConfiguration ( " Debug " )
158+ ] ,
159+ buildPhases: [
160+ TestSourcesBuildPhase ( [ " cxx1.cpp " ] ) ,
161+ ]
162+ ) ,
163+ TestStandardTarget (
164+ " cxx2 " ,
165+ type: . commonObject,
166+ buildConfigurations: [
167+ TestBuildConfiguration ( " Debug " )
168+ ] ,
169+ buildPhases: [
170+ TestSourcesBuildPhase ( [ " cxx2.cpp " ] ) ,
171+ ]
172+ ) ,
173+ ] )
174+
175+ let core = try await Self . getSwiftSDKIntegrationTestingCore ( )
176+ let tester = try await BuildOperationTester ( core, testProject, simulated: false )
177+
178+ let projectDir = tester. workspace. projects [ 0 ] . sourceRoot
179+
180+ try await tester. fs. writeFileContents ( projectDir. join ( " main.swift " ) ) { stream in
181+ stream <<< """
182+ #if canImport(Musl)
183+ print( " Hello from Static Linux! \\ (cxx1() + cxx2()) " )
184+ #else
185+ #error( " should not be active " )
186+ #endif
187+ """
188+ }
189+
190+ try await tester. fs. writeFileContents ( projectDir. join ( " bridging.h " ) ) { stream in
191+ stream <<< """
192+ int cxx1(void);
193+ int cxx2(void);
194+ """
195+ }
196+
197+ try await tester. fs. writeFileContents ( projectDir. join ( " cxx1.cpp " ) ) { stream in
198+ stream <<< """
199+ extern " C " int cxx1() {
200+ try {
201+ throw 1;
202+ } catch (...) {
203+ return 1;
204+ }
205+ return 0;
206+ }
207+ """
208+ }
209+
210+ try await tester. fs. writeFileContents ( projectDir. join ( " cxx2.cpp " ) ) { stream in
211+ stream <<< """
212+ extern " C " int cxx2() {
213+ try {
214+ throw 2;
215+ } catch (...) {
216+ return 2;
217+ }
218+ return 0;
219+ }
220+ """
221+ }
222+
223+ let hostArch = try {
224+ let arch = try #require( Architecture . hostStringValue)
225+ if arch == " arm64 " {
226+ return " aarch64 "
227+ }
228+ return arch
229+ } ( )
230+ let triple = " \( hostArch) -swift-linux-musl "
231+ let swiftSDK = try #require( await core. findStaticLinuxSwiftSDK ( ) )
232+ let destination = try RunDestinationInfo ( sdkManifestPath: swiftSDK. manifestPath, triple: triple, targetArchitecture: hostArch, supportedArchitectures: [ hostArch] , disableOnlyActiveArch: false , core: core)
233+ try await tester. checkBuild ( runDestination: destination) { results in
234+ results. checkNoErrors ( )
235+ }
236+ }
237+ }
107238}
0 commit comments