Setup

Before we can start writing Rust code, we need to install a few tools.

Godot Engine

While you can write Rust code without the Godot engine, we highly recommend to install Godot for quick feedback loops. For the rest of the tutorial, we assume that you have Godot 4 installed and available either:

  • in your PATH as godot4,
  • or an environment variable called GODOT4_BIN, containing the path to the Godot executable.

Godot from pre-built binaries

Binaries of Godot 4 can be downloaded from the official website.
For beta and older versions, you can also check the download archive.

Installing Godot via command-line

# --- Linux ---
# For Ubuntu or Debian-based distros
apt install godot

# For Fedora/RHEL
dnf install godot

# Distro-independent through Flatpak
flatpak install flathub org.godotengine.Godot


# --- Windows ---
# Windows installations can be made through WinGet
winget install --id=GodotEngine.GodotEngine -e


# --- macOS ---
brew install godot

Other Godot versions

If you plan to target Godot versions different from the latest stable release, please read Selecting a Godot version.

Rust

rustup is the preferred way to install the Rust toolchain. It includes the compiler, standard library, Cargo (the package manager) as well as tools like rustfmt or clippy. Visit the website to download binaries or installers for your platform. Alternatively, you can install it via command-line.

Installing rustup via command-line

# Linux (distro-independent)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Windows
winget install --id=Rustlang.Rustup -e

# macOS
brew install rustup

After installation of rustup and the stable toolchain, you can verify that they are working:

$ rustc --version
rustc 1.74.1 (a28077b28 2023-12-04)

LLVM

Tip

In general, you do NOT need to install LLVM.

This was necessary in the past due to bindgen, which depends on LLVM. However, we now provide pre-built artifacts, so that most users can simply add the Cargo dependency and start immediately. This also significantly reduces initial compile times, as bindgen was quite heavyweight with its many transitive dependencies.

You will still need LLVM if you plan to use the api-custom feature, for example if you have a forked version of Godot or custom modules. To just use a different API version of Godot, you do not need LLVM though; see Selecting a Godot version.

LLVM binaries can be downloaded from llvm.org. Once installed, you can check whether LLVM's clang compiler is available:

clang -v