aboutsummaryrefslogtreecommitdiff
path: root/build
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-05-09 18:00:00 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2025-05-09 18:00:00 +0200
commit8e931537ff13137f49de58b84898a13ed3cdeeef (patch)
tree0afa226e273dd07872516f3c780c9baeb34318aa /build
parente261c743dea0184ca32740160b2f101325d366fd (diff)
downloadnissy-core-8e931537ff13137f49de58b84898a13ed3cdeeef.tar.gz
nissy-core-8e931537ff13137f49de58b84898a13ed3cdeeef.zip
Add wasmtest target to build script; minor fixes in tools and tests
Diffstat (limited to 'build')
-rwxr-xr-xbuild60
1 files changed, 43 insertions, 17 deletions
diff --git a/build b/build
index d7d893c..25fb912 100755
--- a/build
+++ b/build
@@ -32,6 +32,10 @@ CC=${CC-${NISSY_BUILD_CC}}
32# The default value is "emcc". 32# The default value is "emcc".
33EMCC=${EMCC-${NISSY_BUILD_EMCC}} 33EMCC=${EMCC-${NISSY_BUILD_EMCC}}
34 34
35# Specify the nodejs command for running tests for the WASM target.
36# The default value is "node".
37NODE=${NODE-${NISSY_BUILD_NODE}}
38
35# The maximum number of threads to use for multi-threaded operations. 39# The maximum number of threads to use for multi-threaded operations.
36# This is also used as default value in case an operation allows 40# This is also used as default value in case an operation allows
37# specifying how many threads to use. 41# specifying how many threads to use.
@@ -115,6 +119,7 @@ parsesanitize() {
115# Set variables to default values if unset 119# Set variables to default values if unset
116CC=${CC:-"cc"} 120CC=${CC:-"cc"}
117EMCC=${EMCC:-"emcc"} 121EMCC=${EMCC:-"emcc"}
122NODE=${NODE:-"emcc"}
118THREADS=${THREADS:-"$(detectthreads)"} 123THREADS=${THREADS:-"$(detectthreads)"}
119ARCH=${ARCH:-"$(detectarch)"} 124ARCH=${ARCH:-"$(detectarch)"}
120OPTIMIZE=${OPTIMIZE:-"-O3"} 125OPTIMIZE=${OPTIMIZE:-"-O3"}
@@ -145,10 +150,11 @@ build_help() {
145 echo "Build system for nissy" 150 echo "Build system for nissy"
146 echo "" 151 echo ""
147 echo "usage:" 152 echo "usage:"
148 echo "$0 TARGET # build the given TARGET" 153 echo "$0 TARGET # build the given TARGET"
149 echo "$0 # same as '$0 nissy'" 154 echo "$0 # same as '$0 nissy'"
150 echo "$0 test [PATTERN] # run unit tests (optionally matching PATTERN) 155 echo "$0 test [PATTERN] # run unit tests (matching PATTERN)"
151 echo "$0 tool PATTERN # run the tool matching PATTERN 156 echo "$0 wasmtest [PATTERN] # same as test, but for WASM target"
157 echo "$0 tool PATTERN # run the tool matching PATTERN"
152 echo "" 158 echo ""
153 echo "targets:" 159 echo "targets:"
154 echo "" 160 echo ""
@@ -171,6 +177,7 @@ build_config() {
171 echo "Optimization options: $OFLAGS" 177 echo "Optimization options: $OFLAGS"
172 echo "Debug flags: $DFLAGS" 178 echo "Debug flags: $DFLAGS"
173 echo "WASM compiler: $EMCC" 179 echo "WASM compiler: $EMCC"
180 echo "nodejs executable: $NODE"
174 echo "Python bindings: $PYTHON3" 181 echo "Python bindings: $PYTHON3"
175} 182}
176 183
@@ -223,7 +230,7 @@ build_python() {
223 230
224build_wasm() { 231build_wasm() {
225 run $EMCC $WASMCFLAGS $WFLAGS $WASMMFLAGS $(odflags) -c \ 232 run $EMCC $WASMCFLAGS $WFLAGS $WASMMFLAGS $(odflags) -c \
226 -o wasmnissy.o src/nissy.c 233 -o nissy.o src/nissy.c
227} 234}
228 235
229dotest() { 236dotest() {
@@ -240,13 +247,12 @@ dotest() {
240 return 0 247 return 0
241 fi 248 fi
242 249
243 $CC $CFLAGS $WFLAGS $DFLAGS $MFLAGS -o runtest "$t"/*.c nissy.o \ 250 $testbuild "$t"/*.c nissy.o || exit 1
244 || exit 1
245 for cin in "$t"/*.in; do 251 for cin in "$t"/*.in; do
246 c="$(echo "$cin" | sed 's/\.in//')" 252 c="$(echo "$cin" | sed 's/\.in//')"
247 cout="$c.out" 253 cout="$c.out"
248 printf '%s: ' "$c" 254 printf '%s: ' "$c"
249 ./runtest < "$cin" > "$testout" 2> "$testerr" 255 $testrun < "$cin" > "$testout" 2> "$testerr"
250 if diff "$cout" "$testout"; then 256 if diff "$cout" "$testout"; then
251 printf "OK\n" 257 printf "OK\n"
252 else 258 else
@@ -257,33 +263,50 @@ dotest() {
257 done 263 done
258} 264}
259 265
260build_test() { 266build_test_generic() {
261 if [ -n "$1" ]; then 267 if [ -n "$1" ]; then
262 pattern="$1" 268 pattern="$1"
263 shift 269 shift
264 fi 270 fi
265 debug="yes" 271 debug="yes"
266 build_nissy 272 build_$obj
267 for t in test/*; do 273 for t in test/*; do
268 dotest || exit 1 274 dotest || exit 1
269 done 275 done
270 echo "All tests passed!" 276 echo "All tests passed!"
271} 277}
272 278
279build_test() {
280 obj="nissy"
281 testobj="runtest"
282 testbuild="$CC $CFLAGS $WFLAGS $DFLAGS $MFLAGS -o $testobj"
283 testrun="./$testobj"
284 build_test_generic $@
285 rm runtest
286}
287
288build_wasmtest() {
289 obj="wasm"
290 testobj="runtest.js"
291 testbuild="$EMCC $WASMCFLAGS $WFLAGS $WASMMFLAGS $DFLAGS -o $testobj"
292 testrun="$NODE $testobj"
293 build_test_generic $@
294 rm -f runtest.js runtest.wasm
295}
296
273tool_usage() { 297tool_usage() {
274 echo "usage: ./build tool PATTERN" 298 echo "usage: ./build tool PATTERN"
275} 299}
276 300
277build_tool() { 301build_tool() {
278 if [ -z "$1" ]; then 302 pattern="$1"
303
304 if [ -z "$pattern" ]; then
279 tool_usage 305 tool_usage
280 exit 1 306 exit 1
281 fi 307 fi
282 pattern="$1"
283 shift 308 shift
284 309
285 build_nissy
286
287 # Select a single tool matched by the given pattern 310 # Select a single tool matched by the given pattern
288 for t in tools/*; do 311 for t in tools/*; do
289 if [ -d "$t" ] && (echo "$t" | grep -q "$pattern"); then 312 if [ -d "$t" ] && (echo "$t" | grep -q "$pattern"); then
@@ -292,13 +315,15 @@ build_tool() {
292 fi 315 fi
293 done 316 done
294 if [ -z "$toolname" ]; then 317 if [ -z "$toolname" ]; then
295 tool_usage 318 echo "pattern '$pattern' does not match any tool"
296 exit 1 319 exit 1
297 fi 320 fi
298 321
322 build_nissy
323
299 results="tools/results" 324 results="tools/results"
300 last="$results/last.out" 325 last="$results/last.out"
301 date="$(date + '%Y-%m-%d-%H-%M-%S')" 326 date="$(date +'%Y-%m-%d-%H-%M-%S')"
302 file="$results/$toolname-$date.txt" 327 file="$results/$toolname-$date.txt"
303 328
304 $CC $CFLAGS $WFLAGS $MFLAGS $(odflags) -o runtool "$t"/*.c nissy.o \ 329 $CC $CFLAGS $WFLAGS $MFLAGS $(odflags) -o runtool "$t"/*.c nissy.o \
@@ -319,6 +344,7 @@ build_tool() {
319 echo "============ tool output ============" 344 echo "============ tool output ============"
320 ./runtool $@ 345 ./runtool $@
321 ) | tee "$file" "$last" 346 ) | tee "$file" "$last"
347 rm -f runtool
322} 348}
323 349
324if [ "$1" = "-d" ]; then 350if [ "$1" = "-d" ]; then
@@ -335,7 +361,7 @@ fi
335 361
336case "$target" in 362case "$target" in
337help|config|clean|\ 363help|config|clean|\
338nissy|lib|sharedlib|shell|python|wasm|test|tool) 364nissy|lib|sharedlib|shell|python|wasm|test|wasmtest|tool)
339 mkdir -p tables tools/results 365 mkdir -p tables tools/results
340 (build_"$target" $@) || exit 1 366 (build_"$target" $@) || exit 1
341 exit 0 367 exit 0

Generated with cgit - Back to sebastiano.tronto.net