commit 9b94c7d039341afb8609075da0ce52a7a7aa705a
parent c368c0f4aa0a810f5102cb8958e57410e572afa8
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Wed, 13 Aug 2025 16:38:21 +0100
More build.bat options
Diffstat:
M | .gitignore | | | 1 | + |
M | build.bat | | | 75 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- |
M | tools/tool.h | | | 36 | ++++++++++++++++++++++++++++++++++++ |
3 files changed, 108 insertions(+), 4 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -39,6 +39,7 @@ tools/results
*.pyd
*.dll
*.exp
+*.exe
*.lib
*.pdb
*.ilk
diff --git a/build.bat b/build.bat
@@ -8,6 +8,7 @@ if [%1]==[/d] (
)
SET CC=clang
+SET CXX=clang++
SET ARCH=PORTABLE
SET THREADS=1
SET SANITIZE=
@@ -34,9 +35,9 @@ SET PYLIBS=%PYPATH%\libs
SET TARGET=%1
if not defined TARGET SET TARGET=nissy
SET EXPR=%2
-for %%a in (nissy python shell test config help) do (
+for %%a in (nissy python shell test config help clean tool cpp solvetest) do (
if %TARGET%==%%a (
- call:build_%TARGET%
+ call:build_%TARGET% %*
exit /b
)
)
@@ -56,11 +57,16 @@ exit /b 1
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 cpp FILE Build and run the given C++ FILE.
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 tool EXPR Run the 'tool' matching the given EXPR.
+ echo solvetest Build nissy and run a collection of tools for testing"
+ echo various solvers.
+ echo help Show this help message.
+ echo config Show build configuration and exit.
+ echo clean Remove all build files.
echo.
echo The /d option activates debug mode (slower, used for testing).
echo Tests are automatically built in debug mode even without /d.
@@ -115,6 +121,57 @@ exit /b
)
exit /b
+:build_clean
+ @echo on
+ del *.o *.so *.a *.ilk *.pdb *.exe
+ @echo off
+exit /b
+
+:build_tool
+ if not defined EXPR (
+ @echo Please provide a valid EXPR to select a tool
+ exit /b 1
+ )
+
+ set toolname=
+ for /d %%d in ( tools\*%EXPR%* ) do (
+ set toolname=%%~nd
+ )
+
+ if [%toolname%]==[] (
+ @echo Expression '%EXPR%' does not match any tool
+ exit /b 1
+ )
+
+ call:build_nissy || exit /b 1
+ call:build_single_tool %*
+exit /b
+
+:build_cpp
+ if not defined EXPR (
+ @echo Please provide a valid C++ source file.
+ exit /b 1
+ )
+ if not exist %EXPR% (
+ @echo File %EXPR% does not exist.
+ exit /b 1
+ )
+ call:build_nissy || exit /b 1
+ @echo on
+ %CXX% %ODFLAGS% -std=c++20 -o runcpp.exe cpp\nissy.cpp nissy.o %EXPR% ^
+ || exit /b 1
+ runcpp
+ @echo off
+exit /b
+
+:build_solvetest
+ call:build_nissy || exit /b 1
+ for /d %%d in ( tools\*solvetest* ) do (
+ set toolname=%%~nd
+ call:build_single_tool
+ )
+exit /b
+
:build_single_test
call:odflags
%CC% %CFLAGS% %ODFLAGS% %LFLAGS% nissy.o %1\*.c -o runtest.exe || exit /b 1
@@ -138,6 +195,16 @@ exit /b
del runtest.*
exit /b
+:build_single_tool
+ @echo on
+ %CC% %CFLAGS% %ODFLAGS% %LFLAGS% nissy.o tools\%toolname%\*.c ^
+ -o runtool.exe || exit /b 1
+ @echo off
+ runtool %3 %4 %5 %6 %7 %8 %9 || exit /b 1
+ @echo.
+ @echo (On Windows, the output of a tool is not saved to any file.)
+exit /b
+
:odflags
if %DEBUG%==1 (
SET ODFLAGS=%DFLAGS%
diff --git a/tools/tool.h b/tools/tool.h
@@ -22,6 +22,40 @@ log_stderr(const char *str, void *unused)
fprintf(stderr, "%s", str);
}
+#ifdef _WIN32
+
+#include <windows.h>
+
+static double
+timerun(void (*run)(void))
+{
+ LARGE_INTEGER freq, start, end;
+ double tdiff;
+
+ fflush(stdout);
+
+ if (run == NULL) {
+ printf("nothing to run!\n");
+ fflush(stdout);
+ return -1.0;
+ }
+
+ QueryPerformanceFrequency(&freq);
+ QueryPerformanceCounter(&start);
+ run();
+ QueryPerformanceCounter(&end);
+
+ tdiff = (double)(end.QuadPart - start.QuadPart) / freq.QuadPart;
+
+ printf("---------\n");
+ printf("\nTotal time: %.4fs\n", tdiff);
+ fflush(stdout);
+
+ return tdiff;
+}
+
+#else
+
static double
timerun(void (*run)(void))
{
@@ -51,6 +85,8 @@ timerun(void (*run)(void))
return tdiff;
}
+#endif
+
static void
writetable(const unsigned char *buf, int64_t size, const char *filename)
{