build.bat (6207B)
1 @echo off 2 3 if [%1]==[/d] ( 4 SET DEBUG=1 5 shift 6 ) else ( 7 SET DEBUG=0 8 ) 9 10 SET CC=clang 11 SET CXX=clang++ 12 SET THREADS=16 13 SET SANITIZE= 14 15 SET ARCH=PORTABLE 16 clang -march=native -dM -E - < NUL | findstr /C:"__AVX2__" >NUL 2>&1 17 if %ERRORLEVEL% EQU 0 ( 18 SET ARCH=AVX2 19 SET ARCHOPTS=-mavx2 20 goto :ArchDone 21 ) 22 clang -march=native -dM -E - < NUL | findstr /C:"__ARM_NEON" >NUL 2>&1 23 if %ERRORLEVEL% EQU 0 ( 24 SET ARCH=NEON 25 goto :ArchDone 26 ) 27 :ArchDone 28 29 30 SET DFLAGS=-g3 -DDEBUG 31 SET WARNINGS=-Wno-deprecated-declarations 32 SET VARIABLES=-DTHREADS=%THREADS% -D%ARCH% 33 SET OFLAGS=-O3 34 35 SET CFLAGS=-std=c11 %ARCHOPTS% %WARNINGS% %VARIABLES% 36 37 SET STACKSIZE=-Wl,-stack:16777216 38 SET LFLAGS=%STACKSIZE% 39 40 :: Python libraries - change to match your local installation 41 for /f "delims=" %%i in ('python -c "import sys; print(sys.base_prefix)"') do set PYPATH=%%i 42 ::SET PYPATH=%userprofile%\AppData\Local\Programs\Python\Python313 43 44 SET PYINCLUDE=%PYPATH%\include 45 SET PYLIBS=%PYPATH%\libs 46 47 SET TARGET=%1 48 if not defined TARGET SET TARGET=nissy 49 SET EXPR=%2 50 for %%a in (nissy python shell test config help clean tool cpp solvetest) do ( 51 if %TARGET%==%%a ( 52 call:build_%TARGET% %* 53 exit /b 54 ) 55 ) 56 57 echo Target '%TARGET%' unavailable, run 'build help' for info 58 exit /b 1 59 60 :build_help 61 echo *** Warning: support for building nissy on Windows is incomplete *** 62 echo. 63 echo Build system for nissy. Usage: 64 echo. 65 echo build [/d] [TARGET] 66 echo. 67 echo Possible values for TARGET (defaults to 'nissy' if unspecified): 68 echo. 69 echo nissy Build the nissy.o object file. 70 echo python Build the Python module for nissy. 71 echo NOTE: Python development headers must be installed in 72 echo order to build the Python module. The path of these 73 echo headers is hardcoded in the PYPATH varible in 74 echo build.bat. You may need to edit this file. 75 echo shell Build the basic nissy shell (./run). 76 echo cpp FILE Build and run the given C++ FILE. 77 echo test [EXPR] Build and run unit tests. If EXPR is provided, only the 78 echo tests whose name contains EXPR are run. The /d option is 79 echo is always implied. 80 echo tool EXPR Run the 'tool' matching the given EXPR. 81 echo solvetest Build nissy and run a collection of tools for testing" 82 echo various solvers. 83 echo help Show this help message. 84 echo config Show build configuration and exit. 85 echo clean Remove all build files. 86 echo. 87 echo The /d option activates debug mode (slower, used for testing). 88 echo Tests are automatically built in debug mode even without /d. 89 echo For more on build configurations, see the comments in build.bat. 90 exit /b 91 92 :build_config 93 echo Compiler: %CC% 94 echo Architecture: %ARCH% 95 echo Max threads: %THREADS% 96 echo Optimization flags: %OFLAGS% 97 echo Debug flags: %DFLAGS% 98 exit /b 99 100 :build_nissy 101 call:odflags 102 @echo on 103 %CC% %CFLAGS% %ODFLAGS% -c src\nissy.c || exit /b 1 104 @echo off 105 exit /b 106 107 :build_shell 108 call:build_nissy || exit /b 1 109 call:odflags 110 @echo on 111 %CC% %CFLAGS% %ODFLAGS% %LFLAGS% nissy.o shell\shell.c -o run.exe ^ 112 || exit /b 1 113 @echo off 114 exit /b 115 116 :build_python 117 call:build_nissy || exit /b 1 118 call:odflags 119 @echo on 120 %CC% %CFLAGS% %LFLAGS% -I%PYINCLUDE% -L%PYLIBS% -shared -lpython3 ^ 121 python\nissy_module.c nissy.o -o python\nissy.pyd || exit /b 1 122 @echo off 123 exit /b 124 125 :build_test 126 SET DEBUG=1 127 call:build_nissy || exit /b 1 128 if not defined EXPR ( 129 SET WILDCARD=* 130 ) else ( 131 SET WILDCARD=*%EXPR%* 132 ) 133 for /d %%d in ( test\%WILDCARD% ) do ( 134 if exist %%d\* ( 135 call:build_single_test %%d || exit /b 1 136 ) 137 ) 138 exit /b 139 140 :build_clean 141 @echo on 142 del *.o *.so *.a *.ilk *.pdb *.exe 143 @echo off 144 exit /b 145 146 :build_tool 147 if not defined EXPR ( 148 @echo Please provide a valid EXPR to select a tool 149 exit /b 1 150 ) 151 152 set toolname= 153 for /d %%d in ( tools\*%EXPR%* ) do ( 154 set toolname=%%~nd 155 ) 156 157 if [%toolname%]==[] ( 158 @echo Expression '%EXPR%' does not match any tool 159 exit /b 1 160 ) 161 162 call:build_nissy || exit /b 1 163 call:build_single_tool %* 164 exit /b 165 166 :build_cpp 167 if not defined EXPR ( 168 @echo Please provide a valid C++ source file. 169 exit /b 1 170 ) 171 if not exist %EXPR% ( 172 @echo File %EXPR% does not exist. 173 exit /b 1 174 ) 175 call:build_nissy || exit /b 1 176 @echo on 177 %CXX% %ODFLAGS% -std=c++20 -o runcpp.exe cpp\nissy.cpp nissy.o %EXPR% ^ 178 || exit /b 1 179 runcpp 180 @echo off 181 exit /b 182 183 :build_solvetest 184 call:build_nissy || exit /b 1 185 for /d %%d in ( tools\*solvetest* ) do ( 186 set toolname=%%~nd 187 call:build_single_tool 188 ) 189 exit /b 190 191 :build_single_test 192 call:odflags 193 %CC% %CFLAGS% %ODFLAGS% %LFLAGS% nissy.o %1\*.c -o runtest.exe || exit /b 1 194 set error=0 195 for %%c in ( %1\*.in ) do ( 196 if %error%==1 exit /b 1 197 @echo | set /p v="%1\%%~nc: " 198 runtest < %%c > test\last.out 2> test\last.err 199 FC /a %1\%%~nc.out test\last.out > test\last.fc.out 200 if ERRORLEVEL 1 ( 201 @echo Test failed! Different output: 202 type test\last.fc.out 203 @echo stderr: 204 type test\last.err 205 goto :error 206 ) else ( 207 @echo ok 208 ) 209 ) 210 if %error%==1 exit /b 1 211 del runtest.* 212 exit /b 213 214 :build_single_tool 215 @echo on 216 %CC% %CFLAGS% %ODFLAGS% %LFLAGS% nissy.o tools\%toolname%\*.c ^ 217 -o runtool.exe || exit /b 1 218 @echo off 219 runtool %3 %4 %5 %6 %7 %8 %9 || exit /b 1 220 @echo. 221 @echo (On Windows, the output of a tool is not saved to any file.) 222 exit /b 223 224 :odflags 225 if %DEBUG%==1 ( 226 SET ODFLAGS=%DFLAGS% 227 ) else ( 228 SET ODFLAGS=%OFLAGS% 229 ) 230 exit /b 231 232 :error 233 exit /b 1