AtlatestRepositorysigil-audio
sigil-audio / treepackage.sgl
1
;;; sigil-audio - Audio playback for Sigil2
;;;3
;;; Provides audio playback through miniaudio (vendored; the device layer4
;;; 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.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 no10
;; wasm32-wasi backend; on wasm the (sigil audio sink) facade delegates to11
;; the WebAudio bridge, so none of this C is needed. Only compile-sigil-modules12
;; runs on wasm, producing the facade + module bytecode. Native builds are13
;; 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 step15
;; (fold-left over steps), so a skipped step must return ctx UNCHANGED.16
(let ((skip-on-wasm17
(lambda (step)18
(lambda (ctx)19
(if (memq (target-os ctx) '(wasm wasi))20
ctx21
(step ctx))))))22
(package23
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: (list32
(config33
name: 'dev34
output-dir: "build/dev"35
debug?: #t36
optimize: 0)37
(config38
name: 'release39
output-dir: "build/release"40
debug?: #f41
optimize: 2)43
;; Windows x86_64 (MinGW via zig) — built so downstream consumers44
;; like cinder-cantata can produce Windows binaries from Linux.45
;; Mirrors the windows-amd64 config in the main sigil package.46
(config47
name: 'windows-amd6448
output-dir: "build/windows-amd64"49
toolchain: 'zig50
target: "x86_64-windows-gnu"51
backend: 'native52
static?: #t53
debug?: #f54
optimize: 255
features: '(release cross windows)))57
dependencies: (list58
(from-git url: "codeberg:sigil/sigil" package: "sigil-stdlib" version: ">=0.20"))60
libraries: (list61
(library62
name: 'sigil-audio63
;; sigil-build reads this list only as a "has native code" test and64
;; for the include dirs; the build task below compiles the real,65
;; target-dependent list (dl-search.c on Linux only). Keep it to66
;; 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 public69
;; ogg/vorbis headers consumed by ogg-encode.c. vendor/vorbis/lib70
;; is needed because libvorbis internal .c files include their71
;; 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 at78
;; run time (libpulse.so.0, libasound.so.2, libjack.so.0 on Linux;79
;; ole32/mmdevapi/avrt/winmm/dsound DLLs on Windows; the CoreAudio80
;; frameworks by absolute path on macOS), so -lasound, AudioToolbox81
;; and ole32/winmm/ksuser are gone. pthread and dl are libc's on82
;; glibc 2.34+ (sigil-build adds -lpthread -ldl on Linux anyway).83
;;84
;; Procedural (lambda ctx) form kept so a target can add a flag85
;; 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: (list94
(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: (list98
(task99
name: 'build100
description: "Build sigil-audio"101
steps: (list102
;; Compile vendored libogg with relaxed warning flags. Upstream103
;; sources are byte-identical to the 1.3.6 tarball (see104
;; vendor/ogg/README.md); keeping warnings off avoids polluting105
;; sigil-audio's own strict-flag set when upstream's style106
;; trips -Wparentheses / -Wunused-* / -Wsign-compare.107
;;108
;; The C steps are wrapped in skip-on-wasm: none of this native audio109
;; C cross-compiles to wasm32-wasi, and the (sigil audio sink) facade's110
;; wasm arm uses the WebAudio bridge instead. compile-sigil-modules is111
;; NOT wrapped: the facade + module bytecode must still build on wasm.112
(skip-on-wasm (compile-c-sources113
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 the124
;; toolchain traps it at RUNTIME, so the suite died in125
;; vorbis_analysis rather than failing a test. Upstream126
;; 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 + file131
;; I/O). Upstream sources are byte-identical to the 1.3.7132
;; tarball (see vendor/vorbis/README.md). Same relaxed-warning133
;; rationale as libogg above.134
(skip-on-wasm (compile-c-sources135
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 so161
;; HAVE_ALLOCA_H gets defined on Linux/macOS (where vorbis162
;; needs it for the alloca prototype under -std=c99) but163
;; NOT on Windows/MinGW (where <alloca.h> is missing and164
;; vorbis's _WIN32 branch handles alloca via <malloc.h>).165
;;166
;; Flags are procedural so the -include path is resolved167
;; against this package's own directory. Literal relative168
;; paths would break downstream consumers whose cwd differs169
;; 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 the183
;; device layer only (the MA_NO_* cuts are in the file). Its184
;; runtime dlopen of libpulse / libasound / libjack goes through185
;; the resolver in dl-search.c (shared with sigil-desktop, which186
;; is the copy that may define dlopen itself; this one exposes the187
;; named sigil_audio_dl_open that miniaudio-impl.c redirects to).188
;; dl-search.c is Linux-only (Guix and Nix profiles); the other189
;; targets compile miniaudio alone. Warnings relaxed for the190
;; vendored header only.191
(skip-on-wasm192
(lambda (ctx)193
((compile-c-sources194
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-sources211
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")))))))