Graalvm to run wasm from spring boot
Graalvm is AOT compilation advanced JDK, I am following the project since 2019, Project’s first target was AOT now lately I start seeing more about multi language support. It supports Python, JS, Ruby, Wasm more details here
And WASM is getting popular day by day, WASM is a new binary file for web. There are many cool examples of WASM
I was wondering how to run WASM code in simple spring boot application,
@GetMapping("/addTwo")
public String addTwo() {
try (Context context = Context.create()) {
URL wasmFile = WasmdemoApplication.class.getResource("/test.wasm");
String moduleName = "main";
context.eval(Source.newBuilder("wasm", wasmFile).name(moduleName).build());
Value addTwo = context.getBindings("wasm").getMember(moduleName).getMember("addTwo");
return "addTwo(40, 2) = " + addTwo.execute(40, 2);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
It is not much but very good starting point how to run WASM from java with #GraalVM. Find full running code here
How looks in the browser
If we check how wasm file described in bash
References: