AtlatestRepositorysigil-audio

sigil-audio / treepackage.sgl

1;;; sigil-audio - Audio playback for Sigil
2;;;
3;;; Provides audio playback through miniaudio (vendored; the device layer
4;;; only, every backend loaded at run time).
5;;; Sound effects are loaded into memory, music is streamed via stb_vorbis.
6;;; OGG Vorbis encoding ships in-tree via vendored libogg + libvorbis.
7
8;; skip-on-wasm wraps a build step so it is a no-op on wasm/wasi targets.
9;; The native audio C (miniaudio, vendored libogg/libvorbis) has no
10;; wasm32-wasi backend; on wasm the (sigil audio sink) facade delegates to
11;; the WebAudio bridge, so none of this C is needed. Only compile-sigil-modules
12;; runs on wasm, producing the facade + module bytecode. Native builds are
13;; unaffected (the guard is false), so behavior there is byte-identical.
14;; run-steps threads each step's return value as the ctx for the next step
15;; (fold-left over steps), so a skipped step must return ctx UNCHANGED.
16(let ((skip-on-wasm
17 (lambda (step)
18 (lambda (ctx)
19 (if (memq (target-os ctx) '(wasm wasi))
20 ctx
21 (step ctx))))))
22 (package
23 name: "sigil-audio"
24 version: "0.12.2"
25 sigil: "0.20"
26 description: "Audio playback and streaming for Sigil"
27 url: "https://codeberg.org/sigil/sigil-audio"
28 license: "BSD-3-Clause"
29 authors: (list "David Wilson <[email protected]>")
31 configs: (list
32 (config
33 name: 'dev
34 output-dir: "build/dev"
35 debug?: #t
36 optimize: 0)
37 (config
38 name: 'release
39 output-dir: "build/release"
40 debug?: #f
41 optimize: 2)
43 ;; Windows x86_64 (MinGW via zig) — built so downstream consumers
44 ;; like cinder-cantata can produce Windows binaries from Linux.
45 ;; Mirrors the windows-amd64 config in the main sigil package.
46 (config
47 name: 'windows-amd64
48 output-dir: "build/windows-amd64"
49 toolchain: 'zig
50 target: "x86_64-windows-gnu"
51 backend: 'native
52 static?: #t
53 debug?: #f
54 optimize: 2
55 features: '(release cross windows)))
57 dependencies: (list
58 (from-git url: "codeberg:sigil/sigil" package: "sigil-stdlib" version: ">=0.20"))
60 libraries: (list
61 (library
62 name: 'sigil-audio
63 ;; sigil-build reads this list only as a "has native code" test and
64 ;; for the include dirs; the build task below compiles the real,
65 ;; target-dependent list (dl-search.c on Linux only). Keep it to
66 ;; files every target compiles.
67 c-sources: '("src/c/miniaudio-impl.c" "src/c/audio.c" "src/c/audio-stream.c" "src/c/ogg-encode.c")
68 ;; vendor/ogg/include + vendor/vorbis/include expose the public
69 ;; ogg/vorbis headers consumed by ogg-encode.c. vendor/vorbis/lib
70 ;; is needed because libvorbis internal .c files include their
71 ;; siblings by bare filename (e.g. #include "codebook.h").
72 c-include-dirs: '("vendor/stb"
73 "vendor/ogg/include"
74 "vendor/vorbis/include"
75 "vendor/vorbis/lib")
76 native-init: "sigil__init_sigil_audio_module"
77 ;; Platform linker flags: none. miniaudio loads every backend at
78 ;; run time (libpulse.so.0, libasound.so.2, libjack.so.0 on Linux;
79 ;; ole32/mmdevapi/avrt/winmm/dsound DLLs on Windows; the CoreAudio
80 ;; frameworks by absolute path on macOS), so -lasound, AudioToolbox
81 ;; and ole32/winmm/ksuser are gone. pthread and dl are libc's on
82 ;; glibc 2.34+ (sigil-build adds -lpthread -ldl on Linux anyway).
83 ;;
84 ;; Procedural (lambda ctx) form kept so a target can add a flag
85 ;; later without going back to the host-evaluated (case (host-os)).
86 link-flags: (lambda (ctx)
87 (case (target-os ctx)
88 ((linux) '())
89 ((darwin) '())
90 ((windows) '())
91 (else '())))))
93 dev-dependencies: (list
94 (from-git url: "codeberg:sigil/sigil" package: "sigil-test" version: ">=0.20")
95 (from-git url: "codeberg:sigil/sigil" package: "sigil-test-runner" version: ">=0.20"))
97 tasks: (list
98 (task
99 name: 'build
100 description: "Build sigil-audio"
101 steps: (list
102 ;; Compile vendored libogg with relaxed warning flags. Upstream
103 ;; sources are byte-identical to the 1.3.6 tarball (see
104 ;; vendor/ogg/README.md); keeping warnings off avoids polluting
105 ;; sigil-audio's own strict-flag set when upstream's style
106 ;; trips -Wparentheses / -Wunused-* / -Wsign-compare.
107 ;;
108 ;; The C steps are wrapped in skip-on-wasm: none of this native audio
109 ;; C cross-compiles to wasm32-wasi, and the (sigil audio sink) facade's
110 ;; wasm arm uses the WebAudio bridge instead. compile-sigil-modules is
111 ;; NOT wrapped: the facade + module bytecode must still build on wasm.
112 (skip-on-wasm (compile-c-sources
113 sources: '("vendor/ogg/src/bitwise.c"
114 "vendor/ogg/src/framing.c")
115 include-dirs: '("vendor/ogg/include")
116 flags: '("-std=c99"
117 "-Wno-parentheses"
118 "-Wno-unused-function"
119 "-Wno-unused-but-set-variable"
120 "-Wno-sign-compare"
121 "-Wno-strict-aliasing"
122 ;; libvorbis shifts negative values (psy.c:319,
123 ;; ((lo-1)<<16) with lo==0). That is UB in C and the
124 ;; toolchain traps it at RUNTIME, so the suite died in
125 ;; vorbis_analysis rather than failing a test. Upstream
126 ;; code we vendor unmodified; scoped to this step only,
127 ;; never to sigil-audio own sources.
128 "-fno-sanitize=undefined")))
130 ;; Compile vendored libvorbis (full library + encoder + file
131 ;; I/O). Upstream sources are byte-identical to the 1.3.7
132 ;; tarball (see vendor/vorbis/README.md). Same relaxed-warning
133 ;; rationale as libogg above.
134 (skip-on-wasm (compile-c-sources
135 sources: '("vendor/vorbis/lib/analysis.c"
136 "vendor/vorbis/lib/bitrate.c"
137 "vendor/vorbis/lib/block.c"
138 "vendor/vorbis/lib/codebook.c"
139 "vendor/vorbis/lib/envelope.c"
140 "vendor/vorbis/lib/floor0.c"
141 "vendor/vorbis/lib/floor1.c"
142 "vendor/vorbis/lib/info.c"
143 "vendor/vorbis/lib/lookup.c"
144 "vendor/vorbis/lib/lpc.c"
145 "vendor/vorbis/lib/lsp.c"
146 "vendor/vorbis/lib/mapping0.c"
147 "vendor/vorbis/lib/mdct.c"
148 "vendor/vorbis/lib/psy.c"
149 "vendor/vorbis/lib/registry.c"
150 "vendor/vorbis/lib/res0.c"
151 "vendor/vorbis/lib/sharedbook.c"
152 "vendor/vorbis/lib/smallft.c"
153 "vendor/vorbis/lib/synthesis.c"
154 "vendor/vorbis/lib/vorbisenc.c"
155 "vendor/vorbis/lib/vorbisfile.c"
156 "vendor/vorbis/lib/window.c")
157 include-dirs: '("vendor/ogg/include"
158 "vendor/vorbis/include"
159 "vendor/vorbis/lib")
160 ;; vendor/vorbis/sigil_alloca_shim.h is force-included so
161 ;; HAVE_ALLOCA_H gets defined on Linux/macOS (where vorbis
162 ;; needs it for the alloca prototype under -std=c99) but
163 ;; NOT on Windows/MinGW (where <alloca.h> is missing and
164 ;; vorbis's _WIN32 branch handles alloca via <malloc.h>).
165 ;;
166 ;; Flags are procedural so the -include path is resolved
167 ;; against this package's own directory. Literal relative
168 ;; paths would break downstream consumers whose cwd differs
169 ;; from the package dir at cc time.
170 flags: (lambda (ctx)
171 (list "-std=c99"
172 "-include"
173 (path-join (context-package-dir ctx)
174 "vendor/vorbis/sigil_alloca_shim.h")
175 "-Wno-parentheses"
176 "-Wno-unused-function"
177 "-Wno-unused-but-set-variable"
178 "-Wno-sign-compare"
179 "-Wno-strict-aliasing"
180 "-fno-sanitize=undefined"))))
182 ;; miniaudio: the playback device, compiled once here with the
183 ;; device layer only (the MA_NO_* cuts are in the file). Its
184 ;; runtime dlopen of libpulse / libasound / libjack goes through
185 ;; the resolver in dl-search.c (shared with sigil-desktop, which
186 ;; is the copy that may define dlopen itself; this one exposes the
187 ;; named sigil_audio_dl_open that miniaudio-impl.c redirects to).
188 ;; dl-search.c is Linux-only (Guix and Nix profiles); the other
189 ;; targets compile miniaudio alone. Warnings relaxed for the
190 ;; vendored header only.
191 (skip-on-wasm
192 (lambda (ctx)
193 ((compile-c-sources
194 sources: (if (eq? (target-os ctx) 'linux)
195 '("src/c/miniaudio-impl.c" "src/c/dl-search.c")
196 '("src/c/miniaudio-impl.c"))
197 include-dirs: '("vendor/miniaudio" "src/c")
198 flags: '("-std=c11" "-D_GNU_SOURCE"
199 "-DSIGIL_DL_SEARCH_OPEN=sigil_audio_dl_open"
200 "-DSIGIL_DL_SEARCH_SUMMARY=sigil_audio_dlopen_search_summary"
201 "-DSIGIL_DL_SEARCH_TAG=\"sigil-audio\""
202 "-DSIGIL_DL_SEARCH_VERBOSE_ENV=\"SIGIL_AUDIO_VERBOSE\""
203 "-DSIGIL_DL_SEARCH_INTERPOSE=0"
204 "-Wno-unused-parameter" "-Wno-unused-function"
205 "-Wno-unused-variable" "-Wno-unused-but-set-variable"
206 "-Wno-sign-compare"))
207 ctx)))
209 ;; sigil-audio's own C sources.
210 (skip-on-wasm (compile-c-sources
211 sources: '("src/c/audio.c" "src/c/audio-stream.c" "src/c/ogg-encode.c")
212 include-dirs: '("vendor/stb"
213 "vendor/ogg/include"
214 "vendor/vorbis/include")
215 flags: (with-sigil-c-flags '("-std=c11" "-D_GNU_SOURCE"
216 "-Wno-unused-parameter" "-Wno-unused-function" "-Wno-sign-compare"))))
217 (skip-on-wasm (create-static-library name: "sigil-audio"))
218 (compile-sigil-modules sources: "src/**/*.sgl"
219 output-dir: (config-output-subdir "lib")))))))