AtlatestRepositorysigil-ui

sigil-ui / tree / scriptsbuild-macos-demo.sgl

1#!/usr/bin/env sigil
2;;; Cross-build the development demo on Linux; never uses an Apple SDK.
3(import (sigil shell prelude))
4(requires (tools cp))
5(define root (realpath (path (script-dir) "..")))
6(define runtime (realpath (arg 1)))
7(define action (arg 2 default: "build"))
8(define zig (realpath (arg 3 default: (path (getenv "HOME") ".sigil/toolchain/zig/zig"))))
9(unless (equal? (out ,zig version) "0.16.0") (error "Expected Zig 0.16.0"))
10(define build (path root "build/macos"))
11(each name '("tmp" "state" "cache" "store")
12 (ensure-directory (path build name)))
13(setenv! "TMPDIR" (path build "tmp"))
14(setenv! "XDG_CACHE_HOME" (path build "cache"))
15(setenv! "SIGIL_STORE" (path build "store"))
16(cond
17 ((equal? action "build")
18 (define redirects (path build "redirects.sgl"))
19 (write-text redirects
20 (format "(redirects packages: (list (for-package name: ~s use: (from-path dir: ~s))))\n"
21 "sigil/sigil-ui" root))
22 ($ ,runtime deps install --redirects ,redirects cwd: ,(path root "demo"))
23 ($ ,runtime build -c darwin-arm64 --redirects ,redirects cwd: ,(path root "demo")))
24 ((equal? action "bundle")
25 (define binary (path root "demo/build/darwin-arm64/bin/sigil-ui-demo"))
26 (unless (file? binary) (error "Cross-build the demo before bundling" binary))
27 (define contents (path build "Sigil UI Demo.app/Contents"))
28 (ensure-directory (path contents "MacOS"))
29 (ensure-directory (path contents "Resources"))
30 ($ ,zig cc -target aarch64-macos.15.0-none -std=c11 -D_DARWIN_C_SOURCE
31 -Wall -Wextra -Werror -O1 ,(path root "demo/macos/launcher.c")
32 -o ,(path contents "MacOS/sigil-ui-launcher"))
33 ($ cp ,(path root "demo/macos/Info.plist") ,(path contents "Info.plist"))
34 ($ cp ,binary ,(path contents "Resources/sigil-ui-demo"))
35 ($ cp -R ,(path root "demo/assets") ,(path contents "Resources")))
36 (else (error "Expected build or bundle; host checks belong to sigil-window" action)))
37(println "PASS: ~a" action)