Compile Swift to Wasm WASI

Thanks to the great work of Swift Wasmarrow-up-right we can now compile Swift to WebAssembly WASI.

Wasienv makes very easy to get started with Swift and WebAssembly.

wasienv install-swift
circle-exclamation

Once that's done, just create an example Swift file:

if CommandLine.arguments.count < 2 {
    print("Hello, WASI!");
} else {
    print("Hello, \(CommandLine.arguments[1])");
}

Now let's Compile it!

wasiswiftc example.swift -o example.wasm

Once the program finishes, you will have a new example.wasm file ready to be executed with your favorite WebAssembly runtime!

$ wasmer example.wasm
Hello, WASI!

Last updated

Was this helpful?