Skip to content

Commit 7fb1f30

Browse files
committed
Add Wasm Swift SDK checks for swift run and swift test
1 parent c920730 commit 7fb1f30

File tree

6 files changed

+108
-1
lines changed

6 files changed

+108
-1
lines changed

lit.cfg

Lines changed: 7 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,10 @@ 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+
)
168+
config.substitutions.append( ('%{swiftpm_homedir}', os.path.join(os.environ['HOME'], ".swiftpm", "swift-sdks")) )
165169

166170
# Use the default Swift src layout if Swift the benchmark suite path is not
167171
# provided as a param.
@@ -263,11 +267,13 @@ if swiftpm_build is not None:
263267
config.substitutions.append( ('%{swift-build}', os.path.join(swiftpm_build, "swift-build")) )
264268
config.substitutions.append( ('%{swift-test}', os.path.join(swiftpm_build, "swift-test")) )
265269
config.substitutions.append( ('%{swift-run}', os.path.join(swiftpm_build, "swift-run")) )
270+
config.substitutions.append( ('%{swift-sdk}', os.path.join(swiftpm_build, "swift-sdk")) )
266271
else:
267272
config.substitutions.append( ('%{swift-package}', swift_path + ' package') )
268273
config.substitutions.append( ('%{swift-build}', swift_path + ' build') )
269274
config.substitutions.append( ('%{swift-test}', swift_path + ' test') )
270275
config.substitutions.append( ('%{swift-run}', swift_path + ' run') )
276+
config.substitutions.append( ('%{swift-sdk}', swift_path + ' sdk') )
271277

272278
###
273279

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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// swift-tools-version: 6.2
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "Hello",
8+
targets: [
9+
// Targets are the basic building blocks of a package, defining a module or a test suite.
10+
// Targets can depend on other targets in this package and products from dependencies.
11+
.executableTarget(
12+
name: "Hello"
13+
),
14+
]
15+
)
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: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# SwiftPM checks for Wasm Swift SDKs
2+
3+
1. Let's install Swift SDK for Wasm first:
4+
5+
```
6+
RUN: %{swift-sdk} list | %{FileCheck} --check-prefix CHECK-SDK-LIST-BEFORE %s
7+
CHECK-SDK-LIST-BEFORE: No Swift SDKs are currently installed.
8+
RUN: find "%{swift-sdk-generator_srcdir}/Bundles" -d 1 | xargs %{swift-sdk} install | %{FileCheck} --check-prefix CHECK-SDK-INSTALL %s
9+
CHECK-SDK-INSTALL: Swift SDK bundle at
10+
CHECK-SDK-INSTALL: successfully installed as
11+
RUN: %{swift-sdk} list | grep wasm | wc -l | %{FileCheck} --check-prefix CHECK-SDK-LIST-AFTER %s
12+
CHECK-SDK-LIST-AFTER: 2
13+
```
14+
15+
2. Creating a package from `init` template:
16+
17+
```
18+
RUN: rm -rf %t.dir
19+
RUN: mkdir -p %t.dir
20+
RUN: cp -r %S/Hello %t.dir
21+
```
22+
23+
3. Building and running prepared `"Hello, world!"` executable from the newly created package:
24+
25+
a) Non-embedded Swift SDK
26+
27+
```
28+
RUN: %{swift-sdk} list | grep -v embedded | xargs %{swift-run} --package-path %t.dir/Hello --swift-sdk | %{FileCheck} --check-prefix CHECK-RUN-OUTPUT %s
29+
CHECK-RUN-OUTPUT: Hello, world!
30+
CHECK-RUN-OUTPUT-NEXT: Hello from WASILibc!
31+
```
32+
33+
b) Embedded Swift SDK
34+
35+
```
36+
RUN: %{swift-sdk} list | grep embedded | xargs %{swift-run} --package-path %t.dir/Hello --swift-sdk | %{FileCheck} --check-prefix CHECK-EMBEDDED-RUN-OUTPUT %s
37+
CHECK-EMBEDDED-RUN-OUTPUT: Hello, world!
38+
CHECK-EMBEDDED-RUN-OUTPUT-NEXT: Hello from WASILibc!
39+
```
40+
41+
4. Running tests from the newly created package:
42+
43+
a) Non-embedded Swift SDK
44+
45+
```
46+
RUN: %{swift-sdk} list | grep -v embedded | xargs %{swift-test} --package-path %t.dir/Hello --swift-sdk | %{FileCheck} --check-prefix CHECK-RUN-OUTPUT %s
47+
```
48+
49+
50+
5. Clean up installed Swift SDK:
51+
52+
```
53+
RUN: find %{swiftpm_homedir}/ -d 1 | xargs rm -rf
54+
RUN: %{swift-sdk} list | %{FileCheck} --check-prefix CHECK-SDK-LIST-FINAL %s
55+
CHECK-SDK-LIST-FINAL: No Swift SDKs are currently installed.
56+
```

0 commit comments

Comments
 (0)