Skip to content

Commit 2d6a174

Browse files
Remove toolchain-style installation instructions (#28)
1 parent e8cc6dd commit 2d6a174

File tree

5 files changed

+55
-203
lines changed

5 files changed

+55
-203
lines changed

src/SUMMARY.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
- [Introduction](README.md)
44
- [Getting Started](getting-started/index.md)
55
- [Installation](getting-started/setup.md)
6-
- [Development Snapshot](getting-started/setup-snapshot.md)
7-
- [Hello, World](getting-started/hello-world.md)
8-
- [Using Swift Package Manager](getting-started/swift-package.md)
96
- [Porting code from other platforms](getting-started/porting.md)
107
- [Creating a browser app](getting-started/browser-app.md)
118
- [JavaScript interoperation](getting-started/javascript-interop.md)

src/getting-started/hello-world.md

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,3 @@
11
# Hello, World!
22

3-
This section will show you how to compile a simple Swift code into WebAssembly and run the produced binary on WASI supported WebAssembly runtime.
4-
5-
## 1. Create a Swift file
6-
7-
```sh
8-
$ echo 'print("Hello, world!")' > hello.swift
9-
```
10-
11-
12-
## 2. Compile Swift code into WebAssembly with WASI
13-
14-
```
15-
$ swiftc -target wasm32-unknown-wasi hello.swift -o hello.wasm
16-
```
17-
18-
19-
## 3. Run the produced binary on WebAssembly runtime
20-
21-
You can the run the produced binary with [wasmtime](https://wasmtime.dev/) (or other WebAssembly runtime):
22-
23-
```sh
24-
$ wasmtime hello.wasm
25-
```
26-
27-
The produced binary depends on WASI which is an interface of system call for WebAssembly.
28-
So you need to use WASI supported runtime and when you run the binary on browser, you need WASI polyfill library like [@bjorn3/browser_wasi_shim](https://github.com/bjorn3/browser_wasi_shim).
3+
> This page has been merged into the [Installation](./setup.md) page.

src/getting-started/setup-snapshot.md

Lines changed: 1 addition & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,3 @@
11
# Installation - Development Snapshot
22

3-
## Swift SDK for WebAssembly - Cross compile to WebAssembly
4-
5-
The upstream Open Source Swift toolchain does support WebAssembly as a target platform since **Swift 6.0**.
6-
For those versions, you just need to install [Swift SDK for cross-compilation](https://github.com/apple/swift-evolution/blob/main/proposals/0387-cross-compilation-destinations.md).
7-
8-
9-
## Instructions
10-
11-
1. **Find a Development Snapshot**
12-
13-
Visit the [SwiftWasm GitHub Releases page](https://github.com/swiftwasm/swift/releases).
14-
15-
2. **Match the Swift Toolchain Version**
16-
17-
Refer to the release note's table to find the corresponding upstream Swift toolchain version.
18-
> For example, [`swift-wasm-DEVELOPMENT-SNAPSHOT-2024-06-12-a`](https://github.com/swiftwasm/swift/releases/tag/swift-wasm-DEVELOPMENT-SNAPSHOT-2024-06-12-a) corresponds to `swift-DEVELOPMENT-SNAPSHOT-2024-06-11-a`
19-
20-
3. **Download the Swift Toolchain**
21-
22-
Download the appropriate Swift toolchain version from [swift.org/install](https://www.swift.org/install).
23-
24-
4. **Get the Swift SDK artifactbundle URL**
25-
26-
Find the URL ending with `.artifactbundle.zip` from the release page you found in step 1.
27-
Currently we provide Swift SDKs for the following WebAssembly targets:
28-
- `wasm32-unknown-wasi` (Recommended): for [WASI Preview 1](https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md)
29-
- `wasm32-unknown-wasip1-threads`: for WASI Preview 1 with [wasi-threads](https://github.com/WebAssembly/wasi-threads) extension
30-
> Choose `wasm32-unknown-wasi` if you are not sure which target to use.
31-
32-
5. **Install the Swift SDK for WebAssembly**
33-
34-
Use the following command to install the Swift SDK:
35-
```console
36-
$ swift sdk install <URL-or-filename-of-swift-sdk-artifactbundle>
37-
```
38-
> For example, if you selected `swift-wasm-DEVELOPMENT-SNAPSHOT-2024-06-12-a`, you need to run the following command:
39-
> ```console
40-
> $ swift sdk install https://github.com/swiftwasm/swift/releases/download/swift-wasm-DEVELOPMENT-SNAPSHOT-2024-06-12-a/swift-wasm-DEVELOPMENT-SNAPSHOT-2024-06-12-a-wasm32-unknown-wasi.artifactbundle.zip
41-
> ```
42-
6. You can see the installed SDKs using the following command:
43-
```console
44-
$ swift sdk list
45-
<Swift SDK id>
46-
...
47-
```
48-
> Once you don't need the SDK, you can remove it using the following command:
49-
> ```console
50-
> $ swift sdk remove <Swift SDK id>
51-
> ```
52-
53-
## How to use the Swift SDK
54-
55-
First, create a new Swift package using the following command:
56-
57-
```console
58-
$ mkdir Example
59-
$ cd Example
60-
$ swift package init --type executable
61-
```
62-
63-
Then, you can build the package using the Swift SDK:
64-
65-
```console
66-
$ swift build --swift-sdk wasm32-unknown-wasi
67-
# or
68-
$ swift build --swift-sdk <Swift SDK id>
69-
```
70-
71-
## FAQ
72-
73-
### What is the difference between the Swift Toolchain and the Swift SDK?
74-
75-
The Swift toolchain is a complete package that includes the Swift compiler, standard library, and other tools.
76-
77-
The Swift SDK includes a subset of the Swift toolchain that includes only the necessary components for cross-compilation and some supplementary resources.
78-
79-
### What is included in the Swift SDK for WebAssembly?
80-
81-
The Swift SDK for WebAssembly includes only the pre-built Swift standard libraries for WebAssembly. It does not include the Swift compiler or other tools that are part of the Swift toolchain.
3+
> This page has been merged into the [Installation](./setup.md) page.

src/getting-started/setup.md

Lines changed: 52 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,90 @@
1-
# Installation - Latest Release (SwiftWasm 5.10)
1+
# Installation - Latest Release (Swift 6.0.3)
22

3-
To install Swift for WebAssembly toolchain, download one of the packages below and follow the instructions for your operating system.
3+
SwiftWasm provides [Swift SDK](https://github.com/apple/swift-evolution/blob/main/proposals/0387-cross-compilation-destinations.md)s for WebAssembly.
44

5-
Tag: [swift-wasm-5.10.0-RELEASE](https://github.com/swiftwasm/swift/releases/tag/swift-wasm-5.10.0-RELEASE)
5+
Before installing the Swift SDK, you need to ensure the following:
66

7-
| Download | Docker Tag |
8-
|:------------------:|:----------:|
9-
| [macOS arm64](https://github.com/swiftwasm/swift/releases/download/swift-wasm-5.10.0-RELEASE/swift-wasm-5.10.0-RELEASE-macos_arm64.pkg) | Unavailable |
10-
| [macOS x86](https://github.com/swiftwasm/swift/releases/download/swift-wasm-5.10.0-RELEASE/swift-wasm-5.10.0-RELEASE-macos_x86_64.pkg) | Unavailable |
11-
| [Ubuntu 18.04 x86_64](https://github.com/swiftwasm/swift/releases/download/swift-wasm-5.10.0-RELEASE/swift-wasm-5.10.0-RELEASE-ubuntu18.04_x86_64.tar.gz) | [5.10-bionic, bionic](https://github.com/orgs/swiftwasm/packages/container/package/swift) |
12-
| [Ubuntu 20.04 x86_64](https://github.com/swiftwasm/swift/releases/download/swift-wasm-5.10.0-RELEASE/swift-wasm-5.10.0-RELEASE-ubuntu20.04_x86_64.tar.gz) | [5.10-focal, focal](https://github.com/orgs/swiftwasm/packages/container/package/swift) |
13-
| [Ubuntu 20.04 aarch64](https://github.com/swiftwasm/swift/releases/download/swift-wasm-5.10.0-RELEASE/swift-wasm-5.10.0-RELEASE-ubuntu20.04_aarch64.tar.gz) | [5.10-focal, focal](https://github.com/orgs/swiftwasm/packages/container/package/swift) |
14-
| [Ubuntu 22.04 x86_64](https://github.com/swiftwasm/swift/releases/download/swift-wasm-5.10.0-RELEASE/swift-wasm-5.10.0-RELEASE-ubuntu22.04_x86_64.tar.gz) | [5.10, 5.10-jammy, jammy, latest](https://github.com/orgs/swiftwasm/packages/container/package/swift) |
7+
- You need to [install an Open Source toolchain from swift.org](https://www.swift.org/install/). (Not the Xcode toolchain)
8+
- You cannot use toolchains bundled with Xcode to use the Swift SDK.
9+
- If you are using macOS, please follow the [official guide](https://www.swift.org/install/macos/package_installer/) to install the toolchain.
1510

16-
17-
You can find older releases from the [GitHub Releases page](https://github.com/swiftwasm/swift/releases?q=prerelease%3Afalse)
18-
19-
## Toolchain Installation
20-
21-
### macOS
22-
23-
1. [Download the latest package release](#latest-release) according to your CPU architecture (arm64 for [Apple Silicon Macs](https://support.apple.com/en-us/HT211814), x86 for Intel Macs).
24-
2. Run the package installer, which will install an Xcode toolchain into `/Library/Developer/Toolchains/`.
25-
3. To use the Swift toolchain with command-line tools, use `env TOOLCHAINS=swiftwasm swift` or add the Swift toolchain to your path as follows:
11+
Once you have installed the Open Source toolchain, you can install the Swift SDK for WebAssembly:
2612

2713
```bash
28-
export PATH=/Library/Developer/Toolchains/<toolchain name>.xctoolchain/usr/bin:"${PATH}"
14+
$ swift sdk install "https://github.com/swiftwasm/swift/releases/download/swift-wasm-6.0.3-RELEASE/swift-wasm-6.0.3-RELEASE-wasm32-unknown-wasi.artifactbundle.zip" --checksum "31d3585b06dd92de390bacc18527801480163188cd7473f492956b5e213a8618"
2915
```
3016

31-
4. Run `swift --version`. If you installed the toolchain successfully, you can get the following message.
17+
After installing the Swift SDK, you can see the installed SDKs:
3218

3319
```bash
34-
$ swift --version
35-
# Or TOOLCHAINS=swiftwasm swift --version
36-
SwiftWasm Swift version 5.10-dev
37-
Target: x86_64-apple-darwin21.6.0
20+
$ swift sdk list
21+
<SDK name>
22+
...
3823
```
3924

40-
If you want to uninstall the toolchain, you can remove the toolchain directory from `/Library/Developer/Toolchains/` and make sure to remove the toolchain from your `PATH`.
41-
42-
## Linux
25+
You can also find other SDKs from [the GitHub Releases page](https://github.com/swiftwasm/swift/releases).
4326

44-
1. [Download the latest package release](#latest-release) according to your Ubuntu version and CPU architecture.
45-
2. Follow the official Swift installation guide for Linux from [swift.org](https://www.swift.org/install/linux/#installation-via-tarball) while skipping GPG key verification, which is not provided for SwiftWasm releases.
27+
Use the following shell snippet to query compatible Swift SDK for your current toolchain version:
4628

47-
## Experimental: Swift SDK
29+
```console
30+
(
31+
V="$(swiftc --version | head -n1)"; \
32+
TAG="$(curl -sL "https://raw.githubusercontent.com/swiftwasm/swift-sdk-index/refs/heads/main/v1/tag-by-version.json" | jq -r --arg v "$V" '.[$v] | .[-1]')"; \
33+
curl -sL "https://raw.githubusercontent.com/swiftwasm/swift-sdk-index/refs/heads/main/v1/builds/$TAG.json" | \
34+
jq -r '.["swift-sdks"]["wasm32-unknown-wasi"] | "swift sdk install \"\(.url)\" --checksum \"\(.checksum)\""'
35+
)
36+
```
4837

49-
SwiftWasm provides [Swift SDK](https://github.com/apple/swift-evolution/blob/main/proposals/0387-cross-compilation-destinations.md)s for WebAssembly. You can use the Swift SDK to cross-compile Swift packages for WebAssembly without installing the whole toolchain.
38+
## Hello, World
5039

51-
To use the Swift SDK, you need to install the official Swift toolchain 5.10 or later. Then, you can install the Swift SDK using the following command while replacing `<your platform>`:
40+
First, create a new directory for your project and navigate into it:
5241

5342
```bash
54-
$ swift experimental-sdk install https://github.com/swiftwasm/swift/releases/download/swift-wasm-5.10.0-RELEASE/swift-wasm-5.10.0-RELEASE-<your platform>.artifactbundle.zip
43+
$ mkdir hello && cd hello
5544
```
5645

57-
You can find the latest Swift SDK release from [the GitHub Releases page](https://github.com/swiftwasm/swift/releases/tag/swift-wasm-5.10.0-RELEASE).
46+
Create a new Swift package:
5847

59-
After installing the Swift SDK, you can see the installed SDKs using the following command:
48+
```bash
49+
$ swift package init --type executable
50+
```
51+
52+
You can use the installed SDKs to cross-compile Swift packages for WebAssembly:
6053

6154
```bash
62-
$ swift experimental-sdk list
63-
<SDK name>
55+
$ swift build --swift-sdk wasm32-unknown-wasi
6456
...
57+
$ file .build/wasm32-unknown-wasi/debug/hello.wasm
58+
.build/wasm32-unknown-wasi/debug/hello.wasm: WebAssembly (wasm) binary module version 0x1 (MVP)
6559
```
6660

67-
You can use the installed SDKs to cross-compile Swift packages for WebAssembly using the following command:
61+
You can run the built WebAssembly module using [`wasmtime`](https://wasmtime.dev/):
6862

6963
```bash
70-
$ swift build --experimental-swift-sdk <SDK name>
64+
$ wasmtime .build/wasm32-unknown-wasi/debug/hello.wasm
65+
Hello, world!
7166
```
7267

73-
## Docker
68+
## FAQ
7469

75-
SwiftWasm offical Docker images are hosted on [GitHub Container Registry](https://github.com/orgs/swiftwasm/packages/container/package/swift).
70+
### How to check if I am using Open Source toolchain or Xcode toolchain?
7671

77-
SwiftWasm Dockerfiles are located on [swiftwasm-docker](https://github.com/swiftwasm/swiftwasm-docker) repository.
72+
```bash
73+
$ swift --version | head -n1
74+
```
7875

79-
### Supported Platforms
76+
| Toolchain | Output |
77+
|-----------|--------|
78+
| Xcode | `Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)` |
79+
| Open Source (macOS) | `Apple Swift version 6.0.3 (swift-6.0.3-RELEASE)` |
80+
| Open Source (Others) | `Swift version 6.0.3 (swift-6.0.3-RELEASE)` |
8081

81-
- Ubuntu 18.04 (x86_64)
82-
- Ubuntu 20.04 (x86_64, aarch64)
83-
- Ubuntu 22.04 (x86_64)
82+
### What is the difference between the Swift Toolchain and the Swift SDK?
8483

85-
### Using Docker Images
84+
The Swift toolchain is a complete package that includes the Swift compiler, standard library, and other tools.
8685

87-
1. Pull the Docker image from [GitHub Container Registry](https://github.com/orgs/swiftwasm/packages/container/package/swift):
86+
The Swift SDK includes a subset of the Swift toolchain that includes only the necessary components for cross-compilation and some supplementary resources.
8887

89-
```bash
90-
docker pull ghcr.io/swiftwasm/swift:latest
91-
```
92-
93-
2. Create a container using tag `latest` and attach it to the container:
88+
### What is included in the Swift SDK for WebAssembly?
9489

95-
```bash
96-
docker run --rm -it ghcr.io/swiftwasm/swift:latest /bin/bash
97-
```
90+
The Swift SDK for WebAssembly includes only the pre-built Swift standard libraries for WebAssembly. It does not include the Swift compiler or other tools that are part of the Swift toolchain.

src/getting-started/swift-package.md

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,3 @@
11
# Compile a SwiftPM package to WebAssembly
22

3-
You can also use SwiftPM for managing packages in the same way as other platforms.
4-
5-
6-
## 1. Create a package from template
7-
8-
```sh
9-
$ swift package init --type executable --name Example
10-
Creating executable package: Example
11-
Creating Package.swift
12-
Creating .gitignore
13-
Creating Sources/
14-
Creating Sources/main.swift
15-
```
16-
17-
## 2. Build the Project into a WebAssembly binary
18-
19-
You need to pass `--triple` option, which indicates that you are building for the target.
20-
21-
```sh
22-
$ swift build --triple wasm32-unknown-wasi
23-
```
24-
25-
If [you installed Swift SDK instead of the whole toolchain](./setup.md#experimental-swift-sdk), you need to use the following command:
26-
27-
```sh
28-
$ swift build --swift-sdk <SDK name>
29-
```
30-
31-
## 3. Run the produced binary
32-
33-
Just as in the [previous section](./hello-world.md), you can run the produced binary with WebAssembly runtimes like `wasmtime`.
34-
35-
```sh
36-
$ wasmtime ./.build/wasm32-unknown-wasi/debug/Example.wasm
37-
Hello, world!
38-
```
3+
> This page has been merged into the [Installation](./setup.md) page.

0 commit comments

Comments
 (0)