Native MoonBit bindings for the Sokol cross-platform C libraries
| Platform | Default graphics backend | Native dependencies |
|---|---|---|
| macOS | Metal | Xcode command-line tools; system AppKit, QuartzCore, Metal, AudioToolbox |
| Linux | OpenGL | C compiler; X11, Xi, Xcursor, GL and ALSA development packages |
| Windows | D3D11 | Clang and Windows SDK |
moon run cmd/main # colored triangle; Escape closes the window
moon run cmd/main -- --smoke # render ten frames, then quit
moon run examples/offscreen # macOS Metal rendering with GPU pixel readback
moon check --target all --warn-list +73
moon testSOKOL_HEADLESS=1 moon test --target native
SOKOL_HEADLESS=1 moon test --target native --release///|
import {
"Milky2018/sokol/app",
"Milky2018/sokol/gfx",
"Milky2018/sokol/glue",
}| Package | Upstream | Main APIs |
|---|---|---|
| app | sokol_app.h | Window/input/clipboard/drop events, lifecycle, environment, native handles |
| gfx | sokol_gfx.h | Buffers, images, samplers, shaders, pipelines, views, render/compute passes, uploads/copies, queries/stats, trace hooks/listeners |
| audio | sokol_audio.h | Audio configuration, device queries, interleaved PCM push, native callback interop |
| fetch | sokol_fetch.h | Async and streaming file loading, owned response snapshots, cancellation, pause/continue, buffer binding |
| time | sokol_time.h | Monotonic ticks, lap timing, refresh-rate rounding and unit conversions |
| args | sokol_args.h | Argument parsing, booleans, defaults and indexed queries |
| log | sokol_log.h | Standard Sokol logging |
| glue | sokol_glue.h | environment() and swapchain() from the active app |
| native | FFI support | Explicitly unowned native pointers and C-string encoding |
///|
#cfg(platform="windows")
fn native_window() -> @native.Handle {
@app.win32_get_hwnd()
}///|
test "owned buffer descriptor" {
let desc = @gfx.BufferDesc::new()
.set_label("vertices")
.set_data(@gfx.Range::from_floats([0.0F, 1.0F, 2.0F]))
assert_eq(desc.data().size(), 12UL)
assert_eq(desc.copy().set_label("other").label(), "other")
assert_eq(desc.label(), "vertices")
}@fetch.setup(@fetch.Desc::new().set_logger(@fetch.Logger::default()))
let request = @fetch.Request::new()
.set_path("assets/texture.bin")
.set_buffer(@fetch.Range::allocate(1024 * 1024))
let handle = @fetch.send(request, fn(response) {
if response.fetched() { consume(response.data().bytes()) }
if response.failed() { report(response.error_code()) }
})
// Call @fetch.dowork() in the application's frame callback.
// When loading ends, or during application cleanup:
@fetch.shutdown()python3 scripts/check_platform_api.py
moon check --target all --warn-list +73
SOKOL_HEADLESS=1 moon test --target native
SOKOL_HEADLESS=1 moon test --target native --release
moon info && moon fmtSOKOL_HEADLESS=1 python3 scripts/run-asan.py
python3 scripts/run-asan.py --run cmd/main --run examples/offscreen # macOS GPU/app checkslet UPSTREAM_REVISION : StringInstall
Download zipNative MoonBit bindings for the Sokol cross-platform C libraries