libretro-core-rs
Rust helpers for building libretro cores.
libretro-core wraps the libretro C ABI behind a single Core trait, so you
write idiomatic Rust and the crate handles the retro_* symbol exports, the
environment callback, AV info negotiation, and content registration for you.
Features
- Safe-ish
Coretrait. Implement a handful of methods (system_info,av_info,run, …) instead of dozens ofunsafe extern "C"functions. - One-line symbol export.
libretro::export_core!(MyCore::default())generates everyretro_*entry point the frontend looks for. - AV helpers.
fixed_system_av_info,silent_stereo_frames_for_video_frame, and pixel-format helpers cover the boilerplate aroundSystemAvInfoand audio/video pacing. - Content contracts. Declare supported extensions and "no content required"
mode with
ContentContract; the crate handles the matching environment callbacks. - Hardware rendering. Negotiate an OpenGL/GLES context with the frontend
and load GL entry points through the libretro callback path (no direct
linking against
libGL). - Input + runtime. A
Runtimehandle exposes input polling, video refresh, audio submission, and environment access duringrun.
Quick start
Add the dependency and configure your crate as a cdylib:
# Cargo.toml
[]
= "hello-libretro"
= "0.1.0"
= "2024"
[]
= ["cdylib"]
[]
= { = "libretro-core", = "0.1" }
A complete "hello world" core that paints a blue framebuffer at 320×240 / 60 Hz with silent stereo audio:
// src/lib.rs
use ;
const WIDTH: u32 = 320;
const HEIGHT: u32 = 240;
const FPS: u32 = 60;
const SAMPLE_RATE: u32 = 48_000;
const BLUE_0RGB1555: u16 = 0x001F;
;
export_core!;
Build it:
The resulting target/release/libhello_libretro.so (or .dylib / .dll) can
be loaded by any libretro frontend such as RetroArch.
Workspace layout
| Crate | Purpose |
|---|---|
libretro-core |
The library above — safe Core trait, AV/content helpers, hardware-render negotiation, typed Gl access. |
libretro-diagnostics |
Optional GL/text/frame helpers for cores that need on-screen failure output. |
examples/software-libretro |
Minimal software framebuffer core. |
examples/retrocompat-libretro |
OpenGL/GLES compatibility triangle and text diagnostic core. |
examples/demo-libretro |
Generic OpenGL/input/audio demo core. |
Run the test suite with:
License
MIT — see LICENSE.