Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfb8c57a

Browse files
Test: Cover wasm32-unknown-wasip1 with Embedded Swift mode
1 parenta2c2963 commitfb8c57a

File tree

1 file changed

+59
-7
lines changed

1 file changed

+59
-7
lines changed

‎Plugins/PackageToJS/Tests/ExampleTests.swift‎

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,36 @@ extension Trait where Self == ConditionTrait {
1414

1515
staticfunc requireSwiftSDK(triple:String)->ConditionTrait{
1616
.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+
guardlet swiftSDKID=ProcessInfo.processInfo.environment["SWIFT_SDK_ID"],
19+
ProcessInfo.processInfo.environment["SWIFT_PATH"]!=nilelse{
20+
returnfalse
21+
}
22+
func sanityCheckCompatibility(triple:String)->Bool{
23+
return swiftSDKID.hasSuffix(triple)
24+
}
25+
// For compatibility with old SDKs, we check wasm32-unknown-wasi as well when
26+
// wasm32-unknown-wasip1 is requested.
27+
if triple=="wasm32-unknown-wasip1"{
28+
ifsanityCheckCompatibility(triple:"wasm32-unknown-wasi"){
29+
returntrue
30+
}
31+
}
32+
returnsanityCheckCompatibility(triple: triple)
33+
}(),
2034
"Requires SWIFT_SDK_ID and SWIFT_PATH environment variables"
2135
)
2236
}
2337

24-
staticvarrequireEmbeddedSwift:ConditionTrait{
38+
staticfunc requireEmbeddedSwift(triple:String)->ConditionTrait{
2539
// Check if $SWIFT_PATH/../lib/swift/embedded/wasm32-unknown-none-wasm/ exists
2640
return.enabled(
2741
if:{
2842
guardlet swiftPath=ProcessInfo.processInfo.environment["SWIFT_PATH"]else{
2943
returnfalse
3044
}
3145
letembeddedPath=URL(fileURLWithPath: swiftPath).deletingLastPathComponent()
32-
.appending(path:"lib/swift/embedded/wasm32-unknown-none-wasm")
46+
.appending(path:"lib/swift/embedded/\(triple)")
3347
returnFileManager.default.fileExists(atPath: embeddedPath.path)
3448
}(),
3549
"Requires embedded Swift SDK under $SWIFT_PATH/../lib/swift/embedded"
@@ -46,6 +60,28 @@ extension Trait where Self == ConditionTrait {
4660
ProcessInfo.processInfo.environment["SWIFT_PATH"]
4761
}
4862

63+
/// Check if the Swift SDK with the given ID is available.
64+
staticfunc isSwiftSDKAvailable(_ id:String)throws->Bool{
65+
letswiftExecutable=URL(
66+
fileURLWithPath:"swift",
67+
relativeTo:URL(fileURLWithPath:try #require(Self.getSwiftPath()))
68+
)
69+
letprocess=Process()
70+
process.executableURL= swiftExecutable
71+
letarguments=["sdk","configure","--show-configuration", id]
72+
process.arguments= arguments
73+
process.standardOutput=FileHandle.nullDevice
74+
process.standardError=FileHandle.nullDevice
75+
do{
76+
try process.run()
77+
process.waitUntilExit()
78+
return process.terminationStatus==0
79+
}catch{
80+
try #require(Bool(false),"Failed to run swift\(arguments.joined(separator:"")) with error:\(error)")
81+
returnfalse
82+
}
83+
}
84+
4985
staticletrepoPath=URL(fileURLWithPath: #filePath)
5086
.deletingLastPathComponent()
5187
.deletingLastPathComponent()
@@ -220,7 +256,7 @@ extension Trait where Self == ConditionTrait {
220256
letswiftPath=try #require(Self.getSwiftPath())
221257
trywithPackage(at:"Examples/Testing"){ packageDir, runProcess, runSwiftin
222258
tryrunSwift(
223-
["package","--swift-sdk", swiftSDKID,"js","test","--enable-code-coverage"],
259+
["package","--disable-sandbox","--swift-sdk", swiftSDKID,"js","test","--enable-code-coverage"],
224260
[
225261
"LLVM_PROFDATA_PATH":URL(fileURLWithPath: swiftPath).appending(path:"llvm-profdata").path
226262
]
@@ -267,7 +303,8 @@ extension Trait where Self == ConditionTrait {
267303
}
268304
}
269305

270-
@Test(.requireEmbeddedSwift)func embedded()throws{
306+
@Test(.requireEmbeddedSwift(triple:"wasm32-unknown-none-wasm"))
307+
func embeddedWasmUnknownNone()throws{
271308
trywithPackage(at:"Examples/Embedded"){ packageDir, _, runSwiftin
272309
tryrunSwift(
273310
["package","--triple","wasm32-unknown-none-wasm","js","-c","release"],
@@ -278,6 +315,21 @@ extension Trait where Self == ConditionTrait {
278315
}
279316
}
280317

318+
@Test(.requireSwiftSDK(triple:"wasm32-unknown-wasip1"))
319+
func embeddedWasmUnknownWasi()throws{
320+
letbaseSwiftSDKID=try #require(Self.getSwiftSDKID())
321+
letswiftSDKID="\(baseSwiftSDKID)-embedded"
322+
try #require(trySelf.isSwiftSDKAvailable(swiftSDKID),"Embedded Swift SDK with ID\(swiftSDKID) is not available")
323+
trywithPackage(at:"Examples/Embedded"){ packageDir, _, runSwiftin
324+
tryrunSwift(
325+
["package","--swift-sdk", swiftSDKID,"js","-c","release"],
326+
[
327+
"JAVASCRIPTKIT_EXPERIMENTAL_EMBEDDED_WASM":"true"
328+
]
329+
)
330+
}
331+
}
332+
281333
@Test(.requireSwiftSDK)
282334
func continuationLeakInTest_XCTest()throws{
283335
letswiftSDKID=try #require(Self.getSwiftSDKID())

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp