godot_rust_tools icon indicating copy to clipboard operation
godot_rust_tools copied to clipboard

A Godot 4 addon to help with development of GDExtensions written in Rust

Godot Rust Tools

Godot Rust Tools icon: a hammer inside the Rust gear, with small letters "rs" written next to it

Godot Rust Tools, or "Rust Tools" for short, is a plugin for Godot 4 to help with development of extensions written in Rust.

gdext is the canonical and recommended library for using GDExtension from Rust, but this plugin does not depend on it and can work just as well with custom bindings.

Features

  • Build Rust code right from the Godot editor, and automatically reload the extension if the build succeeds. Builds are also triggered automatically when running your game.
  • Enable Rust backtraces when running your game.
  • Automatically generate Rust constants for names defined in the editor: input actions, layer names and global groups.

Requirements

The plugin requires Godot 4.5 or greater.

Platform support:

  • Linux & Windows: Supported and tested, should work right out the box.
  • Android: Should work on rooted devices, but untested.
  • MacOS: Should be supported but untested; there may be problems with sandboxing. Please report if it works or doesn't work.

Installation

Installation from the Godot Asset Libary (recommended):

  1. Head over to the AssetLib tab in the Godot editor.
  2. Search for "Rust Tools".
  3. Click the plugin's icon or name, then follow the steps to download and install it.

Manual installation:

  1. Download this plugin's project files from GitHub.
  2. Copy the addons/rust_tools folder to the addons folder in your own Godot project, creating it if necessary. Files outside addons/rust_tools are not needed to use the plugin.

Usage

After enabling the plugin, you'll see some new toolbar buttons to the left of the usual ones, marked with a little rs icon:

A screenshot of Godot's top left toolbar, with three additional buttons: one displaying a call stack, one a broom and one a hammer. All three have an overlay with the letters "rs".

From left to right:

  • Rust Backtrace: toggle RUST_BACKTRACE=1 in the environment of the running project, for more detailed panic reporting. Note that this only takes effect on newly started projects, not on currently running ones.
  • Clean: runs cargo clean.
  • Build: runs cargo build.

Build output goes to the Output pane at the bottom:

A screenshot of Godot's Output pane, showing the output of a cargo build process

cargo build is also invoked automatically when you run or export your project, so you'll never get out-of-date code. However, due to limitations in the Godot API, these invocations must run synchronously, blocking the editor UI.

Before you can run the build, you will need to tell Rust Tools about your Rust code; see the REQUIRED items under Configuration below.

Configuration

Project Settings

These can be found under Project > Project Settings… > Rust Tools.

  • Cargo Package Directories (REQUIRED)

    You need to tell Rust Tools which cargo package(s) to build, by adding their path(s) to the Cargo Package Directories setting.

    Note that this path is relative to the Godot project itself, so:

    • If the Rust code is in a subfolder of the Godot project, specify the name of that folder here.
    • If the Rust code is in a sibling folder next to the Godot project, use ".." to indicate the parent folder, for example "../rust".
  • Gdextension Files (REQUIRED)

    For autoreload to work, it needs to know which GDExtension files need to be reloaded. Specify those here.

  • Generated Constants File Paths

    If specified, Rust Tools will automatically generate constants containing Input Actions, Global Groups names and user-defined Layer Names. The file will be (re)generated upon detecing a change in project settings, and right before a build; you can trigger it manually by using the Command Palette (Ctrl+Shift+P) and choosing Rust Tools > Regenerate Constants.

Editor Settings

These settings apply to all projects using Rust Tools, and can be found under Editor > Editor Settings… > Rust Tools.

  • Cargo Executable

    If you don't have cargo in your PATH, you need to tell the editor where to find it. Set Cargo Executable to the absolute path to the cargo or cargo.exe executable.

    The default, plain cargo, is fine if its containing folder is on your PATH.

  • Enable Autoreload

    By default, Rust Tools automatically reloads extensions after a rebuild. You can turn that off here. (Normally, Godot only reloads after the editor window loses and regains focus.)

License

This plugin is under the MIT license, like Godot itself. See LICENSE.md.

The Rust logo is distributed under the terms of the Creative Commons Attribution license (CC-BY).

This project is not affiliated with, or endorsed by, the Rust Project or Rust Foundation.