@@ -14,27 +14,78 @@ extension Trait where Self == ConditionTrait {
14
14
15
15
static func requireSwiftSDK( triple: String ) -> ConditionTrait {
16
16
. enabled(
17
- if: ProcessInfo . processInfo. environment [ " SWIFT_SDK_ID " ] != nil
18
- && ProcessInfo . processInfo. environment [ " SWIFT_PATH " ] != nil
19
- && ProcessInfo . processInfo. environment [ " SWIFT_SDK_ID " ] !. hasSuffix ( triple) ,
17
+ if: {
18
+ guard let swiftSDKID = ProcessInfo . processInfo. environment [ " SWIFT_SDK_ID " ] ,
19
+ ProcessInfo . processInfo. environment [ " SWIFT_PATH " ] != nil
20
+ else {
21
+ return false
22
+ }
23
+ func sanityCheckCompatibility( triple: String ) -> Bool {
24
+ return swiftSDKID. hasSuffix ( triple)
25
+ }
26
+ // For compatibility with old SDKs, we check wasm32-unknown-wasi as well when
27
+ // wasm32-unknown-wasip1 is requested.
28
+ if triple == " wasm32-unknown-wasip1 " {
29
+ if sanityCheckCompatibility ( triple: " wasm32-unknown-wasi " ) {
30
+ return true
31
+ }
32
+ }
33
+ return sanityCheckCompatibility ( triple: triple)
34
+ } ( ) ,
20
35
" Requires SWIFT_SDK_ID and SWIFT_PATH environment variables "
21
36
)
22
37
}
23
38
24
- static var requireEmbeddedSwift : ConditionTrait {
39
+ static func requireEmbeddedSwiftInToolchain ( triple : String ) -> ConditionTrait {
25
40
// Check if $SWIFT_PATH/../lib/swift/embedded/wasm32-unknown-none-wasm/ exists
26
41
return . enabled(
27
42
if: {
28
43
guard let swiftPath = ProcessInfo . processInfo. environment [ " SWIFT_PATH " ] else {
29
44
return false
30
45
}
31
46
let embeddedPath = URL ( fileURLWithPath: swiftPath) . deletingLastPathComponent ( )
32
- . appending ( path: " lib/swift/embedded/wasm32-unknown-none-wasm " )
47
+ . appending ( path: " lib/swift/embedded/ \( triple ) " )
33
48
return FileManager . default. fileExists ( atPath: embeddedPath. path)
34
49
} ( ) ,
35
50
" Requires embedded Swift SDK under $SWIFT_PATH/../lib/swift/embedded "
36
51
)
37
52
}
53
+
54
+ static func requireEmbeddedSwiftInSwiftSDK( ) -> ConditionTrait {
55
+ // Check if ${SWIFT_SDK_ID}-embedded is available
56
+ return . enabled(
57
+ if: {
58
+ /// Check if the Swift SDK with the given ID is available.
59
+ func isSwiftSDKAvailable( _ id: String , swiftPath: String ) -> Bool {
60
+ let swiftExecutable = URL (
61
+ fileURLWithPath: " swift " ,
62
+ relativeTo: URL ( fileURLWithPath: swiftPath)
63
+ )
64
+ let process = Process ( )
65
+ process. executableURL = swiftExecutable
66
+ let arguments = [ " sdk " , " configure " , " --show-configuration " , id]
67
+ process. arguments = arguments
68
+ process. standardOutput = FileHandle . nullDevice
69
+ process. standardError = FileHandle . nullDevice
70
+ do {
71
+ try process. run ( )
72
+ process. waitUntilExit ( )
73
+ return process. terminationStatus == 0
74
+ } catch {
75
+ return false
76
+ }
77
+ }
78
+ guard let swiftPath = ProcessInfo . processInfo. environment [ " SWIFT_PATH " ] ,
79
+ let swiftSDKID = ProcessInfo . processInfo. environment [ " SWIFT_SDK_ID " ]
80
+ else {
81
+ return false
82
+ }
83
+ let embeddedSDKID = " \( swiftSDKID) -embedded "
84
+ return isSwiftSDKAvailable ( embeddedSDKID, swiftPath: swiftPath)
85
+ } ( ) ,
86
+ " Requires SWIFT_SDK_ID to contain 'embedded' "
87
+ )
88
+ }
38
89
}
39
90
40
91
@Suite struct ExampleTests {
@@ -46,6 +97,11 @@ extension Trait where Self == ConditionTrait {
46
97
ProcessInfo . processInfo. environment [ " SWIFT_PATH " ]
47
98
}
48
99
100
+ static func getEmbeddedSwiftSDKID( ) -> String ? {
101
+ guard let swiftSDKID = getSwiftSDKID ( ) else { return nil }
102
+ return " \( swiftSDKID) -embedded "
103
+ }
104
+
49
105
static let repoPath = URL ( fileURLWithPath: #filePath)
50
106
. deletingLastPathComponent ( )
51
107
. deletingLastPathComponent ( )
@@ -220,7 +276,7 @@ extension Trait where Self == ConditionTrait {
220
276
let swiftPath = try #require( Self . getSwiftPath ( ) )
221
277
try withPackage ( at: " Examples/Testing " ) { packageDir, runProcess, runSwift in
222
278
try runSwift (
223
- [ " package " , " --swift-sdk " , swiftSDKID, " js " , " test " , " --enable-code-coverage " ] ,
279
+ [ " package " , " --disable-sandbox " , " -- swift-sdk" , swiftSDKID, " js " , " test " , " --enable-code-coverage " ] ,
224
280
[
225
281
" LLVM_PROFDATA_PATH " : URL ( fileURLWithPath: swiftPath) . appending ( path: " llvm-profdata " ) . path
226
282
]
@@ -267,7 +323,8 @@ extension Trait where Self == ConditionTrait {
267
323
}
268
324
}
269
325
270
- @Test ( . requireEmbeddedSwift) func embedded( ) throws {
326
+ @Test ( . requireEmbeddedSwiftInToolchain( triple: " wasm32-unknown-none-wasm " ) )
327
+ func embeddedWasmUnknownNone( ) throws {
271
328
try withPackage ( at: " Examples/Embedded " ) { packageDir, _, runSwift in
272
329
try runSwift (
273
330
[ " package " , " --triple " , " wasm32-unknown-none-wasm " , " js " , " -c " , " release " ] ,
@@ -278,6 +335,19 @@ extension Trait where Self == ConditionTrait {
278
335
}
279
336
}
280
337
338
+ @Test ( . requireEmbeddedSwiftInSwiftSDK( ) )
339
+ func embeddedWasmUnknownWasi( ) throws {
340
+ let swiftSDKID = try #require( Self . getEmbeddedSwiftSDKID ( ) )
341
+ try withPackage ( at: " Examples/Embedded " ) { packageDir, _, runSwift in
342
+ try runSwift (
343
+ [ " package " , " --swift-sdk " , swiftSDKID, " js " , " -c " , " release " ] ,
344
+ [
345
+ " JAVASCRIPTKIT_EXPERIMENTAL_EMBEDDED_WASM " : " true "
346
+ ]
347
+ )
348
+ }
349
+ }
350
+
281
351
@Test ( . requireSwiftSDK)
282
352
func continuationLeakInTest_XCTest( ) throws {
283
353
let swiftSDKID = try #require( Self . getSwiftSDKID ( ) )
0 commit comments