Skip to content

Commit 441c0d0

Browse files
authored
5.7.0: Replace ffi::Vectors with Mint and safe binding Vectors with glam (#192)
* 5.7.0: Replace ffi::Vectors with Mint and safe binding Vectors with glam. Various bugfixes * 5.7.0 fix samples from not compiling * fix color examples preventing CI from passing * #[must_use] for more functions that return things * bump thiserror and rand dependencies * expose core::math::glam * delete old unused config.h * minor: removed unused variables and fix lint warnings * [minor] upgraded raygui(4.1->4.5), removed needless cpp wrappers * minor: upgrade to rust edition 2024, fix 2024 errors/lints * minor: remove unused/unmaintained file "gui_textbox_extended.h" * minor: remove allocations from `Image::draw_triangle_strip/draw_triangle_fan`, `RaylibDraw3D::draw_mesh_instanced` * remove imgui in favor of a 1 file implementation in samples * Update CHANGELOG.md * invert bindgen flag * Update Readme
1 parent 66cb8ec commit 441c0d0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+3016
-7223
lines changed

.gitmodules

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,3 @@
33
url = https://github.com/raysan5/raylib
44
commit = "5.5"
55
shallow = true
6-
[submodule "raylib-sys/binding/rlImGui"]
7-
path = raylib-sys/binding/rlImGui
8-
url = https://github.com/raylib-extras/rlImGui/
9-
commit = "7864355"

CHANGELOG.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
# raylib-rs Changelog
22

3-
## 3.7.0 (WIP)
3+
## 5.7.0
4+
- More improved ergonomics
5+
- REFACTOR: Everything that interfaces with `raylib-sys` **has to use mint vectors** because as it has the most common supported interface type in the rust ecosystem. (tl;dr Replaced `ffi::Vectors -> mint::Vectors`)
6+
- REFACTOR: Everything that interfaces with raylib safe bindings will often **take as input mint vectors but output/store glam-rs vectors**(storing them in Camera, Mesh, Boundingbox, etc), This can easily be swapped out. (tl;dr Replaced: `math::core::Vectors -> glam::Vectors`. glam Matrix and Quat however are incompatible so these stay as is)
7+
- BREAKING: Code that uses `Vector4` constructors break, instead use `Vector4::new()
8+
- REFACTOR: `Camera3D` ported methods in favor of calling ffi for easier maintenance reasons
9+
- REFACTOR: trace_log from needing to be on the RaylibHandle and take &self
10+
- MOVED: `color.rs` to `raylib-sys` because having 2 versions of this simple structure is pointless
11+
- MOVED: `Rectangle` to `raylib-sys` because having 2 versions of this simple structure is pointless
12+
- REMOVED: needless `target_os = windows` for rlgl getting&setting matrix functions
13+
- BUGFIX : `build.rs` gen_utils function generated the `util_log.c` as `rgui`making raygui not work
14+
- Removed: Removed imgui from being a feature on `raylib-sys`, instead check [imgui example](https://github.com/raylib-rs/raylib-rs/blob/unstable/samples/imgui.rs) for integration
15+
## build script changes:
16+
- Blacklist Vector2, Vector3, Vector4, Matrix, Quaternion, Rectangle, Color from generating in bindgen as they are replaced by mint and manual implementations
17+
- BUGFIX: Fixed bug where `utils_log` compiled as "rgui" making the rust build fail in some cases
18+
- Prevent android builds from turning on GLFW flags
19+
- Added/exposed various feature flags
20+
- Invert `bindgen` feature flag to `nobindgen` since its a more saner default
21+
22+
23+
## 3.7.0
424

525
- [core] ADDED: LoadVrStereoConfig()
626
- [core] ADDED: UnloadVrStereoConfig()

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[workspace]
22
members = ["raylib", "raylib-sys"]
33
exclude = ["raylib-test", "samples"]
4+
resolver = "2"

README.md

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
# raylib-rs
1111

12-
raylib-rs is a Rust binding for [raylib](http://www.raylib.com/) 5.5. It currently targets Rust toolchain version 1.78 or higher.
12+
raylib-rs is a Rust binding for [raylib](http://www.raylib.com/) **5.5**. It currently targets Rust toolchain version 1.78 or higher.
1313

1414
Please checkout the showcase directory to find usage examples!
1515

@@ -21,14 +21,6 @@ Though this binding tries to stay close to the simple C API, it makes some chang
2121

2222
Most development happens over at: https://github.com/raylib-rs/raylib-rs
2323

24-
- Resources are automatically cleaned up when they go out of scope (or when `std::mem::drop` is called). This is essentially RAII. This means that "Unload" functions are not exposed (and not necessary unless you obtain a `Weak` resource using make_weak()).
25-
- Most of the Raylib API is exposed through `RaylibHandle`, which is for enforcing that Raylib is only initialized once, and for making sure the window is closed properly. RaylibHandle has no size and goes away at compile time. Because of mutability rules, Raylib-rs is thread safe!
26-
- A `RaylibHandle` and `RaylibThread` are obtained through `raylib::init_window(...)` or through the newer `init()` function which will allow you to `build` up some window options before initialization (replaces `set_config_flags`). RaylibThread should not be sent to any other threads, or used in a any syncronization primitives (Mutex, Arc) etc.
27-
- Manually closing the window is unnecessary, because `CloseWindow` is automatically called when `RaylibHandle` goes out of scope.
28-
- `Model::set_material`, `Material::set_shader`, and `MaterialMap::set_texture` methods were added since one cannot set the fields directly. Also enforces correct ownership semantics.
29-
- `Font::from_data`, `Font::set_chars`, and `Font::set_texture` methods were added to create a `Font` from loaded `CharInfo` data.
30-
- `SubText` and `FormatText` are omitted, and are instead covered by Rust's string slicing and Rust's `format!` macro, respectively.
31-
3224
Versions normally match Raylib's own, with the minor number incremented for any patches (i.e. 5.5.1 for Raylib v5.5). On occassion, if enough breaking changes are made in between Raylib releases, we'll release a 5.6, which is 5.5 but with breaking changes.
3325

3426
# Installation
@@ -43,14 +35,14 @@ Versions normally match Raylib's own, with the minor number incremented for any
4335

4436
## Build Dependencies
4537

46-
Requires glfw, cmake, and curl. Tips on making things work smoothly on all platforms is appreciated.
38+
Requires `glfw`, `cmake`, and `curl`. Tips on making things work smoothly on all platforms is appreciated.
4739
Follow instructions for building raylib for your platform [here](https://github.com/raysan5/raylib/wiki)
4840

4941
1. Add the dependency to your `Cargo.toml`:
5042

5143
```toml
5244
[dependencies]
53-
raylib = { version = "5.6.0" }
45+
raylib = { version = "5.7.0", features = [] }
5446
```
5547

5648
2. Start coding!
@@ -85,16 +77,6 @@ You'll also need to enable the Wayland feature on the raylib crate:
8577

8678
Contributions are welcome to improve or fix the shell.nix!
8779

88-
# Tech Notes
89-
90-
- Structs holding resources have RAII/move semantics, including: `Image`, `Texture2D`, `RenderTexture2D`, `Font`, `Mesh`, `Shader`, `Material`, and `Model`.
91-
- `Wave`, `Sound`, `Music`, and `AudioStream` have lifetimes bound to `AudioHandle`.
92-
- Functions dealing with string data take in `&str` and/or return an owned `String`, for the sake of safety. The exception to this is the gui draw functions which take &CStr to avoid per frame allocations. The `rstr!` macro helps make this easy.
93-
- In C, `LoadFontData` returns a pointer to a heap-allocated array of `CharInfo` structs. In this Rust binding, said array is copied into an owned `Vec<CharInfo>`, the original data is freed, and the owned Vec is returned.
94-
- In C, `LoadDroppedFiles` returns a pointer to an array of strings owned by raylib. Again, for safety and also ease of use, this binding copies said array into a `Vec<String>` which is returned to the caller.
95-
- I've tried to make linking automatic, though I've only tested on Windows 10, Ubuntu, and MacOS 15. Other platforms may have other considerations.
96-
- OpenGL 3.3, 2.1, and ES 2.0 may be forced via adding `["opengl_33"]`, `["opengl_21"]` or `["opengl_es_20]` to the `features` array in your Cargo.toml dependency definition.
97-
9880
## Building from source
9981

10082
1. Clone repository: `git clone --recurse-submodules`
@@ -113,10 +95,50 @@ Contributions are welcome to improve or fix the shell.nix!
11395

11496
Cross compiling with raylib-rs can be made easier with cross. [See more on the wiki](https://github.com/raylib-rs/raylib-rs/wiki/Cross%E2%80%90compiling-using-cross)
11597

98+
## Running Examples
99+
1. `cd samples`
100+
2. `cargo run --bin 3d_camera_first_person`
101+
116102
# Extras
103+
- See [the wiki](https://github.com/raylib-rs/raylib-rs/wiki) for more info
104+
- Raylib has tons of features that are **not included by default**, such as support for various file formats like JPG, etc. We match raylibs default build configuration but this can be customized by enabling and disabling [feature flags](https://github.com/raylib-rs/raylib-rs/blob/unstable/raylib/Cargo.toml)
105+
- For a leaner custom build of raylib, set `default-features = false`, **but beware** that there are mandatory flags that when compiled without will break raylib(such as `SUPPORT_STANDARD_FILEIO`)
106+
- See how to integrate dearimgui into your project in [samples/imgui.rs](https://github.com/raylib-rs/raylib-rs/blob/unstable/samples/imgui.rs)
107+
108+
# Contributing checklist:
109+
- [ ] Run `cargo test` and `cargo test --doc` while in `raylib` safe bindings directory and make sure no tests fail
110+
- [ ] Test on major platforms (windows, linux)
111+
- [ ] Run examples: `cd samples` and `cargo run --bin <sample_name>`
112+
- [ ] Find & replace the version numbers in every Cargo.toml "5.6.x" -> "5.6.x"
113+
- [ ] Update the changelog
114+
- [ ] Keep a lookout on tagging functions with `#[inline]` , `#[must_use]` , and `const`
115+
116+
### Updating raygui:
117+
The `raygui.h` file has to have this ifdef modified to point to where `raylib.h` is:
118+
```c
119+
#if !defined(RAYGUI_STANDALONE)
120+
#include "../raylib/src/raylib.h"
121+
#endif
122+
```
123+
124+
# Safe Binding characteristics
125+
- Resources are automatically cleaned up when they go out of scope (or when `std::mem::drop` is called). This is essentially RAII. This means that "Unload" functions are not exposed (and not necessary unless you obtain a `Weak` resource using make_weak()).
126+
- Most of the Raylib API is exposed through `RaylibHandle`, which is for enforcing that Raylib is only initialized once, and for making sure the window is closed properly. RaylibHandle has no size and goes away at compile time. Because of mutability rules, Raylib-rs is thread safe!
127+
- A `RaylibHandle` and `RaylibThread` are obtained through `raylib::init_window(...)` or through the newer `init()` function which will allow you to `build` up some window options before initialization (replaces `set_config_flags`). RaylibThread should not be sent to any other threads, or used in a any syncronization primitives (Mutex, Arc) etc.
128+
- Manually closing the window is unnecessary, because `CloseWindow` is automatically called when `RaylibHandle` goes out of scope.
129+
- `Model::set_material`, `Material::set_shader`, and `MaterialMap::set_texture` methods were added since one cannot set the fields directly. Also enforces correct ownership semantics.
130+
- `Font::from_data`, `Font::set_chars`, and `Font::set_texture` methods were added to create a `Font` from loaded `CharInfo` data.
131+
- `SubText` and `FormatText` are omitted, and are instead covered by Rust's string slicing and Rust's `format!` macro, respectively.
117132

118-
- In addition to the base library, there is also a convenient `ease` module which contains various interpolation/easing functions ported from raylib's `easings.h`, as well as a `Tween` struct to assist in using these functions.
119-
- Equivalent math and vector operations, ported from `raymath.h`, are `impl`ed on the various Vector and Matrix types. Operator overloading is used for more intuitive design.
133+
# Tech Notes
134+
135+
- Structs holding resources have RAII/move semantics, including: `Image`, `Texture2D`, `RenderTexture2D`, `Font`, `Mesh`, `Shader`, `Material`, and `Model`.
136+
- `Wave`, `Sound`, `Music`, and `AudioStream` have lifetimes bound to `AudioHandle`.
137+
- Functions dealing with string data take in `&str` and/or return an owned `String`, for the sake of safety. The exception to this is the gui draw functions which take &CStr to avoid per frame allocations. The `rstr!` macro helps make this easy.
138+
- In C, `LoadFontData` returns a pointer to a heap-allocated array of `CharInfo` structs. In this Rust binding, said array is copied into an owned `Vec<CharInfo>`, the original data is freed, and the owned Vec is returned.
139+
- In C, `LoadDroppedFiles` returns a pointer to an array of strings owned by raylib. Again, for safety and also ease of use, this binding copies said array into a `Vec<String>` which is returned to the caller.
140+
- I've tried to make linking automatic, though I've only tested on Windows 10, Ubuntu, and MacOS 15. Other platforms may have other considerations.
141+
- OpenGL 3.3, 2.1, and ES 2.0 may be forced via adding `["opengl_33"]`, `["opengl_21"]` or `["opengl_es_20]` to the `features` array in your Cargo.toml dependency definition.
120142

121143
# Testing
122144

raylib-sys/Cargo.toml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
11
[package]
22
name = "raylib-sys"
3-
version = "5.6.0"
3+
version = "5.7.0"
44
authors = ["raylib-rs team <https://github.com/raylib-rs/raylib-rs>"]
55
license = "Zlib"
66
description = "Raw FFI bindings for Raylib"
77
documentation = "https://docs.rs/raylib-sys"
88
repository = "https://github.com/raylib-rs/raylib-rs"
99
keywords = ["bindings", "raylib", "gamedev", "ffi"]
1010
categories = ["external-ffi-bindings"]
11-
edition = "2021"
11+
edition = "2024"
1212
exclude = ["raylib/examples/*", "raylib/projects/*", "raylib/templates/*"]
1313

1414
[dependencies]
15-
imgui = { version = "0.12.0", optional = true, features = [] }
16-
imgui-sys = { version = "0.12.0", optional = true }
15+
mint = { version = "0.5" }
16+
serde = { version = "1.0", optional = true }
1717

1818
[build-dependencies]
1919
cmake = "0.1.51"
2020
cc = { version = "1.0", features = ["parallel"] }
21-
bindgen = "0.70"
21+
bindgen = "0.71"
2222

2323
[features]
2424
# default features follow the cmake version: https://github.com/raysan5/raylib/wiki/CMake-Build-Options
2525
# NOTE: some are critical, e.g: SUPPORT_STANDARD_FILEIO should always be turned on because many things like `LoadShader()` uses it to read text
2626
default = [
27-
"bindgen",
2827
"GLFW_BUILD_X11",
2928
"USE_AUDIO",
3029
"SUPPORT_MODULE_RSHAPES",
@@ -72,12 +71,11 @@ default = [
7271
"SUPPORT_STANDARD_FILEIO",
7372
"SUPPORT_TRACELOG",
7473
]
74+
serde = ["dep:serde", "mint/serde"]
7575
raygui = []
76-
# Generate bindings automatically.
77-
# You can turn this off if you wanna go into the source and put in your own bindings.rs, which is
78-
# useful since bindgen doesn't work on esoteric platforms.
79-
bindgen = []
80-
imgui = ["dep:imgui", "dep:imgui-sys"]
76+
# Do not autogenerate bindings, instead read an existing one specified by env RAYLIB_BINDGEN_LOCATION
77+
# useful when bindgen doesn't generate correctly on esoteric platforms and need manual auidting
78+
nobindgen = []
8179

8280

8381
# ----- Copy and paste these from `raylib-sys` for easier maintance

raylib-sys/binding/binding.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "raygui.h"
22
#include "../raylib/src/rlgl.h"
3+
#include "../raylib/src/rcamera.h"
34
#include "utils_log.h"
45

56

0 commit comments

Comments
 (0)