Just to set your expectations first:
- Only bundling for Windows and Linux is currently supported
- You must host your own build server
- The build server provides no sandboxing or security against malicious extensions
Hey all! I’ve been working on a way to make use of Rust in native extensions for a while and it’s now in a state that I consider to be ready for release! This project is split up into a few different parts:
- defold-rs - Rust bindings to dmSDK and test project for new bindings
- defold-rs-extender - Custom build server
- defold-rs-template - Rust port of the native extension template
It works the same way as regular C/C++ extensions: everything is done on the build server and you only need the standard Defold editor to build games. For writing Rust code, you’ll want to use VSCode (or your favorite LSP-compatible IDE) with rust-analyzer
installed.
These extensions are full Cargo projects. The main benefit being that you can use any of the Rust libraries on crates.io in your Defold game just by listing them in your Cargo.toml
. Theoretically, you could even write a game with the Bevy game engine and embed it into a Defold project!
Getting started
- Download and run the build server
- The process is (mostly) the same as normal
- Make a copy of the template project
- In the editor, set
File > Preferences > Extensions > Build Server
to the URL of the build server- This should be
http://localhost:9000
if you’re running the server on your computer
- This should be
- Open up
/myextension/src
(the folder containingCargo.toml
) in your IDE of choice - Once you’re done writing your extension, just press build in Defold as always
- Rust extensions will take much longer to build at first than C++, since it needs to compile several dependencies for the bindings
Project Status
Supported Platforms
- Windows
- Linux
- macOS
- HTML5
- iOS
- Android
- PS4/PS5
-
Nintendo Switch
- Rust actually supports compiling for Switch, but it doesn’t include the standard library
Features
- Template project
-
dmSDK bindings
- Extension and Lua module registering
- Crate documentation
- Complete API coverage
- Handle multiple versions of Defold
-
Build server
- Compile and link Cargo projects
- Cache artifacts between builds
-
Sandbox build-time code
-
cargo-rubber
andsccache
are good examples
-
-
Public instance
- Not likely to happen, at least not one hosted by me