Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What languages can be compiled to WebAssembly (Wasm)? [closed]

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

like image 421
Jordan Stewart Avatar asked Oct 10 '22 15:10

Jordan Stewart


People also ask

Which languages can compile to Wasm?

We are often asked which languages are best supported for production-grade WebAssembly. We suggest C/C++, Rust, and AssemblyScript.

Can Python compile to Wasm?

Python is the second most popular programming language. Thanks to a few different efforts, it is now possible to compile the Python interpreter to WebAssembly.

What language is Wasm?

Awesome WebAssembly Languages. WebAssembly, or wasm for short, is a low-level bytecode format that runs in the browser just like JavaScript. It is designed to be faster to parse than JavaScript, as well as faster to execute which makes it a suitable compilation target for new and existing languages.

Can Java compile to WebAssembly?

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.


1 Answers

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

  • C / C++ - has very good (production ready) support via EmScripten, or other minimal LLVM-based toolchains

  • Rust - WebAssembly is an officially supported target, with a highly active community around it.

  • Go - has now supports WebAssembly as an official, yet experimental, target

  • C# - has experimental support via Blazor, however this currently requires embedding a .NET runtime into Wasm. Blazor was officially adopted by Microsoft as an experimental technology, with a recent preview release.

  • D - the "betterC" subset of D can be compiled to WebAssembly through LDC (LLVM compiler).

  • TypeScript - via AssemblyScript, highly experimental, but gaining momentum.

  • Java - via TeaVM or Bytecoder

  • Haxe - just announced support

  • Kotlin - Kotlin/Native 0.4 gained experimental support of WebAssembly and via TeaVM

  • Python - Pyodide is a port of Python to WebAssembly that includes the core packages of the scientific Python stack (Numpy, Pandas, matplotlib).

  • PHP - Experimental, but with a working prototype

  • Perl - WebPerl is a port of the Perl binary to WebAssembly, allowing you to run Perl scripts on the web.

  • Scala - using the Emscripten compiler, and TeaVM

  • Ruby - via the run.rb project

  • Swift - using SwiftWasm

There are commercial solutions also:

  • RemObjects - Which has announced support for C#, Java, Swift and Oxygene

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.

like image 159
ColinE Avatar answered Oct 20 '22 00:10

ColinE