Home

Awesome

This code is terribly outdated.

There are "official" (and more importantly, auto-generated) Rust bindings now. Head over to sokol-rust to check them out.

sokol-rs

This repository contains source code of the following Rust library crates:

To complement the crates above:

How to build

The current version compiles (and has been tested) with stable Rust (v1.34.1) on Windows (both MSVC and GNU toolchains), MacOS and Linux.

> git clone --recursive https://github.com/code-disaster/sokol-rs
> cd sokol-rs
> cargo build

The sokol-samples folder contains some examples ported from sokol-samples/sapp.

> cargo run --bin clear-sapp 

About the implementation

The SApp program loop

In the C version of sokol_app, when compiled with SOKOL_NO_ENTRY, you call sapp_run(), passing callback function pointers for setup, frame updates, and cleanup.

In the Rust version, you call sokol::app::sapp_run(). This hands over control to the C library, which then will operate as usual. The C callbacks are implemented by sokol-rs. They are forwarded to your application via the SApp trait. User applications implement this trait to power the application loop.

Check the clear-sapp sample for a minimal implementation.

API style and implementation details

I tried to stay as close as possible to the source, while adjusting to the Rust naming conventions, as well as making the public API more convenient in places a direct port would be too cumbersome.

In the Rust library, the app, gfx and audio modules are not as separable as their C counterparts. Essentially, sokol-rs assumes that you use them in conjunction.

Status

The following libraries are implemented:

headerRust modulestatusnotes
sokol_app.hsokol::appdone
sokol_args.hn/an/alow priority: there are many cmdline parsers for Rust already
sokol_audio.hsokol::audiodonecallback API via trait in sokol::app
sokol_gfx.hsokol::gfxmostly donetrace hooks are enabled (and consumed by the sokol_gfx_imgui implementation in the sokol-imgui crate)<br><br>missing: separate resource management, render contexts, user-provided buffers<br><br>not implemented: sg_query_*_info() functions
sokol_time.hsokol::timedone

Additionally, some utility libraries are available:

headerRust modulestatusnotes
sokol_gfx_imgui.hsokol_imgui::gfxpartially<br>donesg_imgui_t is wrapped opaquely instead of replicated in Rust<br><br>missing: sg_imgui_draw_*_content and sg_imgui_draw_*_window functions
sokol_gl.hn/an/ano plans yet
sokol_imgui.hsokol_imgui::imguidone

Remarks