On web we can use any language as long as it is JavaScript.
An extraordinarily optimizable, low-level subset of JavaScript
is a new portable, size- and load-time-efficient format suitable for compilation to the web.
;; simple.wasm
(module
(func $i (import "imports" "i") (param i32))
(func (export "e")
i32.const 42
call $i))
Emscripten is an Open Source LLVM to JavaScript compiler.
With Emscripten you can compile code that can be translated into LLVM bitcode into JavaScript WASM
#include <stdio.h>
int main() {
printf("hello, world!\n");
return 0;
}
./emcc tests/hello_world.c
node a.out.js
$ rustup target add wasm32-unknown-emscripten
$ echo 'fn main() { println!("Hello, Emscripten!"); }' > hello.rs
$ rustc --target=wasm32-unknown-emscripten hello.rs
$ node hello.js
fetch('simple.wasm')
.then(response => response.arrayBuffer())
.then(bytes => instantiate(bytes, importObject))
.then(instance => instance.exports.e());
"We’re not killing JavaScript. I don’t think it’s even possible to kill JavaScript."Brendan Eich
Thank You