Skip to content
Xendergo edited this page May 16, 2021 · 4 revisions

Compiling

Minecraft wasm runtime uses wasmtime to run webassembly, so you're welcome to enable any features supported by it. You can see those here: https://webassembly.org/roadmap/

You also want to compile with WASI as the target.

To say what language you're compiling from, export an i32 called language. Then assign it to whatever the id of the language your using is. If you don't specify a language, it'll assume assemblyscript by default.

Language IDs

AssemblyScript - 0

The language doesn't actually matter as long as you don't try to import or export reference types like strings or arrays. It's only used to determine how to convert those reference types into java objects.

AssemblyScript

To compile with WASI in AssemblyScript, have import "wasi" at the top of the file. You also want to compile with exportRuntime set to true.

Example:

import "wasi"

export const language: i32 = 0;

Future languages

These are languages I hope to support in the future, I might have to take stuff off the list due to technical problems, but hopefully not

Unknown

Will error out when you try to do language specific stuff

Rust

Emscripten (c, c++)

JWebAssembly (JVM (Java, Kotlin, Scala, etc.))

.NET (C#, F#, Visual Basic)

I'm very unsure about this one, since the only resources I could find about compiling c# to wasm are about web frameworks.

Why do we need specific language support?

Webassembly currently only supports numbers and specific reference types, like references to functions. This means that different languages can do whatever they like to make strings and arrays work, which means for any of those types to cross the boundary between wasm and minecraft, we have to know the language.