Skip to content

Commit cb83649

Browse files
MaxDesiatovgrynspanheckj
authored
Revise WASI documentation for swift test commands (#1595)
Updated links and commands for running WebAssembly tests with `swift test`. --------- Co-authored-by: Jonathan Grynspan <jgrynspan@apple.com> Co-authored-by: Joseph Heck <j_heck@apple.com>
1 parent 40c1b67 commit cb83649

File tree

1 file changed

+37
-16
lines changed

1 file changed

+37
-16
lines changed

Documentation/WASI.md

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,52 @@ See https://swift.org/CONTRIBUTORS.txt for Swift project authors
1414
because it provides instructions the reader must follow directly. -->
1515

1616
To run tests for WebAssembly, install a Swift SDK for WebAssembly by following
17-
[these instructions](https://book.swiftwasm.org/getting-started/setup.html).
17+
[these instructions](https://www.swift.org/documentation/articles/wasm-getting-started.html).
1818

19-
Because `swift test` doesn't know what WebAssembly environment you'd like to use
20-
to run your tests, building tests and running them are two separate steps. To
21-
build tests for WebAssembly, use the following command:
19+
20+
In Swift 6.3 and later, running `swift test --swift-sdk <wasm_swift_sdk_id>`
21+
builds and runs your tests. Use `jq` to extract the Swift SDK ID automatically
22+
to build and test in a single command:
23+
24+
swift test --swift-sdk \
25+
"$(swiftc -print-target-info | jq -r '.swiftCompilerTag')_wasm"
26+
```
27+
28+
## Build and Test WebAssembly separately
29+
30+
Prior to Swift 6.3, `swift test` doesn't support `--swift-sdk` option to
31+
indicate the WebAssembly environment to use for tests. In this case, building
32+
tests and running them are two separate steps. To build tests for WebAssembly,
33+
use the following command:
2234
2335
```sh
24-
swift build --swift-sdk wasm32-unknown-wasi --build-tests
36+
swift build \
37+
--swift-sdk "$(swiftc -print-target-info | jq -r '.swiftCompilerTag')_wasm" \
38+
--build-tests
2539
```
2640

27-
After building tests, you can run them using a [WASI](https://wasi.dev/)-compliant
28-
WebAssembly runtime such as [Wasmtime](https://wasmtime.dev/) or
29-
[WasmKit](https://github.com/swiftwasm/WasmKit). For example, to run tests using
30-
Wasmtime, use the following command (replace `{YOURPACKAGE}` with your package's
31-
name):
41+
After building tests, you can run them using
42+
a [WASI](https://wasi.dev/)-compliant WebAssembly runtime such as
43+
[WasmKit](https://github.com/swiftwasm/WasmKit). WasmKit is included in
44+
the Swift toolchain for Linux and macOS for Swift 6.2 and later.
45+
[Download and install an open-source release toolchain from swift.org](https://swift.org/install)
46+
to get a toolchain that includes WasmKit.
47+
48+
To run the rests you built previously using the WasmKit runtime, use the
49+
following command, replacing `{YOURPACKAGE}` with the name of your package:
3250

3351
```sh
34-
wasmtime .build/debug/{YOURPACKAGE}PackageTests.wasm --testing-library swift-testing
52+
wasmkit run .build/debug/{YOURPACKAGE}PackageTests.wasm \
53+
--testing-library swift-testing
3554
```
3655

37-
Most WebAssembly runtimes forward trailing arguments to the WebAssembly program,
38-
so you can pass command-line options of the testing library. For example, to list
39-
all tests and filter them by name, use the following commands:
56+
Most WebAssembly runtimes forward trailing arguments to the WebAssembly
57+
program, so you can pass command-line options of the testing library. For
58+
example, to list all tests and filter them by name, use the following commands:
4059

4160
```sh
42-
wasmtime .build/debug/{YOURPACKAGE}PackageTests.wasm list --testing-library swift-testing
43-
wasmtime .build/debug/{YOURPACKAGE}PackageTests.wasm --testing-library swift-testing --filter "FoodTruckTests.foodTruckExists"
61+
wasmkit run .build/debug/{YOURPACKAGE}PackageTests.wasm list \
62+
--testing-library swift-testing
63+
wasmkit run .build/debug/{YOURPACKAGE}PackageTests.wasm \
64+
--testing-library swift-testing --filter "FoodTruckTests.foodTruckExists"
4465
```

0 commit comments

Comments
 (0)