Skip to content

swiftwasm-pad is a online playground to help developers learn about Swift on Web.

License

Notifications You must be signed in to change notification settings

swiftwasm/swiftwasm-pad

Repository files navigation

swiftwasm-pad

Build and deploy

swiftwasm-pad is a online playground to help developers learn about Swift on Web.

https://swiftwasm-pad.netlify.app

Run

Using docker-compose

$ docker-compose up

Manual start up

# Build PreviewSystem
$ ./PreviewSystem/build-script.sh

# Start frontend
$ cd Frontend
$ npm install
$ npm run start

# Start backend
$ cd CompileAPI
$ export LOCAL_LAMBDA_SERVER_ENABLED=true
$ export LAMBDA_PREVIEW_STUB_PACKAGE=$(pwd)/../PreviewSystem/distribution/PreviewStub
$ export LAMBDA_SWIFTC=$(dirname $(pwd))/.toolchain/darwin/$(cat ../.swift-version)/usr/bin/swiftc
$ swift run CompileSwiftWasm

CompileAPI

CompileAPI is deployed with SwiftWasm toolchain built on Amazon Linux 2 and PreviewSystem. .swiftmodule files in PreviewSystem are used to compile user input code that can use Tokamak or JavaScriptKit. This API returns not an executable wasm binary but an object file. The object file will be linked with prebuilt library on browser.

Frontend

Frontend web application sends requests to CompilerAPI, link compiled object files and shared library and run linked executable wasm. library.so.wasm is the shared library combined with Swift Standard Library, Tokamak and JavaScriptKit. The library is built by ./PreviewSystem/build-script.sh This frontend application uses WebAssembly linker implemented by Swift named chibi-link to reduce CompileAPI's load and also reduce transfer data size. The linker is executed in Web Worker to avoid blocking UI.

Related Projects