https://github.com/floooh/sokol
It doesn't support vulkan though, but if that's important to you you're probably much better off just using vulkan directly since it's supported on all the major platforms.
https://github.com/floooh/sokol
...inspired by:
https://github.com/nothings/stb
(here's how the sokol headers are integrated into a Zig project, note that there is only a build.zig which builds everything: https://github.com/floooh/kc85.zig)
But it's not so much about build systems, but requiring a separate compiler toolchain to build any C++ or ObjC dependencies (Rust needs this, Zig currently does not - unless that controversial proposal is implemented).
(also even complex C++ libraries can be wrapped in a build.zig, so you don't require a separate build system like cmake for the C++ dependencies)
https://wiki.libsdl.org/SDL2/README/emscripten
My own cross-platform headers too:
https://github.com/floooh/sokol
...there are also auto-generated Zig bindings btw ;)
https://floooh.github.io/tiny8bit/
Also see: https://github.com/floooh/sokol and https://floooh.github.io/sokol-html5/index.html.
(e.g. for me it's a way to easily get my C/C++ cross-platform hobby stuff to people without requiring them having to jump through the hoops of downloading and running an untrusted native executable or messing around with C/C++ toolchains and build systems to build the stuff locally).
PS: WASM in the browser is also a good watchdog which punishes you heavily if your code gets to bloated ;)
> Why? ...
...not really, these are business reasons, plain and simple.
The problem with games on Linux is that the market is too small, the technical problems could be overcome if there would be a will and enough money thrown at it (see Steam Deck and Proton where this approach works pretty well) - for instance the technical problems for games on Android are arguably worse, yet the market is big enough that game developers have enough incentives to deal with those problems.
Also WebGPU is not released yet, so looking at caniuse is not really useful.
As for the last point: the CPU's ISA is the least of the problems. Most applications are no longer coded by hand in assembly.
Apart from being slightly faster, I see no difference between coding on an M1 Mac versus an Intel Mac or even a Windows or Linux machine (exactly because I hardly code in assembly these days).
My (same) code runs on all of those, plus the web, iOS and Android (granted I wrote my own set of wrapper libs to make this easy: https://github.com/floooh/sokol - but it's not like that's the only slim solution for cross-platform code).
I've personally used Sokol for a number of projects and it has been great. You get something much leaner and meaner compared to the Emscripten port of SDL, which otherwise seems to be the "default" when people do these things.
Can't provide source though on that one, as it's a propietary engine. Recently I've enjoyed reading the source code to Sokol, lot's of really good decisions there and I love the minimal C -style structure:
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 type 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
https://github.com/floooh/sokol
...live samples:
https://github.com/floooh/sokol
It has DX11, Metal, and OpenGL backends (with optional shader compilation tool from GLSL to each target), which is probably all you need to get cross-platform support for all desktop and mobile targets. Rewrote my OpenGL code to this, was a pretty nice experience. The subset of graphical features it exposes seems more than good enough for simple 2D games (probably enough for simple 3D ones also). Can't say more than that though, since I haven't seen a shipped 3D game on Steam using it yet.
Though what we ultimately need for the future is a Metal-like API that runs on all platforms (since from what I've heard from other graphics developers Metal's API design is quite nice and finds the right balance between low-level control and high-level usability). The experimental SDL_gpu development (https://gist.github.com/icculus/f731224bef3906e4c5e8cbed6f98...) strives to achieve this, although it's still in the early stages...
- Sokol (sokol_gfx in particular): https://github.com/floooh/sokol
- wgpu (see wgpu-native for the C API): https://github.com/gfx-rs/wgpu
It kind of seems like graphics abstractions for modern hardware are getting pretty "figured out". There are wrappers that work for most DirectX/Metal/OpenGL applications so they can run just about anywhere, and new 2D/3D applications have a lot of accessible/open-source options to build on top of. Projects like Mesa's Zink will centralize the burden of maintaining legacy APIs away from hardware manufacturers. Valve's Proton is making waves. WebGPU is on the way.
The future looks bright.
It is an obstacle (at least a massive annoyance) for library authors (like this: https://github.com/floooh/sokol). Those libraries can be used for extremely simple and small WASM snippets embedded in blog posts (like here: https://floooh.github.io/2019/01/05/wasm-embedding.html), or in "proper" games hosted through "proper" hosting services which allow to set the response headers.
Right now the choice is to either support WASM threading, but tell library users that the library will most likely not work on the hosting solution of their choice, or not support WASM threading and work everywhere. At least to me it's clear that "works everywhere" is better than "it's complicated", so I'll ignore WASM threading until the problem is solved somehow (either most hosting services turn on those response headers, or there's another way to enable threading without requiring control over the web server configuration).
The examples somehow need to connect to the underlying operating system, and that's why they depend on GLFW as intermediate layer, but this could also be SDL, or - shameless plug - the sokol headers (https://github.com/floooh/sokol), or (more commonly) a game engine like Unity, Unreal Engine, or your own code.
https://github.com/floooh/sokol
Check out these samples and have a look at the size in the browser devtools which are IMHO quite sensible:
https://floooh.github.io/sokol-html5/
https://floooh.github.io/tiny8bit/
PS: really great writeup btw :)
We use Sokol, an amazing wrapper library, and it only supports the big 3.
https://github.com/floooh/sokol
...and here's a minimal standalone starter project for writing Dear ImGui apps in C I just created a couple of days ago: