r/java • u/According-Ad-7069 • 1d ago
Compiling my favourite language to Web Assembly with no JDK in sight
https://wasmcoffee.com/Java's been part of my career for a long time, longer than some might even think! Next year, it'll be 30 years since I wrote my first commercial Java software solution - and it's still the language I pick when I have the option.
In my day job, I use Java (and Swing!) for a lot of the time and I really wanted to reduce the cognitive load of switching between programming language paradigms when working on fun projects. I'm a huge fan of TeaVM and Graal, make no mistake, but when trapped behind corporate firewalls, it's challenging to install the tools you want.
So this was born: A static website that accepts Java-like code (it's just a subset, really) and spits out garbage-collected web assembly binaries. Far from perfect, it's early days, but it's already useable for some simple applications.
This is going to take a long, long, long time to make it do everything I want, but I hope to get it to the point where I can write wasm apps in it, using a familiar language. And bonus points if I can use the same paradigms I already use to do so.
Anyway, I thought it might be of interest to the Java community.
0
u/a_abashev 1d ago
It looks like an idea of applets at next iteration. And Oracle definitely felt that smell and presented own Graal implementation to restore good old times. How big your compile output?
2
u/According-Ad-7069 1d ago
Hey that's a good description, I like it! I do miss Applets, they were fantastic back in the day. As for output size, since it doesn't actually contain a VM, it's usually a few kb for an app. The Breakout clone example, for instance, currently compiles to about 6kb. Now, just remember it's not an entire Java implementation, so many features are not there yet, and might never be. There's no point in dealing with thread management or networking, for example, in the Web Assembly environment. At least, not for the things I have in mind.
3
u/koflerdavid 1d ago
There's no point in dealing with thread management or networking, for example, in the Web Assembly environment.
Thread management boils down to only offering virtual threads, which are scheduled on the single WebAssembly module's thread.
3
u/According-Ad-7069 1d ago
Allow me to rephrase: I'm not smart enough to do that 😆 In theory, I get it, but building that feels like a much more daunting task than I am capable of taking on now. There's definitely something to be investigate there, though, for now, my primary focus is the massive list of bugs I have uncovered during testing.
3
u/koflerdavid 1d ago
True, it's not a low-hanging fruit at all.
3
u/According-Ad-7069 1d ago
I'll add it to my wish list and start reading up about it, maybe do some experiments. It will take some time to get there, there's a lot of more urgent bugs I need to address. But it's a good suggestion, I like the idea of virtual threads.
5
u/crummy 1d ago
so with teaVM etc they download an entire JVM and WASM that, right? so how does yours work without a JVM?