nissy-core

The "engine" of nissy, including the H48 optimal solver.
git clone https://git.tronto.net/nissy-core
Download | Log | Files | Refs | README | LICENSE

build.bat (7978B)


      1 @echo off
      2 
      3 SET DEBUG=0
      4 if "%1"=="/d" (
      5     SET DEBUG=1
      6     shift
      7 )
      8 if "%1"=="test" (SET DEBUG=1)
      9 
     10 :: Detect architecture, or use user-specified one
     11 if "%ARCH%"=="" goto :detect_arch
     12 if "%ARCH%"=="PORTABLE" goto :arch_done
     13 if "%ARCH%"=="AVX2" goto :arch_done
     14 if "%ARCH%"=="NEON" goto :arch_done
     15 
     16 echo Unsupported architecture '%ARCH%'
     17 exit /b 1
     18 
     19 :detect_arch
     20     if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
     21         SET ARCH=AVX2
     22     ) else if "%PROCESSOR_ARCHITECTURE%"=="ARM64" (
     23         SET ARCH=NEON
     24     ) else (
     25         SET ARCH=PORTABLE
     26     )
     27 :arch_done
     28 
     29 :: Default value for maximum number of threads
     30 SET THREADS=16
     31 
     32 :: Detect Python libraries path
     33 for /f "delims=" %%i in ('python -c "import sys; print(sys.base_prefix)"') do set PYPATH=%%i
     34 SET PYINCLUDE=%PYPATH%\include
     35 SET PYLIBS=%PYPATH%\libs
     36 
     37 :: Select compiler from possibly user-set %CC% variable
     38 :: Currently we only support clang and MSVC
     39 if "%CC%"=="" goto :set_msvc
     40 if /I "%CC%"=="cl" goto :set_msvc
     41 if /I "%CC%"=="msvc" goto :set_msvc
     42 if /I "%CC%"=="clang" goto :set_clang
     43 
     44 echo Unsupported compiler '%CC%'
     45 exit /b 1
     46 
     47 :set_msvc
     48     SET CC=cl
     49     SET CXX=cl
     50 
     51     SET DFLAGS=/Zi /DDEBUG
     52     SET WARNINGS=/W4 /wd4100 /wd4324 /wd4505 /wd4996
     53     SET VARIABLES=/DTHREADS=%THREADS% /D%ARCH%
     54     SET OFLAGS=/O2
     55 
     56     if %DEBUG%==1 (SET ODFLAGS=%DFLAGS%) else (SET ODFLAGS=%OFLAGS%)
     57     if "%ARCH%"=="AVX2" (SET ARCHOPTS=/arch:AVX2) else (SET ARCHOPTS=)
     58 
     59     SET CFLAGS=/std:c11 /experimental:c11atomics /nologo %ARCHOPTS% %WARNINGS% %VARIABLES%
     60     SET LFLAGS=/F 16777216
     61 
     62     SET CC_NISSY=%CC% %CFLAGS% %ODFLAGS% /c src\nissy.c
     63     SET CC_SHELL=%CC% %CFLAGS% %ODFALGS% %LFLAGS% nissy.obj shell\shell.c /Fe:run.exe
     64     SET CC_PYTHON=%CC% %CFLAGS% %LFLAGS% /I"%PYINCLUDE%" /LD /Fe:python\nissy.pyd python\nissy_module.c nissy.obj /link /LIBPATH:"%PYLIBS%" python3.lib
     65     SET CC_TEST=%CC% %CFLAGS% %ODFLAGS% %LFLAGS% /Fe:runtest.exe nissy.obj
     66     SET CC_TOOL=%CC% %CFLAGS% %ODFLAGS% %LFLAGS% /Fe:runtool.exe nissy.obj
     67     SET CC_CXX=%CXX% /EHsc /nologo %ARCHOPTS% %ODFLAGS% %LFLAGS% /std:c++20 /Fe:runcpp.exe nissy_c.obj cpp\nissy.cpp
     68 goto :compiler_done
     69 
     70 :set_clang
     71     SET CC=clang
     72     SET CXX=clang++
     73 
     74     SET DFLAGS=-g3 -DDEBUG
     75     SET WARNINGS=-Wall -Wextra -Wno-unused-function -Wno-unused-parameter -Wno-deprecated-declarations
     76     SET VARIABLES=-DTHREADS=%THREADS% -D%ARCH%
     77     SET OFLAGS=-O3
     78 
     79     if %DEBUG%==1 (SET ODFLAGS=%DFLAGS%) else (SET ODFLAGS=%OFLAGS%)
     80     if "%ARCH%"=="AVX2" (SET ARCHOPTS=-mavx2) else (SET ARCHOPTS=)
     81 
     82     SET CFLAGS=-std=c11 %ARCHOPTS% %WARNINGS% %VARIABLES%
     83     SET LFLAGS=-Wl,-stack:16777216
     84 
     85     SET CC_NISSY=%CC% %CFLAGS% %ODFLAGS% -c src\nissy.c -o nissy.obj
     86     SET CC_SHELL=%CC% %CFLAGS% %ODFLAGS% %LFLAGS% nissy.obj shell\shell.c -o run.exe
     87     SET CC_PYTHON=%CC% %CFLAGS% %LFLAGS% -I%PYINCLUDE% -L%PYLIBS% -shared -lpython3 python\nissy_module.c nissy.obj -o python\nissy.pyd
     88     SET CC_TEST=%CC% %CFLAGS% %ODFLAGS% %LFLAGS% -o runtest.exe nissy.obj
     89     SET CC_TOOL=%CC% %CFLAGS% %ODFLAGS% %LFLAGS% -o runtool.exe nissy.obj
     90     SET CC_CXX=%CXX% %ARCHOPTS% %ODFLAGS% %LFLAGS% -std=c++20 -o runcpp.exe nissy_c.obj cpp\nissy.cpp
     91 :compiler_done
     92 
     93 :: Select compilation target from command line argument
     94 SET TARGET=%1
     95 if not defined TARGET SET TARGET=nissy
     96 SET EXPR=%2
     97 for %%a in (nissy python shell test config help clean tool cpp solvetest) do (
     98     if %TARGET%==%%a (
     99         call:build_%TARGET% %*
    100         exit /b
    101     )
    102 )
    103 echo Target '%TARGET%' unavailable, run 'build help' for info
    104 exit /b 1
    105 
    106 :build_help
    107     echo *** Warning: support for building nissy on Windows is incomplete ***
    108     echo.
    109     echo Build system for nissy. Usage:
    110     echo.
    111     echo build [/d] [TARGET]
    112     echo.
    113     echo Possible values for TARGET (defaults to 'nissy' if unspecified):
    114     echo.
    115     echo nissy       Build the nissy.obj object file.
    116     echo python      Build the Python module for nissy.
    117     echo             NOTE: Python development headers must be installed in
    118     echo                   order to build the Python module. The path of these
    119     echo                   headers is hardcoded in the PYPATH varible in
    120     echo                   build.bat. You may need to edit this file.
    121     echo shell       Build the basic nissy shell (./run).
    122     echo cpp FILE    Build and run the given C++ FILE.
    123     echo test [EXPR] Build and run unit tests. If EXPR is provided, only the
    124     echo             tests whose name contains EXPR are run. The /d option is
    125     echo             is always implied.
    126     echo tool EXPR   Run the 'tool' matching the given EXPR.
    127     echo solvetest   Build nissy and run a collection of tools for testing"
    128     echo             various solvers.
    129     echo help        Show this help message.
    130     echo config      Show build configuration and exit.
    131     echo clean       Remove all build files.
    132     echo.
    133     echo The /d option activates debug mode (slower, used for testing).
    134     echo Tests are automatically built in debug mode even without /d.
    135     echo For more on build configurations, see the comments in build.bat.
    136 exit /b
    137 
    138 :build_config
    139     echo Compiler: %CC%
    140     echo Architecture: %ARCH%
    141     echo Max threads: %THREADS%
    142     echo Optimization flags: %OFLAGS%
    143     echo Debug flags: %DFLAGS%
    144 exit /b
    145 
    146 :build_nissy
    147     @echo on
    148     %CC_NISSY% || exit /b 1
    149     @echo off
    150 exit /b
    151 
    152 :build_shell
    153     call:build_nissy || exit /b 1
    154     @echo on
    155     %CC_SHELL% || exit /b 1
    156     @echo off
    157 exit /b
    158 
    159 :build_python
    160     call:build_nissy || exit /b 1
    161     @echo on
    162     %CC_PYTHON% || exit /b 1
    163     @echo off
    164 exit /b
    165 
    166 :build_test
    167     call:build_nissy || exit /b 1
    168     if not defined EXPR (
    169         SET WILDCARD=*
    170     ) else (
    171         SET WILDCARD=*%EXPR%*
    172     )
    173     for /d %%d in ( test\%WILDCARD% ) do (
    174         if exist %%d\* (
    175             call:build_single_test %%d || exit /b 1
    176         )
    177     )
    178 exit /b
    179 
    180 :build_clean
    181     @echo on
    182     del *.o *.obj *.so *.a *.ilk *.pdb *.exe
    183     @echo off
    184 exit /b
    185 
    186 :build_tool
    187     if not defined EXPR (
    188         @echo Please provide a valid EXPR to select a tool
    189         exit /b 1
    190     )
    191     
    192     set toolname=
    193     for /d %%d in ( tools\*%EXPR%* ) do (
    194         set toolname=%%~nd
    195     )
    196 
    197     if [%toolname%]==[] (
    198         @echo Expression '%EXPR%' does not match any tool
    199         exit /b 1
    200     )
    201     
    202     call:build_nissy || exit /b 1
    203     call:build_single_tool %*
    204 exit /b
    205 
    206 :build_cpp
    207     if not defined EXPR (
    208         @echo Please provide a valid C++ source file.
    209         exit /b 1
    210     )
    211     if not exist %EXPR% (
    212         @echo File %EXPR% does not exist.
    213         exit /b 1
    214     )
    215     call:build_nissy || exit /b 1
    216     copy nissy.obj nissy_c.obj
    217     @echo on
    218     %CC_CXX% %EXPR% || exit /b 1
    219     del nissy.obj
    220     copy nissy_c.obj nissy.obj
    221     runcpp
    222     @echo off
    223 exit /b
    224 
    225 :build_solvetest
    226     call:build_nissy || exit /b 1
    227     for /d %%d in ( tools\*solvetest* ) do (
    228         set toolname=%%~nd
    229         call:build_single_tool
    230     )
    231 exit /b
    232 
    233 :build_single_test
    234     %CC_TEST% %1\*.c || exit /b 1
    235     set error=0
    236     for %%c in ( %1\*.in ) do (
    237         if %error%==1 exit /b 1
    238         @echo | set /p v="%1\%%~nc: "
    239         runtest < %%c > test\last.out 2> test\last.err
    240         FC /a %1\%%~nc.out test\last.out > test\last.fc.out
    241         if ERRORLEVEL 1 (
    242             @echo Test failed! Different output:
    243             type test\last.fc.out
    244             @echo stderr:
    245             type test\last.err
    246             goto :error
    247         ) else (
    248             @echo ok
    249         )
    250     )
    251     if %error%==1 exit /b 1
    252     del runtest.*
    253 exit /b
    254 
    255 :build_single_tool
    256     @echo on
    257     %CC_TOOL% tools\%toolname%\*.c || exit /b 1
    258     @echo off
    259     runtool %3 %4 %5 %6 %7 %8 %9 || exit /b 1
    260     @echo.
    261     @echo (On Windows, the output of a tool is not saved to any file.)
    262 exit /b
    263 
    264 :error
    265     exit /b 1