Swift meets WebAssembly in SwiftWasm project

Posted on 16-05-2019 , by: admin , in , 0 Comments

A new open source project called SwiftWasm aims to integrate a WebAssembly back-end into the official Swift compiler. The project, still in the earliest stages, would allow developers to use the Swift programming language to build applications that run in web browsers.

SwiftWasm compiles Swift code to WebAssembly, which provides a target binary format that allows languages besides JavaScript to be compiled to run in a browser. Developers can try Swift on WebAssembly now using SwiftWasm’s cloud-hosted toolchain, and run the resulting WebAssembly executables in both browsers and stand-alone WebAssembly runtimes. 

The SwiftWasm website includes a working demo, but notes that many features in Swift don’t work on WebAssembly yet. WebAssembly has attributes that present obstacles to Swift, the SwiftWasm developers noted, such as having strict function signature checking.

The creators of SwiftWasm hope to make Swift the “best language for cross-platform development.” Current work would become part of the Swift compiler and available to every Swift user out-of-the-box. Future plans include supporting developer tools to enable Swift developers targeting WebAssembly to be more productive.

Running Swift in the browser has been a goal as far back as 2014, when Apple first announced the language, Max Desiatov, a maintainer of SwiftWasm and software consultant, said. First there was a push to integrate Emscripten compiler infrastructure with Swift. When WebAssembly became available in major browsers, the focus shifted to LLVM compiler technology without Emscripten, Desiatov said.

Desiatov maintains a cross-platform UI framework for Swift called Tomakak.