-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·160 lines (143 loc) · 4.18 KB
/
build.sh
File metadata and controls
executable file
·160 lines (143 loc) · 4.18 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/bin/bash
# Set default values
RELEASE_MODE=false
BUILD_TARGET="$1"
ERROR_OCCURRED=false
RUN_AFTER_BUILD=false
CLEAN_BUILD=false
WEB_BUILD=false
COMPILE_SHADERS=false
ADDITIONAL_ARGS=""
# Check for arguments
ARG_COUNTER=0
for arg in "$@"; do
if [ $ARG_COUNTER -eq 0 ]; then
# Skip the first argument
:
else
case "${arg,,}" in
release)
RELEASE_MODE=true
;;
run)
RUN_AFTER_BUILD=true
;;
clean)
CLEAN_BUILD=true
;;
web)
WEB_BUILD=true
;;
shaders)
COMPILE_SHADERS=true
;;
*)
ADDITIONAL_ARGS="$ADDITIONAL_ARGS -define:$arg=true"
;;
esac
fi
ARG_COUNTER=$((ARG_COUNTER + 1))
done
# Set mode string
if [ "$RELEASE_MODE" = true ]; then
MODE="RELEASE"
else
MODE="DEBUG"
fi
# Set build arguments based on target and mode
if [ "$WEB_BUILD" = true ]; then
# Web build arguments
if [ "$RELEASE_MODE" = true ]; then
ARGS="-o:size -disable-assert -no-bounds-check"
else
ARGS="-debug"
fi
else
# Native build arguments
if [ "$RELEASE_MODE" = true ]; then
ARGS="-o:speed -disable-assert -no-bounds-check"
else
ARGS="-debug"
fi
fi
OUT="./build"
OUT_FLAG="-out:$OUT"
# Check if a build target was provided
if [ -z "$BUILD_TARGET" ]; then
echo "[BUILD] --- Error: Please provide a folder name to build"
echo "[BUILD] --- Usage: ./build.sh folder_name [release] [run] [clean] [web] [shaders]"
echo "[BUILD] --- Options:"
echo "[BUILD] --- release : Build in release mode"
echo "[BUILD] --- run : Run the executable after building"
echo "[BUILD] --- clean : Clean build artifacts before building"
echo "[BUILD] --- web : Build for WebAssembly"
echo "[BUILD] --- shaders : Force recompile shader"
exit 1
fi
TARGET_NAME=$(basename "$BUILD_TARGET")
# Clean build if requested
if [ "$CLEAN_BUILD" = true ]; then
echo "[BUILD] --- Cleaning artifacts..."
rm -f "$OUT"/*.exe
rm -f "$OUT"/*.pdb
rm -f "$OUT"/*.wasm
rm -f "$OUT"/wgpu.js
rm -f "$OUT"/odin.js
rm -f "$OUT"/utils.js
fi
INITIAL_MEMORY_PAGES=2000
MAX_MEMORY_PAGES=65536
PAGE_SIZE=65536
INITIAL_MEMORY_BYTES=$((INITIAL_MEMORY_PAGES * PAGE_SIZE))
MAX_MEMORY_BYTES=$((MAX_MEMORY_PAGES * PAGE_SIZE))
# Get and set ODIN_ROOT environment variable
ODIN_ROOT=$(odin root)
ODIN_ROOT="${ODIN_ROOT%/}"
# Handle web build
if [ "$WEB_BUILD" = true ]; then
echo "[BUILD] --- Building '$TARGET_NAME' for web in $MODE mode..."
odin build "./$BUILD_TARGET" \
"$OUT_FLAG/app.wasm" \
$ARGS \
-target:js_wasm32 \
-extra-linker-flags:"--export-table --import-memory --initial-memory=$INITIAL_MEMORY_BYTES --max-memory=$MAX_MEMORY_BYTES"
if [ $? -ne 0 ]; then
echo "[BUILD] --- Error building '$TARGET_NAME' for web"
ERROR_OCCURRED=true
else
# Build gpu.js
pushd ./wasm > /dev/null
tsc
popd > /dev/null
cp "$ODIN_ROOT/core/sys/wasm/js/odin.js" "$OUT/odin.js"
cp "./wasm/wgpu.js" "$OUT/wgpu.js"
cp "./wasm/utils.js" "$OUT/utils.js"
echo "[BUILD] --- Web build completed successfully."
fi
else
# Build the target (regular build)
echo "[BUILD] --- Building '$TARGET_NAME' in $MODE mode..."
odin build "./$BUILD_TARGET" $ARGS $ADDITIONAL_ARGS "$OUT_FLAG/$TARGET_NAME"
if [ $? -ne 0 ]; then
echo "[BUILD] --- Error building '$TARGET_NAME'"
ERROR_OCCURRED=true
fi
fi
# Check if build was successful
if [ "$ERROR_OCCURRED" = true ]; then
echo "[BUILD] --- Build process failed."
exit 1
fi
echo "[BUILD] --- Build process completed successfully."
# Run after build if requested
if [ "$RUN_AFTER_BUILD" = true ]; then
if [ "$WEB_BUILD" = true ]; then
echo "[BUILD] --- Note: Cannot automatically run web builds. Please serve the build folder."
else
echo "[BUILD] --- Running $TARGET_NAME..."
pushd build > /dev/null
"./$TARGET_NAME"
popd > /dev/null
fi
fi
exit 0