graalvm 2025-04-25

Here's example project with Clojure running in WASM with graal 25 native-image's wasm backend https://github.com/roman01la/graal-clojure-wasm

3
πŸŽ‰ 9

To ask a naive question: Why not over the GraalJS implementation?

@shalokshalom this is doable for a while without many extra steps Roman was exploring/experimenting the new graalvm features of jar2wasn

5MB output is quite big but who cares πŸ˜„

it's possible to shave off like 400KB with wasm-opt https://github.com/WebAssembly/binaryen?tab=readme-ov-file#wasm-opt but that required enabling some wasm runtime flags

is this 5MB for hello world?

can it do eval? ;)

😁 1

lemme run a web server... πŸ˜„

clojure -A:native-image should be -M:native-image

Error: 'wasm-as' not found on the system path. Please extend the PATH environment variable so that it provides a Wasm assembler executable called 'wasm-as'.
I guess this needs to be documented

no idea what's that

probably you already had it installed

maybe you need to create a new terminal session after installing stuff

installing what stuff?

everything mentioned in the readme

I installed sdk and I'm using the graalvm eap

nothing else is mentioned?

ah ok I thought the other thing was optional but it's not, ok, you also need brew install binaryen

πŸ‘ 1

well eval doesn't work

I suspected it. But SCI will maybe work (like in native-image). I'll give it a shot. What benefits does running Clojure code in WASM have, interop with other JavaScript stuff?

and what are the limitations, can you use the entire Java stdlib?

don't know, it's just fun to see it's possible

πŸ‘ 1

alright, it's compiling!

$ time node core.js
Hello, World!
node core.js   0,16s  user 0,03s system 109% cpu 0,169 total

3

now let's try to add some evaluation 😁

now if SCI works you can embed it into a web page as a demo

oh that would be exciting

Try JVM Clojure in the browser via SCI... hm

error:

Fatal error: jdk.graal.compiler.debug.GraalError: com.oracle.svm.core.util.VMError$HostedError: The following method is reachable during compilation, but was not seen during Bytecode parsing: sun.nio.fs.BsdFileSystem.directCopy0(int, int, long)
	at method: int sun.nio.fs.BsdFileSystem.directCopy0(int, int, long)  [Direct call from void UnixFileSystem.copyFile(UnixPath, UnixFileAttributes, UnixPath, UnixFileSystem$Flags, long)]

Caused by: com.oracle.svm.core.util.VMError$HostedError: The following method is reachable during compilation, but was not seen during Bytecode parsing: sun.nio.fs.BsdFileSystem.directCopy0(int, int, long)
	at org.graalvm.nativeimage.builder/com.oracle.svm.core.util.VMError.shouldNotReachHere(VMError.java:78)
	at org.graalvm.nativeimage.builder/com.oracle.svm.core.util.VMError.shouldNotReachHere(VMError.java:137)
	at org.graalvm.nativeimage.builder/com.oracle.svm.core.util.VMError.guarantee(VMError.java:146)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.code.CompileQueue.defaultCompileFunction(CompileQueue.java:1256)
	... 12 more

I guess this is where the experiment ends for now ;)

looks like threading model is not supported either, well it's a good start at least

if you discuss these problems in the GraalvM Slack community you usually get good replies.

πŸ‘€ 1

What are implications of this? which types of application could benefit from this?

running spring boot apps in a browser

so kinda solves distribution problem, maybe

πŸ‘ 1

I don't know why it's complaining about some file system thing in SCI. AFAIK SCI doesn't use any file system stuff

mind sharing the output?

wait, it could be the result of --initialize-at-build-time - you should limit this as much as possible. this is why we made: https://github.com/clj-easy/graal-build-time

πŸ‘€ 1

I'll try with that

I think at this point it's better to talk to a person who really know stuff than randomly trying shit :)

BUT AREN'T YOU ARE AN EXPLORER????

πŸ˜„

I actually know the stuff that chatgpt suggested, but some of these flags are already the default

πŸ‘ 1

but yeah, vibe coding right? ;)

that is the way, looking forward to make a fortune by fixing llm generated code

I misread fortune as torture ;)

πŸ˜‚ 3

Ah, ok. And between Espresso, GraalJS and WASM, what is the most supported at the current time? Particularly in consideration towards interacting with other Truffle languages.

Probably the GraalVM Slack community is the best place to ask since the Graal teams hangs out over there

> I misread fortune as torture πŸ˜‰ ΒΏPorque no los dos? laughcry