lichess.org
Donate

Compiling Stockfish on Windows

Chess engineSoftware Development
Instructions for people interested in Stockfish nerdery

A few years ago, this article, which is now only available via the web archive, was posted on how to compile the popular chess engine Stockfish on windows. The obvious benefits of being able to compile your own stockfish .exe file from the source code include, but are not limited to, compiling the latest and greatest little improvements for your local engine prior to the release date.

However, since the original post, many improvements have been made to the Stockfish project; new architectures are supported, and of course we cannot forget the addition of NNUEs. I have often compiled the popular variant playing Multi-Variant (now retired) and Fairy Stockfishes to get new features such as a new variant, support for the latest NNUE architecture, or simply to have an exe file from the release date of a new NNUE.

So, to get the necessary information on how you can build Stockfish on Windows, start by forking the Github repository you want to compile and going into the src folder (i.e. cd Stockfish/src). Here you can type make help and you will receive an output similar to this:

Fairy-Stockfish/src$ make help

To compile stockfish, type:

make target ARCH=arch [COMP=compiler] [COMPCXX=cxx]

Supported targets:

help                    > Display architecture details
build                   > Standard build
net                     > Download the default nnue net
profile-build           > Faster build (with profile-guided optimization)
strip                   > Strip executable
install                 > Install executable
clean                   > Clean up

Supported archs:

x86-64-vnni512          > x86 64-bit with vnni support 512bit wide
x86-64-vnni256          > x86 64-bit with vnni support 256bit wide
x86-64-avx512           > x86 64-bit with avx512 support
x86-64-bmi2             > x86 64-bit with bmi2 support
x86-64-avx2             > x86 64-bit with avx2 support
x86-64-sse41-popcnt     > x86 64-bit with sse41 and popcnt support
x86-64-modern           > common modern CPU, currently x86-64-sse41-popcnt
x86-64-ssse3            > x86 64-bit with ssse3 support
x86-64-sse3-popcnt      > x86 64-bit with sse3 and popcnt support
x86-64                  > x86 64-bit generic (with sse2 support)
x86-32-sse41-popcnt     > x86 32-bit with sse41 and popcnt support
x86-32-sse2             > x86 32-bit with sse2 support
x86-32                  > x86 32-bit generic (with mmx and sse support)
ppc-64                  > PPC 64-bit
ppc-32                  > PPC 32-bit
armv7                   > ARMv7 32-bit
armv7-neon              > ARMv7 32-bit with popcnt and neon
armv8                   > ARMv8 64-bit with popcnt and neon
e2k                     > Elbrus 2000
apple-silicon           > Apple silicon ARM64
general-64              > unspecified 64-bit
general-32              > unspecified 32-bit

Supported compilers:

gcc                     > Gnu compiler (default)
mingw                   > Gnu compiler with MinGW under Windows
clang                   > LLVM Clang compiler
icc                     > Intel compiler
ndk                     > Google NDK to cross-compile for Android

Simple examples. If you don't know what to do, you likely want to run:

make -j build ARCH=x86-64  (A portable, slow compile for 64-bit systems)
make -j build ARCH=x86-32  (A portable, slow compile for 32-bit systems)

Advanced examples, for experienced users looking for performance:

make    help  ARCH=x86-64-bmi2
make -j profile-build ARCH=x86-64-bmi2 COMP=gcc COMPCXX=g++-9.0
make -j build ARCH=x86-64-ssse3 COMP=clang

-------------------------------
Specify a supported architecture with the ARCH option for more details

-------------------------------
Embed and enable NNUE by default:

make build ARCH=x86-64 nnue=yes

-------------------------------
Version for large boards:

make build ARCH=x86-64 COMP=gcc largeboards=yes

Include all variants (adds Game of the Amazons):

make build ARCH=x86-64 largeboards=yes all=yes 

This is the Fairy Stockfish engine, so it has some more options (such as support for large boards). Follow the directions and compile Stockfish in the way you want. A simple example of what I use is make profile-build ARCH=x86-64-bmi2 COMP=mingw

After you compile Stockfish into the exe file, remember to strip the file with strip stockfish.exe as this will cut the file size by about half. While Stockfish files may not seem very large, the amount of space engines take up can add up very quickly, especially if you keep older versions on hand for historical reasons. I currently have over 16 GB of engines on my computer, and some people may not be able to spare as much space for engines. After stripping stockfish.exe, clean up unnecessary files with make clean; however, remember to rename or move the stockfish.exe file first, otherwise it too will be removed.

Like everything tech related, the information displayed in this post will one day be obsolete; however, as long as Stockfish has the make help option, you can find the necessary information to compile the engine. After all, the point of this is more of to tell people where they can find potentially useful information instead of giving them a command to copy paste. This also results in anyone interested in this topic learning considerably more than if they were just copy pasting a command.