A Rust library for launching Godot from a Cargo run script, specifically designed for GDExtension development.
cargo-godot-lib provides similar functionality to the cargo-godot executable but as a library. This allows you to include it as a dependency in your project, ensuring all developers have access to the same runner without requiring a separate global installation via cargo install.
.gdextensionGeneration: Supports customized Cargo target directory (e.g.target-dir = ".cache/cargo/target").- Godot Project Import: Automatically runs
godot --import --headlessif the.godotfolder is missing, eliminating the need to manually open the editor on a fresh clone. - Godot Binary Discovery: Intelligently locates the Godot binary via environment variables (
godotorGODOT), the systemPATH, or common installation paths. - Developer Friendly: Launches Godot with the
--debugflag by default for better output in your terminal. - Configurable: Convenient builder pattern allows customization of run parameters (See
GodotRunnerfor details).
Example project structure:
project/
├── Cargo.toml (workspace)
├── godot/
│ └── project.godot
└── rust/
├── Cargo.toml (package: example)
├── run_godot.rs
└── src/
└── main.rs
The main interface of cargo-godot-lib is the GodotRunner struct.
This struct follows a builder pattern and can be configured to suit your needs.
See the following project/rust/run_godot.rs example:
fn main() {
let runner = cargo_godot_lib::GodotRunner::create(
env!("CARGO_PKG_NAME"),
&std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../godot"),
);
if let Err(e) = runner.execute() {
eprintln!("{e:?}");
std::process::exit(1);
}
}Add cargo-godot-lib to your dependencies and define the binary in project/rust/Cargo.toml:
[package]
name = "example"
version = "0.1.0"
edition = "2024"
[[bin]]
name = "run-godot"
path = "run_godot.rs"
[dependencies]
# ... your other dependencies (e.g. godot-rust)
cargo-godot-lib = "<latest_version_goes_here>"Now any developer can launch the Godot project and build the extension in one command:
cargo run --package exampleThis project is licensed under the MIT License.