Which programming language for WebAssembly?

WebAssembly solves a lot of cross-device compatibility issues, it's like a more universal Java. But also more complex to implement because of the security measures that have been integrated into it. A language for generating wasm code may be more suitable than another depending on the type of application considered: local full wasm, local with Node.js, or on the Web.

The end of the tunnel with WebAssembly
The end of the tunnel with WebAssembly

C language

C programs compiled in wasm can be used as executables, or as libraries for JavaScript. In the second case, if we use the C runtime, like for example the functions of <stdio.h> the instantiation command in the JavaScript script needs the ImportObject parameter which specifies all the "imported" functions like printf, putchar, etc ...
For the functions which must access the filesystem, we must also include WASI, a runtime dedicated to WebAssembly and which replaces libc.
The command to compile a library looks like this:

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

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

C++

A C++ program converts perfectly to Wasm to be executed with wasmer or wasmtime. But when you want to create a library that can be used by a JavaScript script, it's more complicated. Em++ which is based on CLang modifies the name of the functions. For example add() becomes _Z3addii(). This is called "mangling". You will need to modify the declarations of your C++ functions so that they are treated as C functions.

Rust

It is a new language from 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

Just like Rust, Julia uses the LLVM platform to create executable code, and therefore generates LLVM bitcode which easily converts to wasm.
See at the Julia-Wasm for instructions of use.

AssemblyScript

This is one best solutions for using wasm in the browser. AssemblyScript is a version of TypeScript created to generate wasm code rather than JavaScript. It is still evolving, but currently has shortcomings and only supports part of the TypeScript language.
However, its runtime integrates memory management and a garbage collector. The language supports the String type and dynamic arrays.
We generate a wasm file with a simple command:

asc hello.ts 

C# (With Blazor)

Microsoft's web application building framework, which uses the C# language, can also produce WebAssemby code. Its primary purpose is to replace JavaScript with C# - for a part - which can work in the browser once converted to wasm. It is an alternative to Angular (which uses TypeScript) and React (which uses JavaScript).

Swift (Linux/MacOS)

Another language of the LLVM platform. The SwiftWasm site explains how to create a wasm program with a single instruction:

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

You need to include the WASI runtime. SwiftWasm does not work on Windows, but you can create wasm programs on Linux and use them in the browser on all systems.

Scriptol (C++)

A way to generate wasm by C++ without programming in C++. The scriptol language with its clear and simple syntax compiles in C++ which is then compiled in wasm et may be run directly also with wasmer.

solc hello