HackerReposA FIELD GUIDE TO OPEN SOURCE
ProSponsor the shelf♧ 0
← Back to top all-time
floooh
sokol-zig
C2019–2026
floooh / sokol-zig

sokol-zig

Zig bindings for the sokol headers (https://github.com/floooh/sokol)

2Distinct people
11Mentions
0Explicit recommenders
744GitHub stars
REPOSITORY AT A GLANCE

What to know before exploring

What it is

Zig bindings for the sokol headers (https://github.com/floooh/sokol)

GitHub

Where it is used

No documented product use has been verified yet.

What people are saying

No recommendation phrase was found in the indexed comments.

No classified warning is attached to this page. Read the discussions before treating silence as approval.

Also in these discussions

Mentioned in the same Hacker News threads. That is not proof they are substitutes.

This week on Hacker News

Nov 7–Nov 14 UTC · Direct repository links and separately labeled related project stories. Indexed through 11/14/2026, 3:56:07 PM UTC.

No direct repository links were found in the indexed HN discussions over the past seven days. Older discussions are available below.

Mentions over time

HN mentions by year11 dated mentions

Observed mentions: 2019-10-02 16:05:39 UTC to 2026-02-20 10:58:50 UTC.

01232019-01-01 00:00:00 UTC to 2020-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments20192020-01-01 00:00:00 UTC to 2021-01-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2021-01-01 00:00:00 UTC to 2022-01-01 00:00:00 UTC (exclusive): 3 mentions; 0 submissions, 3 comments2022-01-01 00:00:00 UTC to 2023-01-01 00:00:00 UTC (exclusive): 2 mentions; 0 submissions, 2 comments20222023-01-01 00:00:00 UTC to 2024-01-01 00:00:00 UTC (exclusive): 3 mentions; 0 submissions, 3 comments2024-01-01 00:00:00 UTC to 2025-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2025-01-01 00:00:00 UTC to 2026-01-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2026-01-01 00:00:00 UTC to 2027-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments. Incomplete calendar period.2026*

* An incomplete calendar period is marked with an outlined bar. Its count is not directly comparable with a full period.

Counts come from the repository’s dated source evidence. Index cutoff: 2026-11-02 08:16:59 UTC.

View mention counts and date ranges
UTC ranges include their start and exclude their end. Select a period to filter the source evidence.
PeriodStart (UTC)End (exclusive, UTC)MentionsSubmissionsComments
20192019-01-01 00:00:00 UTC2020-01-01 00:00:00 UTC101
20202020-01-01 00:00:00 UTC2021-01-01 00:00:00 UTC000
20212021-01-01 00:00:00 UTC2022-01-01 00:00:00 UTC303
20222022-01-01 00:00:00 UTC2023-01-01 00:00:00 UTC202
20232023-01-01 00:00:00 UTC2024-01-01 00:00:00 UTC303
20242024-01-01 00:00:00 UTC2025-01-01 00:00:00 UTC101
20252025-01-01 00:00:00 UTC2026-01-01 00:00:00 UTC000
2026 (partial)2026-01-01 00:00:00 UTC2027-01-01 00:00:00 UTC101

What Hacker News says

11 sources
I can show more code examples instead: E.g. notice how here in Rust each nested struct needs a type annotation, even though the compiler could trivially infer the type. Rust also cannot initialize arrays with random access directly, it needs to go through an expression block. Finally Rust requires `..Default::default()`: https://github.com/floooh/sokol-rust/blob/f824cd740d2ac96691... Zig has most of the same issues as Rust, but at least the compiler is able to infer the nested struct types via `.{ }`: https://github.com/floooh/sokol-zig/blob/17beeab59a64b12c307... I don't have C++ code around, but compared to C99 it has the following restrictions: - designators must appear in order (a no-go for any non-trivial struct) - cannot chain designators (e.g. `.a.b.c = 123`) - doesn't have the random array access syntax via `[index]` > ...like a p
Read the rest
retty minor syntax issue... ...sure, each language only has a handful minor syntax issues, but these papercuts add up to a lot of syntax noise to sift through when compared to the equivalent C99 code.
In Defer available in gcc and clang
When initializing a struct, Zig currently doesn't allow chained designators and also doesn't allow to partially initialize arrays and have the rest of the array filled up with default values (the first one isn't all that important, but the second is). E.g. the closest Zig equivalent to this C99 code: https://github.com/floooh/sokol-samples/blob/b3bc55c4411fa03... ...is this: https://github.com/floooh/sokol-zig/blob/a4b3c287fadd153a504... ...note how part of the initialization had to be moved out into separate assignments, which means the struct can't be created as const. There's a ticket about this here, but it's currently not high-priority: https://github.com/ziglang/zig/issues/6068 Zig also isn't alone in this, I haven't encountered any other programming language yet which has such a flexible struct initialization syntax as C99. Odin is
Read the rest
In Zig cookbook: collection of simple Zig programs that demonstrate good practices
I maintain auto-generated bindings for my C libraries for Zig and Nim (and Odin and Rust - although the Rust bindings definitely need some love to make them a lot more idiomatic). I think looking at the examples (which is essentially the same code in different languages) gives you a high level idea, but they only scratch the surface when it comes to language features (for instance the Zig examples don't use any comptime features): Zig: https://github.com/floooh/sokol-zig/tree/master/src/examples Nim: https://github.com/floooh/sokol-nim/tree/master/examples Odin: https://github.com/floooh/sokol-odin/tree/main/examples Rust: https://github.com/floooh/sokol-rust/tree/main/examples
In Nim 2.0
IME you really need a programming language to describe a build, even when it is desired that the result looks 'mostly declarative' in the end. E.g. not sure how Meson handles this, but when I have a project with dozens of similar build targets and platform specific compile options, I really want to do the build description in a loop instead of a data tree. (for example: https://github.com/floooh/sokol-zig/blob/3f978e58712f9eb029b...) PS: apparently Meson build scripts can also have variables, conditions and loops, which I guess makes the difference to an actually Turing complete build system rather esoterical? https://mesonbuild.com/Syntax.html#logical-operations A proper build system is so much more than just describing build targets and their dependencies, you also want to generate source code, copy and process data files, communicate w
Read the rest
ith REST services etc... The more this happens in a 'real' programming language the better.
In Zig build system
> they're nontrivial to bind to from non-C languages This particular library doesn't seem to follow the STB convention where the implementation is inside an #ifdef IMPLEMENTATION block, but that would be trivial to fix. Once you have that it's just as trivial to use from other languages as a regular .h/.c library, just include the implementation into a C source file and compile that into a static link library or DLL, then include the declarations (without IMPLEMENTATION define) into your language (if the language can directly include C headers) or use the header to auto-generate the bindings. For example: - https://github.com/floooh/sokol-zig - https://github.com/floooh/sokol-nim - https://github.com/floooh/sokol-odin These are all auto-generated from STB-style single-file libraries: https://github.com/floooh/sokol
In Tinyphysicsengine: Minimalist 3D C99 single-header physics engine
For a somewhat more complete example which runs in browsers, check out my little pacman.zig toy project [0]. This is cheating a bit by using the Emscripten SDK as 'sysroot' (needed for the Emscripten headers to provide the glue to web APIs), and the Emscripten linker to create the additional html and js output file, but the actual code is all compiled with the Zig compiler to WASM, emcc is only used for linking. The interesting part is that the platform abstraction is provided by the sokol C headers [1], with auto-generated Zig bindings [2]. It's interesting because the C headers use "Emscripten magic" (mainly embedding Javascript snippets in the C sources via the EM_JS() macro), and the Zig compiler is able to compile this (when it has access to the Emscripten headers). It would be nice if the "Emscripten platform" could get the same typ
Read the rest
e of cross-compilation support as the desktop platforms eventually, but apart from bundling the Emscripten headers, this would also require to implement some of the "Emscripten magic" in the Zig linker. Maybe projects like WaJIC [3] can help with this (this basically implements the "Emscripten magic" of embedding Javascript snippets in C/C++ source code, but without Emscripten (only the wasm-opt tool is needed AFAIK). Anyway... it's a lot of fun to tinker around with this stuff in Zig :) [0] https://github.com/floooh/pacman.zig [1] https://github.com/floooh/sokol [2] https://github.com/floooh/sokol-zig [3] https://github.com/schellingb/wajic
In Zig and WASM
(disclaimer: shameless plug) Here's another cross-platform alternative, auto-generated Zig bindings to the Sokol headers: https://github.com/floooh/sokol-zig This is quite a bit slimmer than using one of the WebGPU libraries like wgpu-rs or Dawn, because sokol-gfx doesn't need an integrated shader cross-compiler (instead translation from a common shader source to the backend-specific shader formats happens offline). Eventually I'd also like to support the Android, iOS and WASM backends from Zig (currently this only works from C/C++, for instance here are the samples compiled to WASM: https://floooh.github.io/sokol-html5/) And finally, I'd also like to become completely independent from system SDKs for easier cross-compilation, but with a different approach: by automatically extracting and directly including only the required declarations
Read the rest
right into the source files instead of bundling them into separate git repositories (similar to how GL loaders for Windows work).
In Mach Engine: The Future of Graphics (With Zig)
Not quite as "radical", but I did something in that direction, a minimal "starter kit" for developing Dear ImGui applications in C99: https://github.com/floooh/cimgui-sokol-starterkit It needs the system's "default compiler toolchain" and cmake, but other then that, there are no external dependencies, and I tried to keep everything as simple as possible (even the CMakeLists.txt file). All the dependencies (Dear ImGui, cimgui and the Sokol headers for cross-platform wrapping of the platform-specific window systems and 3D-APIs) are bundled right in the git repo. Zig and Nim are sort-of "in progress" (for instance, see the sokol-zig bindings here: https://github.com/floooh/sokol-zig/)
In A guide to Windows application development using w64devkit
I'm tackling this issue from two sides: (1) Change the C-API to make it more "binding-generator-friendly", for instance by adding a range/slice-struct to th C-API which bundles a pointer and associated size, or specially named typedefs that only exist to give the binding generator hints for special case handling. By adding a C-type which represents a range/slice, it's easier to connect high level languages to the C API, and as a nice side effect, the C-API also becomes safer and more "correct", because pointers and associated sizes can be passed around as one item. (2) Make the bindings-generator configurable on a per-language and per-API basis, this can be as simple as a map which overrides type- and function-names, or injects manually written code into the generated bindings. The goal is to make the generated bindings more idiomatic to
Read the rest
the target language. This mostly works if you have control over the underlying C-API of course, e.g. the language bindings are created by the original C-library project, not as an external project to convert a fixed C-API. I wrote a blog post about this whole topic: https://floooh.github.io/2020/08/23/sokol-bindgen.html ...and here's an example of such semi-auto-generated Zig bindings: https://github.com/floooh/sokol-zig/tree/master/src/sokol ...for instance note the "injected" helper functions here: https://github.com/floooh/sokol-zig/blob/1c93f60ad178869b84d...
In Making Win32 APIs More Accessible to More Languages

MAKE YOURSELF AT HOME

A few shortcuts

/
Search the collection
?
Open this guide
Esc
Close dialogs and navigation

Your saved repositories and interests stay in this browser.