poorna2152 / nballerina

WebAssembly Backend for the nBallerina compiler
https://ballerina.io/
Apache License 2.0
4 stars 0 forks source link
ballerina garbage-collection wasm webassembly

nBallerina Wasm Backend

Usage

  1. Clone the nBallerina repository.
  2. Download and install the latest Ballerina distribution (Swan Lake not 1.2.x)
  3. Download and extract Binaryen Tool.
  4. You can build the compiler by using the command bal build in the compiler directory; this will generate a file target/bin/nballerina.jar. This should work on any system that Ballerina works on.
  5. You can use java -jar nballerina.jar example.bal --backend wasm to compile a Ballerina module into an wat file example.wat (note that the backend only supports upto subset 09). Make sure you invoke the nballerina.jar file inside the cloned nBallerina directory.
  6. If you want to be able to turn the wat file into a wasm file use the wasm-opt tool in the Binaryen tool chain.
    ./wasm-opt -O3 example.wat -o example.wasm -all
  7. To run the generated wasm file. Use the main.js file inside the wrun folder. (Supports NodeJs version 17 and 16. Doesn't support NodeJs version 18)
    node --experimental-wasm-eh --experimental-wasm-gc main.js example.wasm

Testing

The compiler is tested using the test cases in the compiler/testSuite directory. The bal build command performs a first level of testing on these: it checks that the test cases that should get compile errors do, and that the test cases that should not get compile errors do not. This should work on any platform on which the Ballerina distribution works.

For those test cases that are valid Ballerina programs, the Makefile in the test directory is used to further test that the generated wasm files can be compiled and produce the expected output when executed. This Makefile has the following targets:

Status

Wasm backend supports upto subset 14. A blog post on compiler operation.