-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1407 from fermyon/docs/wasm-lang-swift-updates
docs(wasm-languages): swift updates
- Loading branch information
Showing
1 changed file
with
19 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,10 @@ But it is no longer just for iOS apps. | |
Thanks to a recent community-led project, it is possible to [compile Swift into WebAssembly](https://swiftwasm.org/) | ||
destined either for the browser or for a WASI environment. | ||
|
||
## Compatibility | ||
|
||
The latest [5.10 version of the SwiftWasm tools](https://book.swiftwasm.org/getting-started/setup.html#installation---latest-release-swiftwasm-510) uses an older version of wasi-libc that is not supported by Spin 3+. Therefore, Spin 2.x is necessary for running example Swift apps at this time. Assuming Swift 6.0 ships with an updated wasi-libc version, compatibility with Spin 3+ should then be possible. | ||
|
||
## Available Implementations | ||
|
||
The [SwiftWasm](https://swiftwasm.org/) project compiles Swift to WebAssembly. While this is a community-led project, the [stated goal](https://book.swiftwasm.org/index.html) of the project is: | ||
|
@@ -32,8 +36,8 @@ Once that is done, the `swift` tool should report SwiftWasm support: | |
|
||
``` | ||
$ swift --version | ||
SwiftWasm Swift version 5.5 (swiftlang-5.5.0) | ||
Target: arm64-apple-darwin21.1.0 | ||
SwiftWasm Swift version 5.10-dev (LLVM e98989b1092ff3a, Swift 23e8e340a7a32a7) | ||
Target: arm64-apple-darwin24.0.0 | ||
``` | ||
|
||
From there, the `swift` tool works as usual. | ||
|
@@ -69,8 +73,8 @@ Once you have installed SwiftWasm, it is easy to build applications for the Ferm | |
The simplest Swift program for Spin (or Wagi) looks like this: | ||
|
||
```swift | ||
print("content-type: text/plain\n\n") | ||
print("Hello, World!\n") | ||
print("content-type: text/plain\n") | ||
print("Hello, World!") | ||
``` | ||
|
||
To compile, set the target to `wasm32-unknown-wasi` (which ensures that WASI support is enabled): | ||
|
@@ -91,19 +95,22 @@ Hello, World! | |
To run it as a Spin web application, we can add a `spin.toml` that looks like this: | ||
|
||
```toml | ||
spin_version = "1" | ||
authors = ["Fermyon Engineering <[email protected]>"] | ||
description = "Hello world app." | ||
spin_manifest_version = 2 | ||
|
||
[application] | ||
name = "spin-hello" | ||
trigger = { type = "http", base = "/" } | ||
version = "1.0.0" | ||
description = "Hello world app." | ||
authors = ["Fermyon Engineering <[email protected]>"] | ||
|
||
[[component]] | ||
id = "hello" | ||
source = "hello.wasm" | ||
[component.trigger] | ||
[[trigger.http]] | ||
id = "trigger-hello" | ||
component = "hello" | ||
route = "/" | ||
executor = { type = "wagi" } | ||
|
||
[component.hello] | ||
source = "hello.wasm" | ||
``` | ||
|
||
Note that we use the `wagi` executor. | ||
|