AtlatestRepositorysigil-audio

sigil-audio / treepackage.sgl

1;;; sigil-audio - Audio playback for Sigil
2;;;
3;;; Provides audio playback capabilities via sokol_audio.
4;;; Sound effects are loaded into memory, music is streamed via stb_vorbis.
5;;; OGG Vorbis encoding ships in-tree via vendored libogg + libvorbis.
6
7;; skip-on-wasm wraps a build step so it is a no-op on wasm/wasi targets.
8;; The native audio C (sokol_audio, vendored libogg/libvorbis) has no
9;; wasm32-wasi backend; on wasm the (sigil audio sink) facade delegates to
10;; the WebAudio bridge, so none of this C is needed. Only compile-sigil-modules
11;; runs on wasm, producing the facade + module bytecode. Native builds are
12;; unaffected (the guard is false), so behavior there is byte-identical.
13;; run-steps threads each step's return value as the ctx for the next step
14;; (fold-left over steps), so a skipped step must return ctx UNCHANGED.
15(let ((skip-on-wasm
16 (lambda (step)
17 (lambda (ctx)
18 (if (memq (target-os ctx) '(wasm wasi))
19 ctx
20 (step ctx))))))
21 (package
22 name: "sigil-audio"
23 version: "0.12.0"
24 sigil: "^0.17"
25 description: "Audio playback and streaming for Sigil"
26 url: "https://codeberg.org/sigil/sigil-audio"
27 license: "BSD-3-Clause"
28 authors: (list "David Wilson <[email protected]>")
30 configs: (list
31 (config
32 name: 'dev
33 output-dir: "build/dev"
34 debug?: #t
35 optimize: 0)
36 (config
37 name: 'release
38 output-dir: "build/release"
39 debug?: #f
40 optimize: 2)
42 ;; Windows x86_64 (MinGW via zig) — built so downstream consumers
43 ;; like cinder-cantata can produce Windows binaries from Linux.
44 ;; Mirrors the windows-amd64 config in the main sigil package.
45 (config
46 name: 'windows-amd64
47 output-dir: "build/windows-amd64"
48 toolchain: 'zig
49 target: "x86_64-windows-gnu"
50 backend: 'native
51 static?: #t
52 debug?: #f
53 optimize: 2
54 features: '(release cross windows)))
56 dependencies: (list
57 (from-git url: "codeberg:sigil/sigil" package: "sigil-stdlib" version: "^0.17"))
59 libraries: (list
60 (library
61 name: 'sigil-audio
62 c-sources: '("src/c/sokol-audio.c" "src/c/audio.c" "src/c/audio-stream.c" "src/c/ogg-encode.c")
63 ;; vendor/ogg/include + vendor/vorbis/include expose the public
64 ;; ogg/vorbis headers consumed by ogg-encode.c. vendor/vorbis/lib
65 ;; is needed because libvorbis internal .c files include their
66 ;; siblings by bare filename (e.g. #include "codebook.h").
67 c-include-dirs: '("vendor/sokol" "vendor/stb"
68 "vendor/ogg/include"
69 "vendor/vorbis/include"
70 "vendor/vorbis/lib")
71 native-init: "sigil__init_sigil_audio_module"
72 ;; Platform-specific linker flags for sokol_audio's audio backend.
73 ;; OGG Vorbis is now vendored — no more -lvorbis/-lvorbisenc/-logg.
74 ;;
75 ;; Procedural (lambda ctx) form so cross-compile configs evaluate
76 ;; the right branch at link time. (case (host-os) ...) was evaluated
77 ;; once at package-load on the host, leaking Linux flags into
78 ;; cross builds.
79 link-flags: (lambda (ctx)
80 (case (target-os ctx)
81 ((linux) '("-lasound"))
82 ((darwin) '("-framework" "AudioToolbox"))
83 ;; sokol_audio's WASAPI backend uses CoCreateInstance
84 ;; / CoInitializeEx (ole32). winmm + ksuser are
85 ;; carried for completeness against future sokol
86 ;; revisions that touch waveOut / kernel-streaming.
87 ((windows) '("-lole32" "-lwinmm" "-lksuser"))
88 (else '())))))
90 tasks: (list
91 (task
92 name: 'build
93 description: "Build sigil-audio"
94 steps: (list
95 ;; Compile vendored libogg with relaxed warning flags. Upstream
96 ;; sources are byte-identical to the 1.3.6 tarball (see
97 ;; vendor/ogg/README.md); keeping warnings off avoids polluting
98 ;; sigil-audio's own strict-flag set when upstream's style
99 ;; trips -Wparentheses / -Wunused-* / -Wsign-compare.
100 ;;
101 ;; The C steps are wrapped in skip-on-wasm: none of this native audio
102 ;; C cross-compiles to wasm32-wasi, and the (sigil audio sink) facade's
103 ;; wasm arm uses the WebAudio bridge instead. compile-sigil-modules is
104 ;; NOT wrapped: the facade + module bytecode must still build on wasm.
105 (skip-on-wasm (compile-c-sources
106 sources: '("vendor/ogg/src/bitwise.c"
107 "vendor/ogg/src/framing.c")
108 include-dirs: '("vendor/ogg/include")
109 flags: '("-std=c99"
110 "-Wno-parentheses"
111 "-Wno-unused-function"
112 "-Wno-unused-but-set-variable"
113 "-Wno-sign-compare"
114 "-Wno-strict-aliasing")))
116 ;; Compile vendored libvorbis (full library + encoder + file
117 ;; I/O). Upstream sources are byte-identical to the 1.3.7
118 ;; tarball (see vendor/vorbis/README.md). Same relaxed-warning
119 ;; rationale as libogg above.
120 (skip-on-wasm (compile-c-sources
121 sources: '("vendor/vorbis/lib/analysis.c"
122 "vendor/vorbis/lib/bitrate.c"
123 "vendor/vorbis/lib/block.c"
124 "vendor/vorbis/lib/codebook.c"
125 "vendor/vorbis/lib/envelope.c"
126 "vendor/vorbis/lib/floor0.c"
127 "vendor/vorbis/lib/floor1.c"
128 "vendor/vorbis/lib/info.c"
129 "vendor/vorbis/lib/lookup.c"
130 "vendor/vorbis/lib/lpc.c"
131 "vendor/vorbis/lib/lsp.c"
132 "vendor/vorbis/lib/mapping0.c"
133 "vendor/vorbis/lib/mdct.c"
134 "vendor/vorbis/lib/psy.c"
135 "vendor/vorbis/lib/registry.c"
136 "vendor/vorbis/lib/res0.c"
137 "vendor/vorbis/lib/sharedbook.c"
138 "vendor/vorbis/lib/smallft.c"
139 "vendor/vorbis/lib/synthesis.c"
140 "vendor/vorbis/lib/vorbisenc.c"
141 "vendor/vorbis/lib/vorbisfile.c"
142 "vendor/vorbis/lib/window.c")
143 include-dirs: '("vendor/ogg/include"
144 "vendor/vorbis/include"
145 "vendor/vorbis/lib")
146 ;; vendor/vorbis/sigil_alloca_shim.h is force-included so
147 ;; HAVE_ALLOCA_H gets defined on Linux/macOS (where vorbis
148 ;; needs it for the alloca prototype under -std=c99) but
149 ;; NOT on Windows/MinGW (where <alloca.h> is missing and
150 ;; vorbis's _WIN32 branch handles alloca via <malloc.h>).
151 ;;
152 ;; Flags are procedural so the -include path is resolved
153 ;; against this package's own directory. Literal relative
154 ;; paths would break downstream consumers whose cwd differs
155 ;; from the package dir at cc time.
156 flags: (lambda (ctx)
157 (list "-std=c99"
158 "-include"
159 (path-join (context-package-dir ctx)
160 "vendor/vorbis/sigil_alloca_shim.h")
161 "-Wno-parentheses"
162 "-Wno-unused-function"
163 "-Wno-unused-but-set-variable"
164 "-Wno-sign-compare"
165 "-Wno-strict-aliasing"))))
167 ;; sigil-audio's own C sources.
168 (skip-on-wasm (compile-c-sources
169 sources: '("src/c/sokol-audio.c" "src/c/audio.c" "src/c/audio-stream.c" "src/c/ogg-encode.c")
170 include-dirs: '("vendor/sokol" "vendor/stb"
171 "vendor/ogg/include"
172 "vendor/vorbis/include")
173 flags: (with-sigil-c-flags '("-std=c11" "-D_GNU_SOURCE"
174 "-Wno-unused-parameter" "-Wno-unused-function" "-Wno-sign-compare"))))
175 (skip-on-wasm (create-static-library name: "sigil-audio"))
176 (compile-sigil-modules sources: "src/**/*.sgl"
177 output-dir: (config-output-subdir "lib")))))))