From blazing-fast web apps to Python data science in the browser, these programming language and compiler projects offer different twists on the promise of WebAssembly.
When a Blazor WebAssembly app is run in the browser, C# code files and Razor files are compiled into .NET assemblies, which are downloaded to the browser along with the .NET runtime. The apps can be deployed standalone or with server-side support.
The internal IR (intermediate representation) of Binaryen uses compact data structures and draws on all CPU cores for parallel collagen and optimization. The IR also compiles down to WebAssembly easily because it is essentially a subset of WebAssembly. WebAssembly-specific optimizations improve both code size and speed, making Binaryen useful as a compiler back end by itself.
This open-source compiler toolchain compiles C and C++, or any other language using LLVM compiler technology, into WebAssembly for deployment on the web, Node.js, or a Wasm runtime such as Wasmer. Emscripten has been used to convert a list of real-world codebases into WebAssembly, including commercial codebases such as the Unreal Engine 4 game engine and Unity 3D platform. Emscripten supports the C and C++ standard libraries, C++ exceptions, and OpenGL/WebGL graphics commands. The Emscripten SDK used to install the Emscripten toolchain can be used on Linux, macOS, and Windows.
Forest is a functional programming language that compiles to WebAssembly. The goal behind Forest is to provide a language that makes it easier to create web apps that are complex, interactive, and functional, but without the traditional overhead of that approach, developer Nick Johnstone said.
Currently described as “pre-alpha, experimental, conceptual research software,” Forest features static typing, pattern matching, immutable data structures, multiple syntaxes, and automatic code formatting. The first syntax in development is inspired by Elm and Haskell.
Design principles of the Forest language include ease of collaboration, painless-as-possible testing, and agreement on structure and semantics while agreeing to disagree on syntax. Johnstone strives to make Forest fast enough for building complex games so that normal web apps will be “blazing fast.”
JWebAssembly, from I-Net Software, is a Java bytecode to WebAssembly compiler that takes Java class files as input and generates WebAssembly binary format (.wasm file) or text format (.wat file) as output. The target is to run natively in the browser with WebAssembly. In theory, JWebAssembly can compile any language that compiles to Java bytecode such as Clojure, Groovy, JRuby, Kotlin, and Scala, pending testing.
JWebAssembly is not yet production-ready. Although everything necessary for the JWebAssembly 1.0 release has been implemented, testing still remains to be done. The version 1.0 roadmap calls for capabilities such as a Java bytecode parser, a test framework, and a Gradle plug-in. I-Net Software expects to ship JWebAssembly 1.0 this year.
An alternative to the Xamarin mobile app platform, Uno Platform is a UI platform for .NET teams to build single-codebase applications for WebAssembly, the web, Windows, macOS, Linux, iOS, and Android, using C# and XAML. Uno leverages the Mono-WASM runtime in .NET 5 to run C# code in all of the major web browsers and serves as a bridge for WinUI and UWP (Universal Windows Platform) apps to run natively on WebAssembly. For building web apps with Uno, developers can use Visual Studio or Visual Studio Code.
The Grain language brings features from academic and functional languages to the 21st century, the project website states. Compiling to WebAssembly via the Binaryen toolchain and compiler infrastructure, Grain can run in the browser, on the server, and potentially anywhere. There are no runtime type errors and no need for type annotations. The Grain toolchain features a CLI, compiler, runtime, and standard library, shipping as a single binary. Developers will need Node.js and Yarn to build Grain from source, and binaries are available for Linux, macOS, and Windows.