AtlatestRepositorysigil-audio
sigil-audio / treepackage.sgl
1
;;; sigil-audio - Audio playback for Sigil2
;;;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.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 no9
;; wasm32-wasi backend; on wasm the (sigil audio sink) facade delegates to10
;; the WebAudio bridge, so none of this C is needed. Only compile-sigil-modules11
;; runs on wasm, producing the facade + module bytecode. Native builds are12
;; 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 step14
;; (fold-left over steps), so a skipped step must return ctx UNCHANGED.15
(let ((skip-on-wasm16
(lambda (step)17
(lambda (ctx)18
(if (memq (target-os ctx) '(wasm wasi))19
ctx20
(step ctx))))))21
(package22
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: (list31
(config32
name: 'dev33
output-dir: "build/dev"34
debug?: #t35
optimize: 0)36
(config37
name: 'release38
output-dir: "build/release"39
debug?: #f40
optimize: 2)42
;; Windows x86_64 (MinGW via zig) — built so downstream consumers43
;; like cinder-cantata can produce Windows binaries from Linux.44
;; Mirrors the windows-amd64 config in the main sigil package.45
(config46
name: 'windows-amd6447
output-dir: "build/windows-amd64"48
toolchain: 'zig49
target: "x86_64-windows-gnu"50
backend: 'native51
static?: #t52
debug?: #f53
optimize: 254
features: '(release cross windows)))56
dependencies: (list57
(from-git url: "codeberg:sigil/sigil" package: "sigil-stdlib" version: "^0.17"))59
libraries: (list60
(library61
name: 'sigil-audio62
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 public64
;; ogg/vorbis headers consumed by ogg-encode.c. vendor/vorbis/lib65
;; is needed because libvorbis internal .c files include their66
;; 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 evaluate76
;; the right branch at link time. (case (host-os) ...) was evaluated77
;; once at package-load on the host, leaking Linux flags into78
;; 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 CoCreateInstance84
;; / CoInitializeEx (ole32). winmm + ksuser are85
;; carried for completeness against future sokol86
;; revisions that touch waveOut / kernel-streaming.87
((windows) '("-lole32" "-lwinmm" "-lksuser"))88
(else '())))))90
tasks: (list91
(task92
name: 'build93
description: "Build sigil-audio"94
steps: (list95
;; Compile vendored libogg with relaxed warning flags. Upstream96
;; sources are byte-identical to the 1.3.6 tarball (see97
;; vendor/ogg/README.md); keeping warnings off avoids polluting98
;; sigil-audio's own strict-flag set when upstream's style99
;; trips -Wparentheses / -Wunused-* / -Wsign-compare.100
;;101
;; The C steps are wrapped in skip-on-wasm: none of this native audio102
;; C cross-compiles to wasm32-wasi, and the (sigil audio sink) facade's103
;; wasm arm uses the WebAudio bridge instead. compile-sigil-modules is104
;; NOT wrapped: the facade + module bytecode must still build on wasm.105
(skip-on-wasm (compile-c-sources106
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 + file117
;; I/O). Upstream sources are byte-identical to the 1.3.7118
;; tarball (see vendor/vorbis/README.md). Same relaxed-warning119
;; rationale as libogg above.120
(skip-on-wasm (compile-c-sources121
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 so147
;; HAVE_ALLOCA_H gets defined on Linux/macOS (where vorbis148
;; needs it for the alloca prototype under -std=c99) but149
;; NOT on Windows/MinGW (where <alloca.h> is missing and150
;; vorbis's _WIN32 branch handles alloca via <malloc.h>).151
;;152
;; Flags are procedural so the -include path is resolved153
;; against this package's own directory. Literal relative154
;; paths would break downstream consumers whose cwd differs155
;; 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-sources169
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")))))))