Expand description
§sola-raylib
sola_raylib is a safe Rust binding to Raylib, a C library for enjoying games programming.
To get started, take a look at the init_window function. This initializes Raylib and shows a window, and returns a RaylibHandle. This handle is very important, because it is the way in which one accesses the vast majority of Raylib’s functionality. This means that it must not go out of scope until the game is ready to exit. You will also recieve a !Send and !Sync RaylibThread required for thread local functions.
For more control over the game window, the init function will return a RaylibBuilder which allows for tweaking various settings such as VSync, anti-aliasing, fullscreen, and so on. Calling RaylibBuilder::build will then provide a RaylibHandle.
Some useful constants can be found in the consts module, which is also re-exported in the prelude module. In most cases you will probably want to use sola_raylib::prelude::*; to make your experience more smooth.
§Examples
The classic “Hello, world”:
use sola_raylib::prelude::*;
fn main() {
let (mut rl, thread) = sola_raylib::init()
.size(640, 480)
.title("Hello, World")
.build();
while !rl.window_should_close() {
let mut d = rl.begin_drawing(&thread);
d.clear_background(Color::WHITE);
d.draw_text("Hello, world!", 12, 12, 20, Color::BLACK);
}
}§Building for the web
sola-raylib supports wasm32-unknown-emscripten. The link flags
raylib needs (-sUSE_GLFW=3, -sASYNCIFY=1, etc.) live in your
project’s .cargo/config.toml, since cargo can’t propagate linker
flags out of a sys-crate build script.
core::game_loop::run is the cross-platform loop helper. The
project web guide has the config recipe, asset bundling, save
data, audio, and deploy notes.
§Cargo features
sola-raylib exposes Cargo features that toggle build-time options on the
underlying raylib C library. The full reference, with platform notes and
known-broken flags, lives in the project README; the quick summary:
Build / linking
bindgen(default): generate FFI bindings at build time. Disable to supply a hand-rolledbindings.rs(for platforms bindgen can’t target).nobuild: skip building and linking raylib entirely. You then link it yourself (used for docs.rs and headless setups).
Platform and rendering backend
wayland: build raylib’s GLFW with native Wayland support on Linux. Requires the systemglfw-devel(cmake config files), not just the runtime.sdl: use the SDL platform backend. The build script auto-picks SDL3 if present, otherwise SDL2, viapkg-config.opengl_33/opengl_21/opengl_es_20/opengl_es_30: force a specific GL backend.software_render,platform_memory,platform_web_rgfw: experimental raylib 6.0 backends. See the README for caveats.
Behavior toggles
custom_frame_control: enable raylib’sSUPPORT_CUSTOM_FRAME_CONTROL, so you drive frame timing yourself.noscreenshot: disable raylib’s built-in F12 screenshot keybind.
Interop
with_serde: deriveserde::Serialize/Deserializeon public types.convert_mint: conversions to/from themintmath types.
Re-exports§
Modules§
- consts
- Various constant enums to use with raylib
- core
- ease
- Easing and interpolation helpers.
- ffi
- The raw, unsafe FFI binding, in case you need that escape hatch or the safe layer doesn’t provide something you need.
- prelude
- The raylib-rs prelude.
- rgui