commit c368c0f4aa0a810f5102cb8958e57410e572afa8
parent 1562c2e8ef10e25973317c790c2779e9d595e5f1
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Wed, 13 Aug 2025 15:10:37 +0100
Improvements to build.bat (unit tests on Windows)
Diffstat:
4 files changed, 161 insertions(+), 21 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -11,8 +11,6 @@ perf.data.old
run
run.exe
debugrun
-shell/lasttest.out
-shell/lasttest.err
tables/*
test/*/runtest
test/.DS_Store
@@ -43,3 +41,7 @@ tools/results
*.exp
*.lib
*.pdb
+*.ilk
+python/*.pyd
+python/*.exp
+python/*.lib
diff --git a/README.md b/README.md
@@ -48,15 +48,25 @@ the "C++ development" pack, as well as the "clang" and "Windows SDK 11"
components. It is advised to use "x64 Native Tools Command Prompt for
VS 2022" instead of a regular command prompt to run the build script.
-The `build.bat` script is going to build:
+The `build.bat` script has the same syntax as the `build.sh` script,
+but not all options are available. For example
-* The core nissy library
-* The shell `run.exe` (see below)
-* The Python module (see below)
+```
+> build.bat shell
+```
+
+can be used to build the basic shell, while
+
+```
+> build.bat test
+```
+
+Builds and runs the unit tests. See `build.bat help` for a list of
+all available options.
-All other options are unavailable. Moreover, Windows build will not
-enable certain optimizations, such as multithreading and advanced CPU
-instructions. Work is ongoing to improve Windows support.
+Not: At the moment certain optimizations, such as multithreading and
+advanced CPU instructions, are not supported on Windows.
+Work is ongoing to improve Windows support.
## Running tests
diff --git a/build.bat b/build.bat
@@ -1,21 +1,150 @@
-SET COMPILER=clang
+@echo off
+
+if [%1]==[/d] (
+ SET DEBUG=1
+ shift
+) else (
+ SET DEBUG=0
+)
+
+SET CC=clang
+SET ARCH=PORTABLE
+SET THREADS=1
+SET SANITIZE=
+
+:: TODO depends on ARCH variable
+SET ARCHOPTS=
+:: TODO depends on SANITIZE variable
+SET DFLAGS=-g3 -DDEBUG
-SET ARCH=
SET WARNINGS=-Wno-deprecated-declarations
-SET VARIABLES=-DTHREADS=1 -DPORTABLE
+SET VARIABLES=-DTHREADS=%THREADS% -D%ARCH%
SET OFLAGS=-O3
-SET DFLAGS=-g -fsanitize=address
-SET CFLAGS=-std=c11 %OFLAGS% %ARCH% %WARNINGS% %VARIABLES%
+
+SET CFLAGS=-std=c11 %ARCHOPTS% %WARNINGS% %VARIABLES%
SET STACKSIZE=-Wl,-stack:16777216
SET LFLAGS=%STACKSIZE%
-%COMPILER% %CFLAGS% -c src\nissy.c || exit /b
-%COMPILER% %CFLAGS% %LFLAGS% nissy.o shell\shell.c -o run.exe || exit /b
-
-:: Python libraries - change to mathc your local installation
+:: Python libraries - change to match your local installation
SET PYPATH=%userprofile%\AppData\Local\Programs\Python\Python313
SET PYINCLUDE=%PYPATH%\include
SET PYLIBS=%PYPATH%\libs
-%COMPILER% %CFLAGS% -I%PYINCLUDE% -L%PYLIBS% -shared -lpython3 python/nissy_module.c nissy.o -o nissy.pyd
-\ No newline at end of file
+SET TARGET=%1
+if not defined TARGET SET TARGET=nissy
+SET EXPR=%2
+for %%a in (nissy python shell test config help) do (
+ if %TARGET%==%%a (
+ call:build_%TARGET%
+ exit /b
+ )
+)
+
+echo Target '%TARGET%' unavailable, run 'build help' for info
+exit /b 1
+
+:build_help
+ echo *** Warning: support for building nissy on Windows is incomplete ***
+ echo.
+ echo Build system for nissy. Usage:
+ echo.
+ echo build [/d] [TARGET]
+ echo.
+ echo Possible values for TARGET (defaults to 'nissy' if unspecified):
+ echo.
+ echo nissy Build the nissy.o object file.
+ echo python Build the Python module for nissy.
+ echo shell Build the basic nissy shell (./run).
+ echo help Show this help message.
+ echo config Show build configuration and exit.
+ echo test [EXPR] Build and run unit tests. If EXPR is provided, only the
+ echo tests whose name contains EXPR are run. The /d option is
+ echo is always implied.
+ echo.
+ echo The /d option activates debug mode (slower, used for testing).
+ echo Tests are automatically built in debug mode even without /d.
+ echo For more on build configurations, see the comments in build.bat.
+exit /b
+
+:build_config
+ echo Compiler: %CC%
+ echo Architecture: %ARCH%
+ echo Max threads: %THREADS%
+ echo Optimization flags: %OFLAGS%
+ echo Debug flags: %DFLAGS%
+exit /b
+
+:build_nissy
+ call:odflags
+ @echo on
+ %CC% %CFLAGS% %ODFLAGS% -c src\nissy.c || exit /b 1
+ @echo off
+exit /b
+
+:build_shell
+ call:build_nissy || exit /b 1
+ call:odflags
+ @echo on
+ %CC% %CFLAGS% %ODFLAGS% %LFLAGS% nissy.o shell\shell.c -o run.exe ^
+ || exit /b 1
+ @echo off
+exit /b
+
+:build_python
+ call:build_nissy || exit /b 1
+ call:odflags
+ @echo on
+ %CC% %CFLAGS% %LFLAGS% -I%PYINCLUDE% -L%PYLIBS% -shared -lpython3 ^
+ python\nissy_module.c nissy.o -o python\nissy.pyd || exit /b 1
+ @echo off
+exit /b
+
+:build_test
+ SET DEBUG=1
+ call:build_nissy || exit /b 1
+ if not defined EXPR (
+ SET WILDCARD=*
+ ) else (
+ SET WILDCARD=*%EXPR%*
+ )
+ for /d %%d in ( test\%WILDCARD% ) do (
+ if exist %%d\* (
+ call:build_single_test %%d || exit /b 1
+ )
+ )
+exit /b
+
+:build_single_test
+ call:odflags
+ %CC% %CFLAGS% %ODFLAGS% %LFLAGS% nissy.o %1\*.c -o runtest.exe || exit /b 1
+ set error=0
+ for %%c in ( %1\*.in ) do (
+ if %error%==1 exit /b 1
+ @echo | set /p v="%1\%%~nc: "
+ runtest < %%c > test\last.out 2> test\last.err
+ FC /a %1\%%~nc.out test\last.out > test\last.fc.out
+ if ERRORLEVEL 1 (
+ @echo Test failed! Different output:
+ type test\last.fc.out
+ @echo stderr:
+ type test\last.err
+ goto :error
+ ) else (
+ @echo ok
+ )
+ )
+ if %error%==1 exit /b 1
+ del runtest.*
+exit /b
+
+:odflags
+ if %DEBUG%==1 (
+ SET ODFLAGS=%DFLAGS%
+ ) else (
+ SET ODFLAGS=%OFLAGS%
+ )
+exit /b
+
+:error
+ exit /b 1
+\ No newline at end of file
diff --git a/test/test.h b/test/test.h
@@ -1,7 +1,6 @@
#define TEST_H
#include <inttypes.h>
-#include <pthread.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>