-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·102 lines (84 loc) · 2.63 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·102 lines (84 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env bash
# Build helper, a thin wrapper over zig build.
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")"
# --- Utility Functions ---
CONFIG=ReleaseFast
TARGET=x86_64-linux-gnu.2.17 # portable baseline for linux releases
set_config() {
case "${1:-release}" in
debug) CONFIG=Debug ;;
release) CONFIG=ReleaseFast ;;
*) echo "Unknown config: $1"; exit 1 ;;
esac
}
project_name() {
sed -n 's/^const name = "\([A-Za-z0-9_-]*\)".*/\1/p' build.zig
}
# --- Commands ---
run() {
set_config "${1:-debug}"
unset WATCH # run never watches, dev does
zig build run -Doptimize=$CONFIG -Dtarget=$TARGET
}
dev() {
export WATCH=1 # hot reload, see WatchFiles in src/main.c
zig build run -Doptimize=Debug -Dtarget=$TARGET
}
linux() {
set_config "${1:-}"
zig build -Doptimize=$CONFIG -Dtarget=$TARGET
}
windows() {
set_config "${1:-}"
zig build -Doptimize=$CONFIG -Dtarget=x86_64-windows-gnu
}
web() {
zig build web -Dweb
echo "test locally: emrun zig-out/web/index.html"
}
dist() {
rm -rf dist
linux
windows
web
local name="$(project_name)"
mkdir -p dist
zip -j "dist/$name-linux.zip" "zig-out/bin/$name" zig-out/bin/*.pak
zip -j "dist/$name-windows.zip" "zig-out/bin/$name.exe" zig-out/bin/*.pak
zip -j "dist/$name-web.zip" zig-out/web/index.html \
zig-out/web/index.js zig-out/web/index.wasm zig-out/web/index.data
echo "dist/ ready: $name-linux.zip $name-windows.zip $name-web.zip"
}
bindgen() {
zig build bindgen
}
clean() {
rm -rf zig-out .zig-cache dist
}
# --- Command Handling ---
show_help() {
echo "Usage: $0 <command> [options]"
echo "Commands:"
echo " run Build and run the game [debug|release]"
echo " dev Build and run the game with hot reload"
echo " linux Build the linux target [debug|release]"
echo " windows Build the windows target [debug|release]"
echo " web Build the web target"
echo " dist Package release zips for all platforms into dist/"
echo " bindgen Regenerate the python bindings and type stubs"
echo " clean Clean build environment"
echo " help Show this help message"
echo ""
echo "Build targets default to release, run defaults to debug."
}
case "${1:-help}" in
run|linux|windows)
[ "$#" -le 2 ] || { echo "$1 takes at most one option"; exit 1; }
"$1" "${2:-}" ;;
dev|web|dist|bindgen|clean)
[ "$#" -le 1 ] || { echo "$1 takes no options"; exit 1; }
"$1" ;;
help|--help|-h) show_help ;;
*) echo "Unknown command: $1"; show_help; exit 1 ;;
esac