- Clone the nBallerina repository.
- Download and install the latest Ballerina distribution (Swan Lake not 1.2.x)
- Download and extract Binaryen Tool.
- You can build the compiler by using the command
bal build
in thecompiler
directory; this will generate a filetarget/bin/nballerina.jar
. This should work on any system that Ballerina works on. - You can use
java -jar nballerina.jar example.bal --backend wasm
to compile a Ballerina module into anwat
fileexample.wat
(note that the backend only supports upto subset 09). Make sure you invoke thenballerina.jar
file inside the cloned nBallerina directory. - If you want to be able to turn the
wat
file into awasm
file use thewasm-opt
tool in the Binaryen tool chain.
./wasm-opt -O3 example.wat -o example.wasm -all
- To run the generated
wasm
file. Use the main.js file inside thewrun
folder. (Supports NodeJs version 17 and 16. Doesn't support NodeJs version 18)
node --experimental-wasm-eh --experimental-wasm-gc main.js example.wasm
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:
test
(the default target) forces a rebuild of all the.ll
files andwasm
files if the compiler jar has changed, and then doescompile
,testwat
andtestll
compile
builds any out of date.ll
files (but does not consider the compiler jar when determining whether a.ll
is out of date)testll
builds an executable for each test case, executes it and checks its outputtestwat
builds an executable for each test case, executes it and checks its output
Wasm backend supports upto subset 14. A blog post on compiler operation.