### Install Rust Toolchain using rustup Source: https://godot-rust.github.io/book/intro/setup.html Commands to install rustup and the Rust toolchain on Linux, Windows, and macOS. ```bash # Linux (distro-independent) curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh # Windows winget install -e --id Rustlang.Rustup # macOS brew install rustup ``` -------------------------------- ### Verify Rust Installation Source: https://godot-rust.github.io/book/intro/setup.html Command to verify the Rust toolchain installation by checking the compiler version. ```bash $ rustc --version rustc 1.88.0 (6b00bc388 2025-06-23) ``` -------------------------------- ### Install Godot 4 Source: https://godot-rust.github.io/book/intro/setup.html Commands to install Godot 4 on various Linux distributions, Windows, and macOS. ```bash # --- Linux --- # Fedora/RHEL. dnf install godot # Arch Linux. pacman -Syu godot paru -Syu godot # Flatpak (e.g. Ubuntu, Debian, or distro-independent). flatpak install flathub org.godotengine.Godot # --- Windows --- winget install -e --id GodotEngine.GodotEngine choco install godot scoop bucket add extras && scoop install godot # --- macOS --- brew install godot ``` -------------------------------- ### Example: Adding a Rust target Source: https://godot-rust.github.io/book/toolchain/export-android.html An example of adding the 'aarch64-linux-android' target triple to rustup. ```bash rustup target add aarch64-linux-android ``` -------------------------------- ### Emscripten SDK Installation Source: https://godot-rust.github.io/book/print.html Commands to clone, install, and activate a specific version of the Emscripten SDK. ```bash git clone https://github.com/emscripten-core/emsdk.git cd emsdk ./emsdk install 3.1.74 ./emsdk activate 3.1.74 source ./emsdk_env.sh # on Linux run ./emsdk_env.bat # on Windows ``` -------------------------------- ### Windows Source: https://godot-rust.github.io/book/print.html Installation command for rustup on Windows. ```bash # Windows winget install -e --id Rustlang.Rustup ``` -------------------------------- ### Rust Toolchain and Target Installation for Web Source: https://godot-rust.github.io/book/print.html Commands to install the nightly Rust toolchain, the wasm32-unknown-emscripten target, and rust-src component. ```bash rustup toolchain install nightly rustup component add rust-src --toolchain nightly rustup target add wasm32-unknown-emscripten --toolchain nightly ``` -------------------------------- ### macOS Source: https://godot-rust.github.io/book/print.html Installation command for rustup on macOS. ```bash # macOS brew install rustup ``` -------------------------------- ### Local Server URL Example Source: https://godot-rust.github.io/book/toolchain/export-web.html An example URL for the local web server created by the Godot editor, useful for troubleshooting Firefox issues. ```text http://localhost:8060/tmp_js_export.html ``` -------------------------------- ### Example APPLE_DEV_ID Source: https://godot-rust.github.io/book/toolchain/export-mac-and-ios.html Example of setting the APPLE_DEV_ID environment variable. ```bash APPLE_DEV_ID = email@provider.com ``` -------------------------------- ### Windows Source: https://godot-rust.github.io/book/print.html Installation commands for Godot 4 on Windows. ```bash # --- Windows --- winget install -e --id GodotEngine.GodotEngine choco install godot scoop bucket add extras && scoop install godot ``` -------------------------------- ### Example APPLE_DEV_PASSWORD Source: https://godot-rust.github.io/book/toolchain/export-mac-and-ios.html Example of setting the APPLE_DEV_PASSWORD environment variable. ```bash APPLE_DEV_PASSWORD = abcd-abcd-abcd-abcd ``` -------------------------------- ### Example APPLE_DEV_TEAM_ID Source: https://godot-rust.github.io/book/toolchain/export-mac-and-ios.html Example of setting the APPLE_DEV_TEAM_ID environment variable. ```bash APPLE_DEV_TEAM_ID = 1ABCD2EFG ``` -------------------------------- ### Load a scene and instantiate it Source: https://godot-rust.github.io/book/print.html Example of loading a scene and instantiating it as a `RigidBody2D`. ```rust #![allow(unused)] fn main() { // mob_scene is declared as a field of type Gd. self.mob_scene = load("res://Mob.tscn"); // instanced is of type Gd. let mut instanced = self.mob_scene.instantiate_as::(); } ``` -------------------------------- ### Linux Source: https://godot-rust.github.io/book/print.html Installation commands for Godot 4 on Linux. ```bash # --- Linux --- # Fedora/RHEL. dnf install godot # Arch Linux. pacman -Syu godot paru -Syu godot # Flatpak (e.g. Ubuntu, Debian, or distro-independent). flatpak install flathub org.godotengine.Godot ``` -------------------------------- ### Linux (distro-independent) Source: https://godot-rust.github.io/book/print.html Installation command for rustup on Linux. ```bash # Linux (distro-independent) curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh ``` -------------------------------- ### Example APPLE_CERT_BASE64 format Source: https://godot-rust.github.io/book/toolchain/export-mac-and-ios.html An example of the format for the APPLE_CERT_BASE64 environment variable, which contains the base64 encoded certificate content. ```shell APPLE_CERT_BASE64 = ...(A long text file) ``` -------------------------------- ### macOS Source: https://godot-rust.github.io/book/print.html Installation command for Godot 4 on macOS. ```bash # --- macOS --- brew install godot ``` -------------------------------- ### Install nightly Rust and Emscripten components Source: https://godot-rust.github.io/book/toolchain/export-web.html Commands to install the nightly Rust toolchain, the rust-src component, the wasm32-unknown-emscripten target, and the Emscripten SDK. ```bash rustup toolchain install nightly rustup component add rust-src --toolchain nightly rustup target add wasm32-unknown-emscripten --toolchain nightly ``` ```bash git clone https://github.com/emscripten-core/emsdk.git cd emsdk ./emsdk install 3.1.74 ./emsdk activate 3.1.74 source ./emsdk_env.sh # on Linux run ./emsdk_env.bat # on Windows ``` -------------------------------- ### GDScript add_button examples Source: https://godot-rust.github.io/book/print.html Demonstrates calling the GDScript add_button method with different argument combinations. ```gdscript var dialog = AcceptDialog.new() var button0 = dialog.add_button("Yes") var button1 = dialog.add_button("Yes", true) var button2 = dialog.add_button("Yes", true, "confirm") ``` -------------------------------- ### Check LLVM Clang Source: https://godot-rust.github.io/book/intro/setup.html Command to check if LLVM's clang compiler is available. ```bash clang -v ``` -------------------------------- ### Example Project Directory Structure Source: https://godot-rust.github.io/book/intro/hello-world.html A common and recommended directory structure for a Godot project using a Rust GDExtension. ```tree my-cool-project ├── godot │ ├── project.godot │ └── my-extension.gdextension └── rust ├── Cargo.toml ├── src └── target └── debug └── (lib)?my_extension.(so|dll|dylib) ``` -------------------------------- ### .gdextension file configuration Source: https://godot-rust.github.io/book/intro/hello-world.html This is an example of a `.gdextension` file that tells Godot how to load a compiled Rust extension. It includes the path to the dynamic library and the entry point for initialization. ```ini [configuration] entry_symbol = "gdext_rust_init" compatibility_minimum = 4.1 reloadable = true [libraries] linux.debug.x86_64 = "res://../rust/target/debug/lib{YourCrate}.so" linux.release.x86_64 = "res://../rust/target/release/lib{YourCrate}.so" windows.debug.x86_64 = "res://../rust/target/debug/{YourCrate}.dll" windows.release.x86_64 = "res://../rust/target/release/{YourCrate}.dll" macos.debug = "res://../rust/target/debug/lib{YourCrate}.dylib" macos.release = "res://../rust/target/release/lib{YourCrate}.dylib" macos.debug.arm64 = "res://../rust/target/debug/lib{YourCrate}.dylib" macos.release.arm64 = "res://../rust/target/release/lib{YourCrate}.dylib" ``` -------------------------------- ### Build the Rust project Source: https://godot-rust.github.io/book/intro/hello-world.html Command to compile the Rust project. ```bash cargo build ``` -------------------------------- ### Registering self with a HashMap Source: https://godot-rust.github.io/book/print.html Example of how to get a Gd pointer to the current instance and use it to register or unregister the monster in a HashMap. ```Rust #![allow(unused)] fn main() { #[godot_api] impl Monster { // Function that registers each monster by name, or unregisters it if dead. fn update_registry(&self, registry: &mut HashMap>) { if self.is_alive() { let self_as_gd: Gd = self.to_gd(); registry.insert(self.name.clone(), self_as_gd); } else { registry.remove(&self.name); } } } } ``` -------------------------------- ### Create a new Rust crate Source: https://godot-rust.github.io/book/intro/hello-world.html Command to create a new Rust library crate. ```bash cargo new "{YourCrate}" --lib ``` -------------------------------- ### Link to GitHub repo Source: https://godot-rust.github.io/book/intro/hello-world.html Alternative way to add godot-rust dependency by linking directly to the GitHub repository for bleeding-edge development. ```toml godot = { git = "https://github.com/godot-rust/gdext", branch = "master" } ``` -------------------------------- ### Basic GDExtension Entry Point Source: https://godot-rust.github.io/book/intro/hello-world.html This Rust code defines the minimal structure required for a GDExtension library, including the entry point and the `ExtensionLibrary` trait implementation. ```rust #![allow(unused)] fn main() { use godot::prelude::*; struct MyExtension; #[gdextension] unsafe impl ExtensionLibrary for MyExtension {} } ``` -------------------------------- ### Example of raw pointers in virtual methods Source: https://godot-rust.github.io/book/print.html Some virtual methods declare raw pointers in their parameters or return types, for example: ```rust #![allow(unused)] fn main() { trait IAudioStreamPlayback { unsafe fn mix(&mut self, buffer: *mut AudioFrame, rate_scale: f32, frames: i32) -> i32; } } ``` -------------------------------- ### File structure Source: https://godot-rust.github.io/book/intro/hello-world.html The assumed file structure for the Godot and Rust parts of the project. ```text 📂 project_dir │ ├── 📂 .git │ ├── 📂 godot │ ├── 📂 .godot │ ├── 📄 HelloWorld.gdextension │ └── 📄 project.godot │ └── 📂 rust ├── 📄 Cargo.toml ├── 📂 src │ └── 📄 lib.rs └── 📂 target └── 📂 debug ``` -------------------------------- ### Cargo.toml configuration Source: https://godot-rust.github.io/book/intro/hello-world.html Modifying the Cargo.toml file to configure the crate as a dynamic C library. ```toml [package] name = "rust_project" # Part of dynamic library name; we use {YourCrate} placeholder. version = "0.1.0" # You can leave version and edition as-is for now. edition = "2021" [lib] crate-type = ["cdylib"] # Compile this crate to a dynamic C library. ``` -------------------------------- ### Example APPLE_CERT_PASSWORD Source: https://godot-rust.github.io/book/toolchain/export-mac-and-ios.html An example indicating that APPLE_CERT_PASSWORD is the password set during the p12 certificate export. ```shell APPLE_CERT_PASSWORD = ``` -------------------------------- ### Example error message Source: https://godot-rust.github.io/book/recipes/editor-plugin/inspector-plugins.html An example of an error that might occur if the editor plugin is not properly loaded or recognized. ```text Initialize godot-rust (API v4.2.stable.official, runtime v4.2.2.stable.official) ERROR: Cannot get class 'RandomInspectorPlugin'. at: (core/object/class_db.cpp:392) ERROR: Cannot get class 'RandomInspectorPlugin'. at: (core/object/class_db.cpp:392) ``` -------------------------------- ### Add godot-rust dependency Source: https://godot-rust.github.io/book/intro/hello-world.html Command to add the godot-rust dependency to the project. ```bash cargo add godot ``` -------------------------------- ### Example APPLE_DEV_APP_ID format Source: https://godot-rust.github.io/book/toolchain/export-mac-and-ios.html An example of the format for the APPLE_DEV_APP_ID environment variable, which is derived from the Common Name of the certificate. ```shell APPLE_DEV_APP_ID = Developer ID Application: Common Name (1ABCD23EFG) ``` -------------------------------- ### Create iOS framework bundle Source: https://godot-rust.github.io/book/toolchain/export-mac-and-ios.html Creates a .framework directory and copies the compiled dylib into it. ```bash mkdir target/release/lib{YourCrate}.ios.framework cp target/release/lib{YourCrate}.ios.dylib \ target/release/lib{YourCrate}.ios.framework/lib{YourCrate}.ios.dylib ``` -------------------------------- ### extension_list.cfg file content Source: https://godot-rust.github.io/book/intro/hello-world.html This is the content for the `extension_list.cfg` file, which lists all extensions registered within your Godot project. It should contain the Godot path to your `.gdextension` file. ```plaintext res://HelloWorld.gdextension ``` -------------------------------- ### GDScript enum declaration Source: https://godot-rust.github.io/book/register/properties.html Example of how an enum is declared in GDScript. ```gdscript enum Planet { EARTH, VENUS, MARS, } @export var favorite_planet: Planet ``` -------------------------------- ### Player struct and init method Source: https://godot-rust.github.io/book/intro/hello-world.html This code defines the Player struct and overrides the init method to initialize fields and print a message to the console. ```Rust #![allow(unused)] fn main() { use godot::classes::ISprite2D; #[godot_api] impl ISprite2D for Player { fn init(base: Base) -> Self { godot_print!("Hello, world!"); // Prints to the Godot console Self { speed: 400.0, angular_speed: std::f64::consts::PI, base, } } } } ``` -------------------------------- ### Visual Studio Code launch.json configuration Source: https://godot-rust.github.io/book/toolchain/debugging.html Example launch configuration for debugging a Godot project with LLDB in VS Code. ```json { "configurations": [ { "name": "Debug Project (Godot 4)", "type": "lldb", // type provided by CodeLLDB extension "request": "launch", "cwd": "${workspaceFolder}/godot", "preLaunchTask": "build-rust", "args": [ "-w" // windowed mode // "-e": editor does not keep breakpoints; thus not listed here. ], "program": "PATH/TO/GODOT" } ] } ``` -------------------------------- ### ResourceLoader Implementation Source: https://godot-rust.github.io/book/print.html Example implementation of a custom ResourceLoader in Rust for Godot. ```rust // All file extensions you want to be redirected to your loader // should be added here. fn get_recognized_extensions(&self) -> PackedStringArray { let mut arr = PackedStringArray::new(); arr.push("myextension"); arr } // All resource types that this loader handles. fn handles_type(&self, ty: StringName) -> bool { ty == "MyResourceType".into() } // The stringified name of your resource should be returned. fn get_resource_type(&self, path: GString) -> GString { // The extension arg always comes with a `.` in Godot, so don't forget it ;) if path.get_extension().to_lower() == ".myextension".into() { "MyResourceType".into() } else { // In case of not handling the given resource, this function must // return an empty string. GString::new() } } // The actual loading and parsing of your data. fn load( &self, // The path that should be openend to load the resource. path: GString, // If the resource was part of a import step you can access the original file // with this. Otherwise this path is equal to the normal path. original_path: GString, // This parameter is true when the resource is loaded with // load_threaded_request(). // Internal implementations in Godot also ignore this parameter. _use_sub_threads: bool, // If you want to provide custom caching this parameter is the CacheMode enum. // You can look into the ResourceLoader docs to learn about the values. // When calling the default load() method, cache_mode is CacheMode::REUSE. cache_mode: i32, ) -> Variant { // TODO: Put your saving logic in here, with the `GFile` API (see link below). // If your loading operation failed and you want to handle errors, // you can return a godot::global::Error and cast it to a Variant. } } ``` ``` -------------------------------- ### Info.plist for iOS framework Source: https://godot-rust.github.io/book/toolchain/export-mac-and-ios.html Example Info.plist file content for an iOS framework. ```xml CFBundleInfoDictionaryVersion 6.0 CFBundleDevelopmentRegion en CFBundleExecutable lib{YourCrate}.ios.dylib CFBundleName My App Name CFBundleDisplayName My App Name CFBundleIdentifier org.my-website.my-app NSHumanReadableCopyright Copyright (c) ... CFBundleVersion 0.12.0 CFBundleShortVersionString 0.12.0 CFBundlePackageType FMWK CSResourcesFileMapped DTPlatformName iphoneos MinimumOSVersion 12.0 ``` -------------------------------- ### Accessing signals Source: https://godot-rust.github.io/book/print.html Example of accessing the `damage_taken` signal and its generated type. ```Rust #![allow(unused)] fn main() { // Generated code ($ are placeholders, actual names up to implementation): impl $SignalCollection { fn damage_taken(&mut self) -> $Signal {...} } #[godot_api] impl INode3D for Monster { fn ready(&mut self) { let sig = self.signals().damage_taken(); } } } ``` -------------------------------- ### Project Structure Example Source: https://godot-rust.github.io/book/register/virtual-functions.html Illustrates a typical project directory layout for a Godot-Rust project using virtual functions. ```text project_dir/ │ ├── godot/ │ ├── .godot/ │ ├── project.godot │ ├── MonsterGame.gdextension │ └── Scenes │ ├── Monster.tscn │ ├── Orc.gd │ └── Goblin.gd │ └── rust/ ├── Cargo.toml └── src/ ├── lib.rs └── monster.rs ``` -------------------------------- ### Emitting a Signal Source: https://godot-rust.github.io/book/register/signals.html Example of emitting a signal, specifically `world_loaded`, through `Gd::signals()`. ```rust fn load_map() { // All the loading. ... // Notify player that the world around is now loaded. let player: Gd = ...; player.signals().world_loaded().emit(); } ``` -------------------------------- ### Storing and disconnecting signals Source: https://godot-rust.github.io/book/register/signals.html Example of storing a `ConnectHandle` to disconnect a signal later. ```rust #![allow(unused)] fn main() { #[derive(GodotClass)] #[class(init, base=Node3D)] struct Monster { handle: Option, base: Base, } #[godot_api] impl INode3D for Monster { fn ready(&mut self) { self.handle = Some(self.signals() .damage_taken() .connect(Self::on_damage_taken)); } } impl Monster { fn make_invulnerable(&mut self) { if let Some(connection) = self.handle.take() { connection.disconnect(); } } } } ``` -------------------------------- ### GDScript Signal Declarations Source: https://godot-rust.github.io/book/register/signals.html Examples of declaring signals in GDScript with and without parameters. ```gdscript signal damage_taken signal damage_taken(amount) signal damage_taken(amount: int) ``` -------------------------------- ### Running a Local Web Server with CORS and Multi-threading Support Source: https://godot-rust.github.io/book/toolchain/export-web.html Example command using npm and npx to host a web game locally with Cross-Origin Isolation support, enabling multi-threading. ```bash npx serve --cors ``` -------------------------------- ### Load a scene and instantiate it Source: https://godot-rust.github.io/book/godot-api/objects.html Example of loading a scene and instantiating it as a RigidBody2D. ```rust #![allow(unused)] fn main() { // mob_scene is declared as a field of type Gd. self.mob_scene = load("res://Mob.tscn"); // instanced is of type Gd. let mut instanced = self.mob_scene.instantiate_as::(); } ``` -------------------------------- ### Create Info.plist directory Source: https://godot-rust.github.io/book/toolchain/export-mac-and-ios.html Creates the Resources subdirectory within the framework for the Info.plist file. ```bash mkdir target/release/lib{YourCrate}.macos.framework/Resources ``` -------------------------------- ### Connecting a GDScript signal Source: https://godot-rust.github.io/book/print.html Example of connecting a signal to a handler function in GDScript. ```gdscript signal damage_taken(amount: int) func log_damage(): print("damaged!") func _ready(): damage_taken.connect(log_damage) ``` -------------------------------- ### GDScript enum type unsafety Source: https://godot-rust.github.io/book/print.html This example illustrates that GDScript enums are not type-safe. ```GDScript var p: Planet = 5 ``` -------------------------------- ### Registering a custom singleton Source: https://godot-rust.github.io/book/print.html This code demonstrates how to register a custom singleton `MySingleton` using `godot::classes::Engine` and implement `UserSingleton` for easy access. It also shows the necessary `gdextension` setup for initialization and deinitialization. ```rust #[derive(GodotClass)] #[class(init, base = Object)] struct MySingleton {} // Provides blanket implementation allowing to use MySingleton::singleton(). // Ensures that `MySingleton` is a valid singleton // (i.e., a non-refcounted GodotClass). impl UserSingleton for MySingleton {} struct MyExtension; #[gdextension] unsafe impl ExtensionLibrary for MyExtension { fn on_stage_init(stage: InitStage) { // Singleton should be registered before the MainLoop startup; // otherwise it won't be recognized by the GDScriptParser. if stage == InitStage::Scene { let obj = MySingleton::new_alloc(); Engine::singleton() .register_singleton( &MySingleton::class_id().to_string_name(), &obj ); } } fn on_stage_deinit(stage: InitStage) { if stage == InitStage::Scene { let obj = MySingleton::singleton(); Engine::singleton() .unregister_singleton( &MySingleton::class_id().to_string_name() ); obj.free(); } } } ```