#binding #bindings #generator #json #file #api #engine #godot #stability

build gdnative_bindings_generator

Generates bindings for the Godot engine’s gdnative classes from a json api description file

8 releases (5 breaking)

0.9.0 Sep 20, 2020
0.9.0-preview.0 Jul 10, 2020
0.8.1 May 31, 2020
0.8.0 Mar 9, 2020
0.1.0 Sep 23, 2018

#15 in Game dev

Download history 94/week @ 2020-06-09 113/week @ 2020-06-16 72/week @ 2020-06-23 92/week @ 2020-06-30 146/week @ 2020-07-07 144/week @ 2020-07-14 122/week @ 2020-07-21 144/week @ 2020-07-28 150/week @ 2020-08-04 146/week @ 2020-08-11 155/week @ 2020-08-18 146/week @ 2020-08-25 163/week @ 2020-09-01 119/week @ 2020-09-08 139/week @ 2020-09-15 121/week @ 2020-09-22

581 downloads per month
Used in 14 crates (13 directly)

MIT license

81KB
2K SLoC

GDNative bindings for Rust

Docs Status

Rust bindings to the Godot game engine.

User Guide | API Documentation

Stability

The bindings cover most of the exposed API of Godot 3.2, and are being used on a number of projects in development, but we still expect non-trivial breaking changes in the API in the coming releases.

Engine compatibility

We are serious about engine compatibility. We are committed to keeping compatibility with the latest stable patch releases of all minor versions of the engine, starting from Godot 3.2.

The current minimum compatible version, with api.json replacement, is Godot 3.1.1-stable. Changes to this will be considered a breaking change, and will be called out in the release notes.

The bindings do not support Godot 4.0 (master branch) currently.

Requirements

The generator makes use of bindgen, which depends on Clang. Instructions for installing bindgen's dependencies for popular OSes can be found in their documentation: https://rust-lang.github.io/rust-bindgen/requirements.html.

bindgen may complain about a missing llvm-config binary, but it is not actually required to build the gdnative crate. If you see a warning about llvm-config and a failed build, it's likely that you're having a different problem!

Usage

Godot 3.2.2-stable

After bindgen dependencies are installed, add the gdnative crate as a dependency, and set the crate type to cdylib:

[dependencies]
gdnative = "0.9.0-preview.0"

[lib]
crate-type = ["cdylib"]

Other versions or custom builds

The bindings are currently generated from the API description of Godot 3.2.2-stable by default. To use the bindings with another version or a custom build, see Using custom builds of Godot in the user guide.

Example

The most general use-case of the bindings will be to interact with Godot using the generated wrapper classes, as well as providing custom functionality by exposing Rust types as NativeScripts.

NativeScript is an extension for GDNative that allows a dynamic library to register "script classes" to Godot.

As is tradition, a simple "Hello World" should serve as an introduction. For a full tutorial, check out "Getting Started" from the user guide!

use gdnative::prelude::*;

#[derive(NativeClass)]
#[inherit(Node)]
pub struct HelloWorld;

#[methods]
impl HelloWorld {
    fn new(_owner: &Node) -> Self {
        HelloWorld
    }

    #[export]
    fn _ready(&self, _owner: &Node) {
        godot_print!("hello, world.");
    }
}

fn init(handle: InitHandle) {
    handle.add_class::<HelloWorld>();
}

godot_init!(init);

Further examples

The /examples directory contains several ready to use examples, complete with Godot projects and setup for easy compilation from Cargo:

Third-party resources

Several third-party resources have been created for the bindings. However, most of them are not updated for 0.9. If you have updated yours, open a PR to let us know!

Outdated resources for godot-rust 0.8

Tutorials

Open-source projects

Utilities

Contributing

See the contribution guidelines

License

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be licensed under the MIT license, without any additional terms or conditions.

Dependencies

~1.2–1.7MB
~34K SLoC