AtlatestRepositorysigil-graphics
sigil-graphics / tree / examples / web-spritepackage.sgl
1
;;; web-sprite — sigil-graphics on the web (Milestone 2, Option A).2
;;;3
;;; Proves the graphics-on-web cond-expand seam end-to-end: a Sigil program using4
;;; (sigil graphics) renders in-browser through the sigil-wasm-gles3 raw-GLES35
;;; binding, driven by the Sigil VM tick loop — no Emscripten, no sokol_app.6
;;;7
;;; Per the M2 "Option A" decision, this example compiles sigil-graphics' own8
;;; cond-expanded C sources directly (with the web -D flags) and imports the9
;;; (sigil graphics) Sigil modules by path, depending on sigil-wasm-gles3 (NOT10
;;; the sigil-graphics package, so sigil-app — which cannot build for wasm — is11
;;; never pulled). The monorepo WASM packages are wired via from-path here for12
;;; local dev; production packaging (a first-class sigil-graphics web config) is13
;;; the filed Option-B follow-up.15
(define sigil-repo "codeberg:sigil/sigil")17
(package18
name: "web-sprite"19
version: "0.1.0"20
sigil: "^0.17"21
entry: '(web-sprite main)23
configs: (list24
(config25
name: 'web26
output-dir: "build/web"27
toolchain: 'zig28
target: "wasm32-wasi"29
debug?: #f30
optimize: 231
bundle?: #t32
features: '(web wasm graphics)))34
;; Canonical monorepo deps. Local dev wiring lives in dev-redirects.sgl35
;; (points sigil-repo at the graphics-on-web monorepo checkout); revert it +36
;; `sigil deps install` to restore. sigil-wasm-gles3 must be a released37
;; monorepo package for a from-git build without the redirect.38
dependencies: (list39
(from-git url: sigil-repo package: "sigil-lib" version: "^0.17")40
(from-git url: sigil-repo package: "sigil-stdlib" version: "^0.17")41
(from-git url: sigil-repo package: "sigil-wasm-runtime" version: "^0.17")42
(from-git url: sigil-repo package: "sigil-wasm-gles3" version: "^0.17"))44
;; This app ships its own native code: sigil-graphics' sokol natives compiled45
;; for wasm, plus src/c/app-register.c whose sigil_wasm_app_register hook calls46
;; sigil-graphics' module init. The WASM runtime's exported sigil_wasm_init47
;; calls that weak hook, so the whole native chain (register -> graphics init48
;; -> sokol -> gl* imports) is reachable and survives --gc-sections. The C49
;; objects link loose (no static library), and gl_shim.h is found via50
;; sigil-wasm-gles3's propagated c-include-dirs.51
tasks: (list52
(task53
name: 'build54
description: "Build the sigil-graphics web-sprite demo (wasm32-wasi, GLES3 over sigil-wasm-gles3)"55
steps: (list56
(compile-c-sources57
sources: '("src/c/app-register.c"58
"../../src/c/sokol-graphics.c" "../../src/c/stb_impl.c"59
"../../src/c/graphics.c" "../../src/c/image.c" "../../src/c/font.c")60
include-dirs: '("../../vendor/sokol" "../../vendor/stb")61
flags: (with-sigil-c-flags '("-std=c99" "-D_GNU_SOURCE"62
"-DSOKOL_NO_ENTRY" "-DSOKOL_GLES3"63
"-DSOKOL_EXTERNAL_GL_LOADER"64
"-Wno-unused-parameter" "-Wno-unused-function"65
"-Wno-sign-compare")))66
;; Compile the shared (sigil graphics) modules from the sigil-graphics67
;; source tree into library-name-relative bytecode paths.68
(compile-sigil-modules69
sources: "../../src/sigil/**/*.sgl"70
output-layout: 'module-name)71
;; Then the local app entry module.72
(compile-sigil-modules sources: "src/**/*.sgl")73
(link-web-application74
name: "web-sprite"75
html-mount-id: "status")))))