BlackBoxMC / blackboxmc

Minecraft plugin that allows you to write plugins in many other compiled languages besides Java
GNU Lesser General Public License v3.0
14 stars 1 forks source link

WebAssembly-based Plugins #7

Open Luyten-Orion opened 8 months ago

Luyten-Orion commented 8 months ago

Hey there, there's no Discord listed here so I've decided to create an issue to discuss this instead, there are 3 issues raised due to the nature of the project and the issues mentioned are distribution, JNI overhead and plugin interop, I believe WebAssembly (via something such as Asmble or Wasmtime via Panama which still has an issue with portability, a preview feature available from Java 17 onwards I believe) could solve these problems

WASM supports host function interop which would mean a wrapper around JVM classes from the host could be done, as well as implementing a JVM reflection API that can be used in WASM to call code from JVM plugins for example

I've wanted to tinker with the idea myself but haven't had the balls to wade through the shithole that is Java, personally

Note: This isn't an actual issue with the library so it can be closed

Luyten-Orion commented 8 months ago

Also I've noticed an archived repo in the organisation scraped javadocs in order to get a usable JSON format presumably for automated wrapper generation, if you're interested, I have made this for when I had a similar goal (involving GraalJS + TypeScript though) https://github.com/The-Ticking-Clockwork/JvTypeGen

IoIxD commented 8 months ago

I tried WASM and there was some reason that it would not work at all. I do not remember why.

That said, WASM plugins would still use JNI. The correct solution to the (15ns of) overhead would be Panama.

IoIxD commented 8 months ago

Also yes, I actually plan on started redoing blackbox-rs with some JSON thing I found. I found something else, thanks for this though.

Luyten-Orion commented 8 months ago

I tried WASM and there was some reason that it would not work at all. I do not remember why.

That said, WASM plugins would still use JNI. The correct solution to the (15ns of) overhead would be Panama.

Via Wasmtime they'd use JNI sure, but GraalWASM (in interpreted mode) and Asmble are pure JVM, but understandable, good luck with this project! It definitely seems interesting for sure!

IoIxD commented 8 months ago

Oh Graal.

Yeah somebody else has suggested GraalVM and it seems much better, but the problem is you need that special Java interpreter, which often is not an option. When doing projects like this, I generally prefer to target the lowest feature set that somebody would usually have access to (in this case, a Java 17 interpreter that somebody's host would provide).

And thanks! There's no Discord because for as many people as were interested, nobody other then me ever wanted to make plugins for it, so I didn't get advice for it and development kinda fell off. I'm picking it back up again though, coincidentally right as you posted this.

Luyten-Orion commented 8 months ago

GraalWASM can actually run on a stock JDK (but you need to actually extract the jar manually), but the pain point is that to expose custom host functions, you also need to use GraalJS (which also runs on a stock JDK), but yeah that's understandable

And also the lack of a discord is fair enough, personally I don't use Spigot or Fabric anymore and I'm considering learning mod making for Fabric and NeoForge, I just made this issue because I thought it may of interested you haha