AtlatestRepositorysigil-graphics
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 using
4;;; (sigil graphics) renders in-browser through the sigil-wasm-gles3 raw-GLES3
5;;; 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' own
8;;; cond-expanded C sources directly (with the web -D flags) and imports the
9;;; (sigil graphics) Sigil modules by path, depending on sigil-wasm-gles3 (NOT
10;;; the sigil-graphics package, so sigil-app — which cannot build for wasm — is
11;;; never pulled). The monorepo WASM packages are wired via from-path here for
12;;; local dev; production packaging (a first-class sigil-graphics web config) is
13;;; the filed Option-B follow-up.
15(define sigil-repo "codeberg:sigil/sigil")
17(package
18 name: "web-sprite"
19 version: "0.1.0"
20 sigil: "^0.17"
21 entry: '(web-sprite main)
23 configs: (list
24 (config
25 name: 'web
26 output-dir: "build/web"
27 toolchain: 'zig
28 target: "wasm32-wasi"
29 debug?: #f
30 optimize: 2
31 bundle?: #t
32 features: '(web wasm graphics)))
34 ;; Canonical monorepo deps. Local dev wiring lives in dev-redirects.sgl
35 ;; (points sigil-repo at the graphics-on-web monorepo checkout); revert it +
36 ;; `sigil deps install` to restore. sigil-wasm-gles3 must be a released
37 ;; monorepo package for a from-git build without the redirect.
38 dependencies: (list
39 (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 compiled
45 ;; for wasm, plus src/c/app-register.c whose sigil_wasm_app_register hook calls
46 ;; sigil-graphics' module init. The WASM runtime's exported sigil_wasm_init
47 ;; calls that weak hook, so the whole native chain (register -> graphics init
48 ;; -> sokol -> gl* imports) is reachable and survives --gc-sections. The C
49 ;; objects link loose (no static library), and gl_shim.h is found via
50 ;; sigil-wasm-gles3's propagated c-include-dirs.
51 tasks: (list
52 (task
53 name: 'build
54 description: "Build the sigil-graphics web-sprite demo (wasm32-wasi, GLES3 over sigil-wasm-gles3)"
55 steps: (list
56 (compile-c-sources
57 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-graphics
67 ;; source tree into library-name-relative bytecode paths.
68 (compile-sigil-modules
69 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-application
74 name: "web-sprite"
75 html-mount-id: "status")))))