sigil-graphics: first-class web (wasm32-wasi) config
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.
package.sgl | 36 +++++++++++++++++++++++++++++++++---
src/c/sokol-graphics.c | 21 ++++++++++++++++++++-
2 files changed, 53 insertions(+), 4 deletions(-)package.sglmodified
static?: #t debug?: #f optimize: 2 features: '(release cross windows))) features: '(release cross windows)) ;; Web (wasm32-wasi): the first-class graphics-on-web build. sokol_gfx's ;; GLES3 backend over the sigil-wasm-gles3 raw-WebGL2 binding, no Emscripten, ;; no sokol_app (the app shell comes from the wasm bridge). sigil-app is ;; excluded from this config's deps (config-conditional gating); the sokol ;; backend is self-selected in sokol-graphics.c via __wasm__. (config name: 'web output-dir: "build/web" toolchain: 'zig target: "wasm32-wasi" debug?: #f optimize: 2 features: '(web wasm graphics))) dependencies: (list (from-git url: "codeberg:sigil/sigil-app" version: "^0.9.0")) ;; sigil-app provides the native sokol_app window/loop + slog_func. It is a ;; NATIVE-ONLY dep: its C (SOKOL_GLCORE + X11/Cocoa) cannot build for ;; wasm32-wasi, and on web sigil-graphics needs nothing from it (the app ;; shell + slog_func come from the wasm path). Config-conditional gating ;; excludes it from the `web` build. (from-git url: "codeberg:sigil/sigil-app" version: "^0.9.0" configs: '(dev release windows-amd64)) ;; Web-only: the raw-GLES3 WebGL2 binding. sigil-graphics' web C ;; (sokol-graphics.c under __wasm__) includes gl_shim.h — propagated here via ;; sigil-wasm-gles3's c-include-dirs — and its gl* calls resolve to the "gl" ;; import module the binding provides. This is what makes `sigil build ;; --config web` first-class (no compile-C-directly / dev-redirect hacks). (from-git url: "codeberg:sigil/sigil" package: "sigil-wasm-gles3" version: "^0.17" configs: '(web))) libraries: (list (library sources: '("src/c/sokol-graphics.c" "src/c/stb_impl.c" "src/c/graphics.c" "src/c/image.c" "src/c/font.c") include-dirs: '("vendor/sokol" "vendor/stb") ;; No -DSOKOL_GLCORE/-DSOKOL_GLES3 here: sokol-graphics.c self-selects ;; the backend from __wasm__, so this one build task serves both the ;; native configs and the wasm `web` config. flags: (with-sigil-c-flags '("-std=c99" "-D_GNU_SOURCE" "-DSOKOL_NO_ENTRY" "-DSOKOL_GLCORE" "-DSOKOL_NO_ENTRY" "-Wno-unused-parameter" "-Wno-unused-function" "-Wno-sign-compare"))) (create-static-library name: "sigil-graphics") (compile-sigil-modules sources: "src/**/*.sgl"src/c/sokol-graphics.cmodified
#if defined(__wasm__)/* Web (wasm32-wasi): sokol_gfx's GLES3 backend, with GL entry points supplied * as WASM imports (SOKOL_EXTERNAL_GL_LOADER) rather than a native loader. These * are self-configured here from the wasm target so a first-class `sigil build * --config web` needs no -D flags; the #ifndef guards keep the older examples * that still pass -DSOKOL_GLES3/-DSOKOL_EXTERNAL_GL_LOADER conflict-free. */#ifndef SOKOL_GLES3#define SOKOL_GLES3#endif#ifndef SOKOL_EXTERNAL_GL_LOADER#define SOKOL_EXTERNAL_GL_LOADER#endif/* Web: bind every gl* sokol calls as a WASM import in the "gl" module. Must be * included before sokol_gfx.h so GL types/constants/prototypes are visible. */#include "gl_shim.h"#else/* Native: SOKOL_GLCORE is defined via compiler flags. *//* Native: desktop GL core backend. Self-configured here (was previously set via * a -DSOKOL_GLCORE compiler flag; moved into the source so one build task serves * both native and web). #ifndef-guarded so a build/example still passing * -DSOKOL_GLCORE is conflict-free. Behaviour is identical: SOKOL_GLCORE ends up * defined either way. */#ifndef SOKOL_GLCORE#define SOKOL_GLCORE#endif/* Include sokol_app declarations WITHOUT implementation (implemented in sigil-app) */#include "sokol_app.h"