What programming language for WebAssembly

?

WebAssembly solves many interoperability issues between devices, it's like a more generic Java. In addition, the more difficult task is to ensure security. One wasm code generation language may work better than another depending on the intended type of application: local everything in wasm, local with Node.js or on the Web.

Le bout du tunnel avec WebAssembly
End of Tunnel with WebAssembly

Language C

C programs compiled in wasm can be used as executable or as function libraries for JavaScript. In the second case, if you use runtime C, such as the <stdio.h> functions, the command to create instances in the JavaScript script needs an ImportObject parameter indicating all "imported" functions such as printf, putchar, etc.
File system access functions should still include WASI dedicated to WebAssembly and replace libc.
The library compilation command has the following shape:

emcc hello.c -Oz -s WASM=1 -s SIDE_MODULE=1 -o hello.wasm 

The C and C++ languages are not the ones best suited for use with node.js.

C++

The C++ program is ideally converted to Wasm for execution using wasmer or wasmtime. But when you want to create a library usable by JavaScript, it's harder. An Em++ based on CLang changes the name of the function. For example, add () becomes _Z3addii (). This is called "mangling." You will need to modify the declaration of C++ functions so that they can be considered as C functions.

Rust

This is the new language of Mozilla, one of the main players in the development of WebAssembly, so it compiles well in wasm, but obviously does not allow reuse of old programs.

Julia

Like Rust, Julia uses the LLVM platform to create executable code, and therefore generates LLVM bitcode, which is easily converted to wasm.
See the Julia-Wasm website for usage instructions.

AssemblyScript

This is a solution for using wasm in a browser. AssemblyScript is a version of TypeScript created to generate wasm code, not JavaScript. It is constantly evolving, but today has disadvantages and only supports part of the TypeScript language.
However, his running time includes memory management and a collection garage. The language supports String type and dynamic tables.
The wasm file is created with a simple command:

asc hello.ts 

C # (с Blazor

)

The Microsoft Web Application Framework, which uses the C # language, can also generate WebAssemby code. Its main goal is to replace JavaScript with C # - partially - which can run in the browser after being converted to wasm. It is an alternative to Angular (uses TypeScript) and React (uses JavaScript).

Swift (Linux/MacOS)

Another LLVM platform language. The SwiftWasm website tells you how to create a wasm program with one instruction:

swiftc -target wasm32-unknown-wasi hello.swift -o hello.wasm

WASI runtime must be enabled. SwiftWasm does not work on Windows, but you can create wasm programs under Linux and use them in a browser on all systems.

Scriptol (C++)

A way to generate wasm over C++ without programming in C++. The Script language has a clear simple syntax, compiled in C++, which is then compiled into wasm and can also be executed directly by wasmer.

solc hello