Commitca34ff6cRecorded12 Jul 2026Repositorysigil-graphics

sigil-graphics: first-class web (wasm32-wasi) config

Message

Adds a web config (zig / wasm32-wasi) so sigil build --config web builds sigil-graphics against sokolgfx's GLES3 backend over the sigil-wasm-gles3 raw-WebGL2 binding — no Emscripten, no sokolapp.

- sigil-app is now a native-only dependency (configs: '(dev release windows-amd64)); its SOKOLGLCORE/X11 sources can't build for wasm and the web path needs nothing from it. Config-conditional dep gating excludes it from the web build. - Adds a web-only dep on sigil-wasm-gles3 (configs: '(web)) so glshim.h propagates (its c-include-dirs) and sokol's gl* calls bind to the "gl" import module the binding provides. - sokol-graphics.c self-selects the sokol backend from wasm (SOKOLGLES3+SOKOLEXTERNALGLLOADER on web, SOKOLGLCORE on native), #ifndef-guarded so builds/examples still passing -D flags don't conflict. The build task drops the hard-coded -DSOKOLGLCORE so one task serves both native and web; native behaviour is identical (SOKOL_GLCORE ends up defined either way; sokol keys on defined-ness).

Verified: sigil build --config web produces libsigil-graphics.a as a wasm archive (5 wasm objects, 0 ELF) with sigil-app fully excluded.

Changed
 package.sgl            | 36 +++++++++++++++++++++++++++++++++---
 src/c/sokol-graphics.c | 21 ++++++++++++++++++++-
 2 files changed, 53 insertions(+), 4 deletions(-)
Diff
package.sglmodified
@@ -35,10 +35,37 @@
35
static?: #t
36
debug?: #f
37
optimize: 2
38
features: '(release cross windows)))
+38
features: '(release cross windows))
+39
+40
;; Web (wasm32-wasi): the first-class graphics-on-web build. sokol_gfx's
+41
;; GLES3 backend over the sigil-wasm-gles3 raw-WebGL2 binding, no Emscripten,
+42
;; no sokol_app (the app shell comes from the wasm bridge). sigil-app is
+43
;; excluded from this config's deps (config-conditional gating); the sokol
+44
;; backend is self-selected in sokol-graphics.c via __wasm__.
+45
(config
+46
name: 'web
+47
output-dir: "build/web"
+48
toolchain: 'zig
+49
target: "wasm32-wasi"
+50
debug?: #f
+51
optimize: 2
+52
features: '(web wasm graphics)))
53
54
dependencies: (list
41
(from-git url: "codeberg:sigil/sigil-app" version: "^0.9.0"))
+55
;; sigil-app provides the native sokol_app window/loop + slog_func. It is a
+56
;; NATIVE-ONLY dep: its C (SOKOL_GLCORE + X11/Cocoa) cannot build for
+57
;; wasm32-wasi, and on web sigil-graphics needs nothing from it (the app
+58
;; shell + slog_func come from the wasm path). Config-conditional gating
+59
;; excludes it from the `web` build.
+60
(from-git url: "codeberg:sigil/sigil-app" version: "^0.9.0"
+61
configs: '(dev release windows-amd64))
+62
;; Web-only: the raw-GLES3 WebGL2 binding. sigil-graphics' web C
+63
;; (sokol-graphics.c under __wasm__) includes gl_shim.h — propagated here via
+64
;; sigil-wasm-gles3's c-include-dirs — and its gl* calls resolve to the "gl"
+65
;; import module the binding provides. This is what makes `sigil build
+66
;; --config web` first-class (no compile-C-directly / dev-redirect hacks).
+67
(from-git url: "codeberg:sigil/sigil" package: "sigil-wasm-gles3" version: "^0.17"
+68
configs: '(web)))
69
70
libraries: (list
71
(library
@@ -72,8 +99,11 @@
99
sources: '("src/c/sokol-graphics.c" "src/c/stb_impl.c"
100
"src/c/graphics.c" "src/c/image.c" "src/c/font.c")
101
include-dirs: '("vendor/sokol" "vendor/stb")
+102
;; No -DSOKOL_GLCORE/-DSOKOL_GLES3 here: sokol-graphics.c self-selects
+103
;; the backend from __wasm__, so this one build task serves both the
+104
;; native configs and the wasm `web` config.
105
flags: (with-sigil-c-flags '("-std=c99" "-D_GNU_SOURCE"
76
"-DSOKOL_NO_ENTRY" "-DSOKOL_GLCORE"
+106
"-DSOKOL_NO_ENTRY"
107
"-Wno-unused-parameter" "-Wno-unused-function" "-Wno-sign-compare")))
108
(create-static-library name: "sigil-graphics")
109
(compile-sigil-modules sources: "src/**/*.sgl"
src/c/sokol-graphics.cmodified
@@ -24,6 +24,18 @@
24
25
#if defined(__wasm__)
26
+27
/* Web (wasm32-wasi): sokol_gfx's GLES3 backend, with GL entry points supplied
+28
* as WASM imports (SOKOL_EXTERNAL_GL_LOADER) rather than a native loader. These
+29
* are self-configured here from the wasm target so a first-class `sigil build
+30
* --config web` needs no -D flags; the #ifndef guards keep the older examples
+31
* that still pass -DSOKOL_GLES3/-DSOKOL_EXTERNAL_GL_LOADER conflict-free. */
+32
#ifndef SOKOL_GLES3
+33
#define SOKOL_GLES3
+34
#endif
+35
#ifndef SOKOL_EXTERNAL_GL_LOADER
+36
#define SOKOL_EXTERNAL_GL_LOADER
+37
#endif
+38
39
/* Web: bind every gl* sokol calls as a WASM import in the "gl" module. Must be
40
* included before sokol_gfx.h so GL types/constants/prototypes are visible. */
41
#include "gl_shim.h"
@@ -52,7 +64,14 @@ void slog_func(const char* tag, uint32_t log_level, uint32_t log_item_id,
64
65
#else
66
55
/* Native: SOKOL_GLCORE is defined via compiler flags. */
+67
/* Native: desktop GL core backend. Self-configured here (was previously set via
+68
* a -DSOKOL_GLCORE compiler flag; moved into the source so one build task serves
+69
* both native and web). #ifndef-guarded so a build/example still passing
+70
* -DSOKOL_GLCORE is conflict-free. Behaviour is identical: SOKOL_GLCORE ends up
+71
* defined either way. */
+72
#ifndef SOKOL_GLCORE
+73
#define SOKOL_GLCORE
+74
#endif
75
76
/* Include sokol_app declarations WITHOUT implementation (implemented in sigil-app) */
77
#include "sokol_app.h"