AtlatestRepositorysigil-app
1
;;; sigil-desktop - Desktop host layer for Sigil (window, GL context, input,2
;;; frame clock, quit). Named sigil-app through 0.9.x, when it wrapped3
;;; sokol_app.4
;;;5
;;; Window, GL context, input, frame clock and quit for interactive6
;;; applications, over GLFW (vendored under vendor/glfw). On Linux one7
;;; binary runs as a native Wayland client or under X11, picked at startup;8
;;; GLFW loads every platform library at runtime, so nothing9
;;; platform-specific is linked.11
;; ---- GLFW source lists, per target OS -------------------------------12
;;13
;; The lists mirror vendor/glfw/src/CMakeLists.txt (see vendor/glfw/VENDOR.md14
;; for the pin and the file inventory). Compile-time defines pick the15
;; platform backends; on Linux both _GLFW_X11 and _GLFW_WAYLAND are built16
;; into the one archive and glfwInit picks one at startup.18
(define glfw-common-sources19
'("vendor/glfw/src/context.c" "vendor/glfw/src/init.c"20
"vendor/glfw/src/input.c" "vendor/glfw/src/monitor.c"21
"vendor/glfw/src/platform.c" "vendor/glfw/src/vulkan.c"22
"vendor/glfw/src/window.c" "vendor/glfw/src/egl_context.c"23
"vendor/glfw/src/osmesa_context.c" "vendor/glfw/src/null_init.c"24
"vendor/glfw/src/null_monitor.c" "vendor/glfw/src/null_window.c"25
"vendor/glfw/src/null_joystick.c"))27
(define glfw-linux-sources28
'("vendor/glfw/src/posix_module.c" "vendor/glfw/src/posix_time.c"29
"vendor/glfw/src/posix_thread.c" "vendor/glfw/src/posix_poll.c"30
"vendor/glfw/src/linux_joystick.c"31
;; X1132
"vendor/glfw/src/x11_init.c" "vendor/glfw/src/x11_monitor.c"33
"vendor/glfw/src/x11_window.c" "vendor/glfw/src/xkb_unicode.c"34
"vendor/glfw/src/glx_context.c"35
;; Wayland (protocol code pre-generated under src/wayland-protocols)36
"vendor/glfw/src/wl_init.c" "vendor/glfw/src/wl_monitor.c"37
"vendor/glfw/src/wl_window.c"))39
(define glfw-windows-sources40
'("vendor/glfw/src/win32_module.c" "vendor/glfw/src/win32_time.c"41
"vendor/glfw/src/win32_thread.c" "vendor/glfw/src/win32_init.c"42
"vendor/glfw/src/win32_joystick.c" "vendor/glfw/src/win32_monitor.c"43
"vendor/glfw/src/win32_window.c" "vendor/glfw/src/wgl_context.c"))45
;; Listed and vendored; compiled only on darwin. No macOS build has run yet.46
(define glfw-darwin-sources47
'("vendor/glfw/src/posix_module.c" "vendor/glfw/src/posix_thread.c"48
"vendor/glfw/src/macos_time.c"49
"vendor/glfw/src/cocoa_init.m" "vendor/glfw/src/cocoa_joystick.m"50
"vendor/glfw/src/cocoa_monitor.m" "vendor/glfw/src/cocoa_window.m"51
"vendor/glfw/src/nsgl_context.m"))53
(define (glfw-sources os)54
(append glfw-common-sources55
(case os56
((linux) glfw-linux-sources)57
((windows) glfw-windows-sources)58
((darwin) glfw-darwin-sources)59
;; Other OSes: the null platform only (compiles; no window).60
(else '()))))62
;; _DEFAULT_SOURCE: GLFW's own CMake adds it on Linux because -std=c9963
;; hides the POSIX 2008 declarations it uses. HAVE_MEMFD_CREATE: glibc64
;; has memfd_create; GLFW's CMake probes for it and defines the same.65
(define (glfw-defines os)66
(case os67
((linux) '("-D_GLFW_X11" "-D_GLFW_WAYLAND" "-D_DEFAULT_SOURCE" "-DHAVE_MEMFD_CREATE"))68
((windows) '("-D_GLFW_WIN32" "-DUNICODE" "-D_UNICODE"))69
((darwin) '("-D_GLFW_COCOA"))70
(else '())))72
;; dl-search.c interposes dlopen so GLFW's runtime loading finds libraries73
;; in Guix and Nix profile directories; Linux-only by design (see the file).74
(define (desktop-sources os)75
(append '("src/c/desktop.c")76
(if (eq? os 'linux) '("src/c/dl-search.c") '())))78
(define desktop-include-dirs79
'("include" "vendor/glfw/include"))81
;; The dl-search.c configuration (the file is shared with sigil-audio, see82
;; its header): this package defines dlopen itself for the whole83
;; executable, so GLFW's loads go through the resolver unpatched.84
(define dl-search-flags85
'("-DSIGIL_DL_SEARCH_OPEN=sigil_desktop_dl_open"86
"-DSIGIL_DL_SEARCH_SUMMARY=sigil_desktop_dlopen_search_summary"87
"-DSIGIL_DL_SEARCH_TAG=\"sigil-desktop\""88
"-DSIGIL_DL_SEARCH_VERBOSE_ENV=\"SIGIL_DESKTOP_VERBOSE\""89
"-DSIGIL_DL_SEARCH_INTERPOSE=1"))91
(define desktop-flags92
(append '("-std=c99" "-D_GNU_SOURCE" "-Wno-unused-parameter") dl-search-flags))94
;; GLFW's own warning set is -Wall; its sources are compiled as they95
;; ship, with only the platform defines above (no local patches).96
;; -U_GNU_SOURCE: sigil's toolchain passes -D_GNU_SOURCE=1 to every C97
;; compile, and GLFW's posix_poll.c defines _GNU_SOURCE itself; the -U98
;; removes the toolchain's copy so the file compiles in the feature-macro99
;; environment upstream builds it in, without a redefinition warning.100
(define glfw-include-dirs101
'("vendor/glfw/include" "vendor/glfw/src/wayland-protocols"))103
(define glfw-flags104
'("-std=c99" "-Wall" "-Wno-unused-parameter" "-U_GNU_SOURCE"))106
;; The compile steps, procedural so the GLFW source list and the platform107
;; defines follow the config's target rather than the host (the same108
;; reason link-flags below is a lambda). Both steps register their109
;; objects on the context; create-static-library archives them all.110
(define (compile-desktop ctx)111
((compile-c-sources112
sources: (desktop-sources (target-os ctx))113
include-dirs: desktop-include-dirs114
flags: (with-sigil-c-flags desktop-flags))115
ctx))117
(define (compile-glfw ctx)118
(let ((os (target-os ctx)))119
((compile-c-sources120
sources: (glfw-sources os)121
include-dirs: glfw-include-dirs122
flags: (append glfw-flags (glfw-defines os)))123
ctx)))125
(package126
name: "sigil-desktop"127
version: "0.10.2"128
sigil: "0.20"129
description: "Desktop host layer for Sigil (window, GL context, input, frame clock) over GLFW"130
;; The repository was sigil/sigil-app on Codeberg through 0.9.x and is131
;; sigil/sigil-desktop since 2026-09-20 (renamed in place; the old URL132
;; redirects). Consumers pin from-git url: "codeberg:sigil/sigil-desktop".133
url: "https://codeberg.org/sigil/sigil-desktop"134
license: "BSD-3-Clause"135
authors: (list "David Wilson <[email protected]>")137
configs: (list138
(config139
name: 'dev140
output-dir: "build/dev"141
debug?: #t142
optimize: 0)143
(config144
name: 'release145
output-dir: "build/release"146
debug?: #f147
optimize: 2)149
;; Windows x86_64 (MinGW via zig) — built so downstream consumers150
;; (e.g., cinder-cantata) can produce Windows binaries from Linux.151
;; Mirrors the windows-amd64 config in sigil-audio and the main sigil package.152
(config153
name: 'windows-amd64154
output-dir: "build/windows-amd64"155
toolchain: 'zig156
target: "x86_64-windows-gnu"157
static?: #t158
debug?: #f159
optimize: 2160
features: '(release cross windows)))162
dependencies: (list163
(from-git url: "codeberg:sigil/sigil" package: "sigil-stdlib" version: ">=0.20"))165
;; The key table test (test/test-keys.sgl) needs a harness that links the166
;; native module; built only when tests are built.167
dev-dependencies: (list168
(from-git url: "codeberg:sigil/sigil" package: "sigil-test" version: ">=0.20")169
(from-git url: "codeberg:sigil/sigil" package: "sigil-test-runner" version: ">=0.20"))171
libraries: (list172
(library173
name: 'sigil-desktop174
;; sigil-build reads this list only as a "has native code" test and175
;; for the include dirs; the build task below compiles the real,176
;; target-dependent list (this plus dl-search.c on Linux plus177
;; the GLFW backend files). Keep it to files every target compiles.178
c-sources: '("src/c/desktop.c")179
c-include-dirs: '("include" "vendor/glfw/include")180
native-init: "sigil__init_sigil_desktop_module"181
;; Platform linker flags.182
;;183
;; Linux: none. GLFW dlopens libwayland-client, libwayland-egl,184
;; libxkbcommon, libdecor, libX11 and friends, libGL/libEGL at185
;; runtime; dlopen and pthread are in libc on glibc 2.34+.186
;; Windows: the Win32 system libraries GLFW's win32 backend calls187
;; directly (DirectInput/XInput are loaded at runtime).188
;; Darwin: the frameworks GLFW's Cocoa backend needs.189
;;190
;; Procedural (lambda ctx) form so cross-compile configs evaluate191
;; the right branch at link time. (case (host-os) ...) was evaluated192
;; once at package-load on the host, leaking Linux flags into193
;; cross builds.194
link-flags: (lambda (ctx)195
(case (target-os ctx)196
((linux) '())197
((darwin) '("-framework" "Cocoa" "-framework" "IOKit"198
"-framework" "CoreFoundation" "-framework" "QuartzCore"))199
((windows) '("-lkernel32" "-luser32" "-lshell32" "-lgdi32"))200
(else '())))))202
tasks: (list203
(task204
name: 'build205
description: "Build sigil-desktop"206
steps: (list207
compile-desktop208
compile-glfw209
(create-static-library name: "sigil-desktop")210
(compile-sigil-modules sources: "src/**/*.sgl"211
output-dir: (config-output-subdir "lib"))))))