WebAssembly Rust


According to this it helps the user to set up in WebAssembly Rust. Is there a way to code purly in Rust without recompiling the game engine or anything like that? Does WebAssembly slow down Rust’s speed?

No, you don’t have to recompile the engine, it say you have to compile your rust script in wasm and then use that format wasm code in armory and yes, you can code purely in rust.

WebAssembly ( Wasm ) is a binary instruction format for a stack-based virtual machine, designed as a portable target for compilation of languages like C / C++ / Rust .

This is according to some the website.

So does WebAssembly slow down my code by any chance? Since it uses virtual machine? Isn’t it possible to use something else that does not use virtual machine?

In short, probably not, but it may not be out of the question.

The two primary runtimes for Armory are HL/C, a virtual machine for Haxe that compiles to C and allows it to communicate with native C/C++ libraries such as Bullet physics, and Krom, which is a JavaScript runtime for Armory that allows you run you game quickly without having to wait for C code to compile. Krom is what supports executing WASM, which, by definition runs in the Javascript VM.

I don’t know how Rust can bind to C/C++ libraries, but it might be possible to write Rust code and compile it to WASM for Krom during development, letting you get fast build times, and compiling it to native code that binds to the C/C++ generated by HL/C for production builds. That would all depend on the ability to bind Rust to the entire Armory API; I don’t know how that works, but it might be possible in the future.

Either way Krom is actually very fast, and I think that WASM might be even faster than the rest of Armory that is compiled to plain JavaScript ( not really sure ), so it shouldn’t be a problem even if you had to use the VM, as long as you don’t have to deploy to consoles or iOS where Krom doesn’t work.

Lets just say if I fully published my game, would the official game run with JavaScript VM and all that other stuff?

When I officially build my game for actual comercial use, then would I use Krom? (sorry I don’t understand much about this)?

Krom is used at least for development because of fast build times, but it should be fine for production deployment as well, as long as you don’t need to publish to consoles or to iOS.

You might get some more efficiency out of the C build of the game, but there was a time where Krom actually ran faster than the C++ build ( that was before we switched to compiling to C I think ) so that could depend on the game.

Also be aware that WASM doesn’t yet have full access to the Armory API. It is actually pretty limited in what it can access at the moment. See this post.

If you wanted to write a library in Rust and interact with it in Haxe, that might be easier to get working, but either way, using Rust in Armory hasn’t really been put into practice yet as far as I’m aware, so it might require some more work to get going.

1 Like

I see.

Is it possible to use Rust without having to use WASM and without having to do anything complicated?

Not that I know of unfortunately. :disappointed:

Maybe in the future, but not immediately.

1 Like

What about native C++ (without WASM or any other stuff)? Is that supported now?

You mean being able to write C++ for Armory? It is possible to write libraries in C++ and include them into Armory. That is how Armory gets its bullet physics integration. I’m working on something right now that will automate binding C++ libraries for use in Armory.

I’m not sure about writing C++ as the primary language for Armory, though because I don’t know about a way to call the Armory API from C++. I just know how to call C++ from Haxe.

1 Like

Before using rust please read my answer in How to set up WASM Rust and then DON’T :smiley:

1 Like