floooh/sokol-zig is a C project with 742 stars. Zig bindings for the sokol headers (https://github.com/floooh/sokol)
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
In case of breaking changes in Zig, the bindings might fall behind. Please don't hesitate to
ping me via a Github issue, or even better, provide a PR :)
Related projects:
pacman.zig
chipz emulators
Dear ImGui sample project
Build Prerequisites
On Linux you'll need to install a couple of dev-packages. For instance with Ubuntu:
sudo apt install xorg-dev libpulse-dev
Additionally when using EGL instead of GLX:
sudo apt install libegl-dev`
Additionally when using the experimental Vulkan backend:
All other platforms should build 'out of the box'.
[!NOTE]
even though the experimental Vulkan backend now also supports Windows,
the build.zig has not been prepared yet. If you still want to tinker with
this you'll need to install the Vulkan SDK (https://vulkan.lunarg.com/sdk/home)
and use the VULKAN_SDK env variable to find the vulkan header and library stubs.
Building the samples
Supported platforms are: Windows, macOS, Linux (with X11) and web
On Linux install the following packages: libglu1-mesa-dev, mesa-common-dev, xorg-dev, libpulse-dev
(or generally: the dev packages required for X11, GL and PulseAudio development)
(also run zig build -l to get a list of build targets)
By default, the backend 3D API will be selected based on the target platform:
macOS: Metal
Windows: D3D11
Linux: GL
To force the GL backend on macOS or Windows, build with -Dgl=true:
> zig build -Dgl=true run-clear
To force the experimental Vulkan backend, build with -Dvulkan=true
> zig build -Dvulkan=true run-clear
NOTE: Vulkan support is currently only supported on Linux, and
as of Zig 0.16.x there's an issue with the libvulkan.so DLL from the
Vulkan SDK (linking with the system Vulkan DLL appears to work)
The clear sample prints the selected backend to the terminal:
For the web-samples, first install a local Emscripten SDK into ./zig-pkg:
zig build install-emsdk
...then build with -Dtarget=wasm32-emscripten
zig build examples -Dtarget=wasm32-emscripten
# or to build and run one of the samples
zig build run-clear -Dtarget=wasm32-emscripten
...
There is currently no build system functionality to update or delete the Emscripten SDK
after this first install. The current workaround is to simply delete the zig-pkg subdirectory.
Improving the Emscripten SDK integration with the Zig build system is planned for the future.
How to integrate sokol-zig into your project
Add a build.zig.zon file to your project which has at least a .sokol dependency:
To force the GL backend on macOS or Windows, you can pass .gl = true to the dependency call:
const dep_sokol = b.dependency("sokol", .{
.target = target,
.optimize = optimize,
// same as building sokol-zig with -Dgl=true
.gl = true
});
This can be done with any build option declared in sokol-zig.
If you also want to run on the web via -Dtarget=wasm32-emscripten, the web platform
build must look special, because Emscripten must be used for linking, and to run
the build result in a browser, a special run step must be created.
Such a 'hybrid' build script might look like this (copied straight from pacman.zig):
const std = @import("std");
const Build = std.Build;
const sokol = @import("sokol");
const Options = struct {
mod: *Build.Module,
dep_sokol: *Build.Dependency,
};
pub fn build(b: *Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const dep_sokol = b.dependency("sokol", .{
.target = target,
.optimize = optimize,
});
const mod_pacman = b.createModule(.{
.root_source_file = b.path("src/pacman.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "sokol", .module = dep_sokol.module("sokol") },
.{ .name = "shader", .module = try createShaderModule(b, dep_sokol) },
},
});
// special case handling for native vs web build
const opts = Options{ .mod = mod_pacman, .dep_sokol = dep_sokol };
if (target.result.cpu.arch.isWasm()) {
try buildWeb(b, opts);
} else {
try buildNative(b, opts);
}
}
// this is the regular build for all native platforms, nothing surprising here
fn buildNative(b: *Build, opts: Options) !void {
const exe = b.addExecutable(.{
.name = "pacman",
.root_module = opts.mod,
});
b.installArtifact(exe);
const run = b.addRunArtifact(exe);
b.step("run", "Run pacman").dependOn(&run.step);
}
// for web builds, the Zig code needs to be built into a library and linked with the Emscripten linker
fn buildWeb(b: *Build, opts: Options) !void {
const lib = b.addLibrary(.{
.name = "pacman",
.root_module = opts.mod,
});
// create a build step which invokes the Emscripten linker
const emsdk = opts.dep_sokol.builder.dependency("emsdk", .{});
const link_step = try sokol.emLinkStep(b, .{
.lib_main = lib,
.target = opts.mod.resolved_target.?,
.optimize = opts.mod.optimize.?,
.emsdk = emsdk,
.use_webgl2 = true,
.use_emmalloc = true,
.use_filesystem = false,
.shell_file_path = opts.dep_sokol.path("src/sokol/web/shell.html"),
});
// attach Emscripten linker output to default install step
b.getInstallStep().dependOn(&link_step.step);
// ...and a special run step to start the web build output via 'emrun'
const run = sokol.emRunStep(b, .{ .name = "pacman", .emsdk = emsdk });
run.step.dependOn(&link_step.step);
b.step("run", "Run pacman").dependOn(&run.step);
}
// compile shader via sokol-shdc
fn createShaderModule(b: *Build, dep_sokol: *Build.Dependency) !*Build.Module {
// ...
}
Shader compilation
sokol-zig comes with builtin sokol-shdc support and offers two ways to
integrate shader compilation into the build process:
Compile the shader source file into a Zig source file within the
project's source directory, which is then directly imported.
Compile the shader source file into a Zig module, with the module
source file existing only in the Zig cache.
For both cases, you need to import the sokol dependency in your
project's build.zig:
const sokol = @import("sokol");
...you'll also need the sokol and shdc dependencies:
Keep in mind that the implementation is already provided in the sokol_clib
static link library (e.g. don't try to build the Sokol implementations yourself
via the SOKOL_IMPL macro).
wasm32-emscripten caveats
the Zig stdlib only has limited support for the wasm32-emscripten
target, for instance using std.fs functions will most likely fail
to compile (the sokol-zig bindings might add more sokol headers
in the future to fill some of the gaps)
Dear ImGui support
The sokol-zig bindings come with sokol_imgui.h (exposed as the Zig package
sokol.imgui), but integration into a project's build.zig requires some extra
steps, mainly because I didn't want to add a
cimgui dependency to the sokol-zig package
(especially since cimgui uses git submodule which are not supported by the Zig
package manager).
The main steps to create Dear ImGui apps with sokol-zig are:
'bring your own cimgui'
tell the sokol dependency that it needs to include sokol_imgui.h into
the compiled C library:
No homepage URL was recorded for floooh/sokol-zig in TopGit's last sync. The README tab above frequently contains screenshots and demo links, or check the repository description on GitHub.
How active is development on floooh/sokol-zig?
The most recent commit recorded on floooh/sokol-zig was 13 days ago, based on the GitHub push timestamp. The repository has 94 forks — one of the better signals of community interest.
How many stars does floooh/sokol-zig have?
floooh/sokol-zig has 742 GitHub stars — refresh the page for the live number, or check github.com/floooh/sokol-zig. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
Is floooh/sokol-zig open source?
Yes — floooh/sokol-zig ships under the Zlib license, which makes its source code freely readable (and, depending on license terms, forkable and reusable). Source: github.com/floooh/sokol-zig.
What topics is floooh/sokol-zig associated with?
GitHub's repository topics for floooh/sokol-zig: "crossplatform", "sokol", "zig", "zig-package". TopGit's editorial category is open-source.
Where do I read more about floooh/sokol-zig?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/floooh/sokol-zig is the definitive source.
Read full README in the tab above.
Still deciding about sokol-zig?
One click hands the question to an AI along with this page — see what it says about sokol-zig.