This section will show you how to compile a simple Swift code into WebAssembly and run the produced binary on WASI supported WebAssembly runtime.
$ echo 'print("Hello, world!")' > hello.swift
$ swiftc -target wasm32-unknown-wasi hello.swift -o hello.wasm
You can the run the produced binary with wasmer (or other WebAssembly runtime):
$ wasmer hello.wasm
The produced binary depends on WASI which is an interface of system call for WebAssembly. So you need to use WASI supported runtime and when you run the binary on browser, you need WASI polyfill library like @wasmer/wasi.