Skip to content

Commit f5638d8

Browse files
committed
Compute Swift version and tags in wasm-getting-started.md
1 parent f225592 commit f5638d8

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

documentation/articles/wasm-getting-started.md

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,27 @@ WebAssembly support in Swift started out as a community project. Any instruction
1313
standardized ABI and system interfaces, and from its inception Wasm support in Swift targeted [WebAssembly System
1414
Interface](https://wasi.dev/), which made porting Swift core libraries to this platform much easier.
1515

16-
With Swift 6.2 and development snapshots you can easily cross-compile and run Wasm modules with Swift SDKs for Wasm distributed on [swift.org](https://swift.org/download).
16+
Starting with Swift 6.2 and development snapshots you can easily cross-compile and run Wasm modules with Swift SDKs for Wasm distributed on [swift.org](https://swift.org/download).
1717
The distributed artifact bundles also include support for the experimental Embedded Swift mode.
1818

1919
## Installation
2020

21-
1. [Install `swiftly` per the instructions](https://www.swift.org/install/) for the platform that you're bulding on.
22-
23-
2. Install Swift 6.2 with `swiftly install 6.2`, note the exact snapshot date component in the output of this command.
21+
{% assign last_release = site.data.builds.swift_releases.last %}
22+
{% assign platform = last_release.platforms | where: 'name', 'Wasm'| first %}
23+
{% assign release_name = last_release.name %}
24+
{% assign tag = last_release.tag %}
25+
{% assign tag_downcase = last_release.tag | downcase %}
2426

25-
3. Select the installed toolchain with `swiftly use 6.2`.
27+
{% assign base_url = "https://download.swift.org/" | append: tag_downcase | append: "/wasm/" | append: tag | append: "/" | append: tag %}
28+
{% assign command = "swift sdk install " | append: base_url | append: "_wasm.artifactbundle.tar.gz --checksum " | append: platform.checksum %}
2629

27-
4. Run a command in your terminal application to install Swift SDKs for Wasm.
30+
1. [Install `swiftly` per the instructions](https://www.swift.org/install/) for the platform that you're bulding on.
2831

29-
{% assign platform = site.data.builds.swift_releases.last.platforms | where: 'name', 'Wasm'| first %}
30-
{% assign tag = site.data.builds.swift_releases.last.tag %}
31-
{% assign tag_downcase = site.data.builds.swift_releases.last.tag | downcase %}
32+
2. Install Swift {{ release_name }} with `swiftly install {{ release_name }}`, note the exact snapshot date component in the output of this command.
3233

33-
{% assign base_url = "https://download.swift.org/" | append: tag_downcase | append: "/wasm/" | append: tag | append: "/" | append: tag %}
34-
{% assign command = "swift sdk install " | append: base_url | append: "_wasm.artifactbundle.tar.gz --checksum " | append: platform.checksum %}
34+
3. Select the installed toolchain with `swiftly use {{ release_name }}`.
3535

36+
4. Run a command in your terminal application to install Swift SDKs for Wasm.
3637
```
3738
{{ command }}
3839
```
@@ -76,15 +77,15 @@ struct wasi_test {
7677
Build your package with the following command, substituting the ID from step 5 of [the "Installation" section](#installation) above.
7778

7879
```
79-
swift build --swift-sdk swift-6.2-RELEASE_wasm
80+
swift build --swift-sdk {{ tag }}_wasm
8081
```
8182

8283
Recent toolchain snapshots that are compatible with Swift SDKs for Wasm also include
8384
[WasmKit](https://github.com/swiftwasm/wasmkit/), which is a Wasm runtime that `swift run` can delegate to for
8485
execution. To run the freshly built module, use `swift run` with the same `--swift-sdk` option:
8586

8687
```
87-
swift run --swift-sdk swift-6.2-RELEASE_wasm
88+
swift run --swift-sdk {{ tag }}_wasm
8889
```
8990

9091
You should see the following output:
@@ -103,5 +104,14 @@ Hello from WASI!
103104
allowing the toolchain to produce Wasm binaries that are multiple orders of magnitude smaller. One of the Swift SDKs in the artifact bundle you've installed
104105
with the `swift sdk install` command is tailored specifically for Embedded Swift.
105106

106-
To build with Embedded Swift SDK, pass its ID as noted in `swift sdk list` output (which has an `-embedded` suffix) in the `--swift-sdk` option.
107+
To build with Embedded Swift SDK, pass its ID as noted in `swift sdk list` output (which has an `-embedded` suffix) in the `--swift-sdk` option. For example:
108+
109+
```
110+
swift build --swift-sdk {{ tag }}_wasm-embedded
111+
```
107112

113+
or
114+
115+
```
116+
swift run --swift-sdk {{ tag }}_wasm-embedded
117+
```

0 commit comments

Comments
 (0)