Skip to content

Commit f4b3c67

Browse files
authored
Add Wasm Swift SDK checks for swift run (#166)
This integration test ensures that `swift run` executing Wasm binaries with WasmKit and `import WASILibc` statement do not regress with Wasm Swift SDKs.
1 parent c920730 commit f4b3c67

File tree

6 files changed

+97
-1
lines changed

6 files changed

+97
-1
lines changed

lit.cfg

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ else:
123123
# that's possible
124124
if lit_config.params.get("have-network"):
125125
config.available_features.add("have-network")
126-
126+
127127
###
128128

129129
# Get the package path.
@@ -162,6 +162,9 @@ if swiftpm_srcdir is None:
162162
if os.path.exists(swiftpm_srcdir):
163163
config.available_features.add("have-swiftpm")
164164
config.substitutions.append( ('%{swiftpm_srcdir}', swiftpm_srcdir) )
165+
config.substitutions.append(
166+
('%{swift-sdk-generator_srcdir}', os.path.join(swiftpm_srcdir, "..", "swift-sdk-generator"))
167+
)
165168

166169
# Use the default Swift src layout if Swift the benchmark suite path is not
167170
# provided as a param.
@@ -263,11 +266,13 @@ if swiftpm_build is not None:
263266
config.substitutions.append( ('%{swift-build}', os.path.join(swiftpm_build, "swift-build")) )
264267
config.substitutions.append( ('%{swift-test}', os.path.join(swiftpm_build, "swift-test")) )
265268
config.substitutions.append( ('%{swift-run}', os.path.join(swiftpm_build, "swift-run")) )
269+
config.substitutions.append( ('%{swift-sdk}', os.path.join(swiftpm_build, "swift-sdk")) )
266270
else:
267271
config.substitutions.append( ('%{swift-package}', swift_path + ' package') )
268272
config.substitutions.append( ('%{swift-build}', swift_path + ' build') )
269273
config.substitutions.append( ('%{swift-test}', swift_path + ' test') )
270274
config.substitutions.append( ('%{swift-run}', swift_path + ' run') )
275+
config.substitutions.append( ('%{swift-sdk}', swift_path + ' sdk') )
271276

272277
###
273278

wasm/Hello/.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
xcuserdata/
5+
DerivedData/
6+
.swiftpm/configuration/registries.json
7+
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
8+
.netrc

wasm/Hello/Package.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// swift-tools-version: 6.2
2+
import PackageDescription
3+
4+
let package = Package(
5+
name: "Hello",
6+
targets: [
7+
.executableTarget(
8+
name: "Hello"
9+
),
10+
]
11+
)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import WASILibc
2+
3+
@main
4+
struct Hello {
5+
static func main() {
6+
print("Hello, world!")
7+
puts("Hello from WASILibc!")
8+
}
9+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Testing
2+
import XCTest
3+
@testable import Hello
4+
5+
@Test func example() async throws {
6+
#expect(Int("42") == 42)
7+
}
8+
9+
final class HelloTests: XCTestCase {
10+
func testExample() throws {
11+
XCTAssertEqual(Int("42") == 42)
12+
}
13+
}

wasm/swiftpm.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# SwiftPM checks for Wasm Swift SDKs
2+
3+
This test can only run on Linux CI as we only build Swift SDK for Wasm on Linux CI nodes.
4+
5+
```
6+
REQUIRES: platform=Linux
7+
```
8+
9+
1. Prepare the test environment:
10+
11+
```
12+
RUN: rm -rf %t.dir
13+
RUN: mkdir -p %t.dir/swift-sdks
14+
```
15+
16+
2. Let's install Swift SDK for Wasm:
17+
18+
```
19+
RUN: %{swift-sdk} list --swift-sdks-path %t.dir/swift-sdks | %{FileCheck} --check-prefix CHECK-SDK-LIST-BEFORE %s
20+
CHECK-SDK-LIST-BEFORE: No Swift SDKs are currently installed.
21+
RUN: find "%{swift-sdk-generator_srcdir}/Bundles" -mindepth 1 -maxdepth 1 | xargs %{swift-sdk} install --swift-sdks-path %t.dir/swift-sdks | %{FileCheck} --check-prefix CHECK-SDK-INSTALL %s
22+
CHECK-SDK-INSTALL: Swift SDK bundle at
23+
CHECK-SDK-INSTALL: successfully installed as
24+
RUN: %{swift-sdk} list --swift-sdks-path %t.dir/swift-sdks | grep wasm | wc -l | %{FileCheck} --check-prefix CHECK-SDK-LIST-AFTER %s
25+
CHECK-SDK-LIST-AFTER: 2
26+
```
27+
28+
3. Using a prepared basic package that exercises Swift stdlib and `import WASILibc`:
29+
30+
```
31+
RUN: cp -r %S/Hello %t.dir
32+
```
33+
34+
4. Building and running the prepared package:
35+
36+
a) Non-embedded Swift SDK
37+
38+
```
39+
RUN: %{swift-sdk} list --swift-sdks-path %t.dir/swift-sdks | grep -v embedded | xargs %{swift-run} --swift-sdks-path %t.dir/swift-sdks --package-path %t.dir/Hello --swift-sdk | %{FileCheck} --check-prefix CHECK-RUN-OUTPUT %s
40+
CHECK-RUN-OUTPUT: Hello, world!
41+
CHECK-RUN-OUTPUT-NEXT: Hello from WASILibc!
42+
```
43+
44+
b) Embedded Swift SDK
45+
46+
```
47+
RUN: %{swift-sdk} list --swift-sdks-path %t.dir/swift-sdks | grep embedded | xargs %{swift-run} --swift-sdks-path %t.dir/swift-sdks --package-path %t.dir/Hello --swift-sdk | %{FileCheck} --check-prefix CHECK-EMBEDDED-RUN-OUTPUT %s
48+
CHECK-EMBEDDED-RUN-OUTPUT: Hello, world!
49+
CHECK-EMBEDDED-RUN-OUTPUT-NEXT: Hello from WASILibc!
50+
```

0 commit comments

Comments
 (0)