139

What languages can be compiled to WebAssembly (Wasm)?

I believe right now C, C++, and Rust (experimental) can be compiled to WebAssembly, with the llvm compiler backend, with languages like Java, Swift, and C# not currently being supported, but being possible candidates for future development.

I don't believe JavaScript can be compiled to Wasm. https://github.com/WebAssembly/design/issues/219

1
  • 1
    Just as a note to anyone reading this, I've recently used C and C++ to WASM via emscripten and it works very nicely. Mar 18, 2019 at 16:55

4 Answers 4

161

WebAssembly support is ever evolving. Right now it is supported by the following languages:

There are commercial solutions also:

Regarding JavaScript, it is unlikely to gain support as WebAssembly is a statically typed assembly language.

There are also various more obscure / hobbyist languages that support WebAssembly. Further details can be found on the more exhaustive Awesome WebAssembly Languages list.

5
19

See https://github.com/mbasso/awesome-wasm#compilers -- for now it's only C/C++, others are experimental, but amount of the "experimental" part grows.

Currently WebAssembly supports just flat linear memory. That's suitable for C/C++/Rust and a lot of other languages, but most popular modern languages need garbage collector to run. That's "post-MVP feature" of WebAssembly (see https://github.com/WebAssembly/design/issues/1079). For now the only option is to implement garbage collector inside the wasm with some custom code.

1
  • 2
    It is worth adding that asm.js can be easily compiled to wasm and asm.js is javascript. That said, compiling javascript is/would be much more difficult because it generally lacks as much immediately available contextual information.
    – Culex
    Jul 21, 2017 at 15:02
16

This repo

Contains a list of languages that currently compile to or have their VMs in WebAssembly(wasm)

Features:

  • Uses emojis to show how mature each language is currently
  • Provides links to each languages project names and options
3
  • 4
    "Uses emojis to show how mature each language is currently" read that one to yourself a couple of times ...it's a pretty deep statement.
    – ipatch
    Jun 8, 2019 at 21:35
  • Yup, simple intuitive explanations coupled with silly expressions. Jun 9, 2019 at 17:59
  • 🥚 - Work in progress. 🐣 - Unstable but usable. 🐥 - Stable for production usage. Mar 15, 2021 at 1:05
11

TeaVM can be used to transpile JVM bytecode to WebAssembly. You can checkout the project homepage at https://github.com/konsoletyper/teavm.

TeaVM at its core can transpile JVM bytecode to JS and WebAssembly. WebAssembly support is in an early stage, but there are demos available to compare performance of a simple JBox2D simulation with GWT, TeaVM(JS output) and TeaVM(WASM output), which are quite impressive.

Please note that WebAssembly currently has no direct access to the DOM or other JavaScript APIs. Also in the current MVP there is no support for opaque datatypes or even the GC. However, it is possible to do up/downcalls from JS to WASM and back again using some JS trickery, as seen in the mentioned demos.

Not the answer you're looking for? Browse other questions tagged or ask your own question.