The maintained Windows build is the one used by our GitLab CI. It builds the Python module, tests it, and creates a wheel.
Install Visual Studio Community Edition with the x64 C++ toolchain from visualstudio.microsoft.com. The current build instructions are tested with Visual Studio 2022.
Install CMake 3.20 or newer (Windows x64 installer) from cmake.org/download and Ninja from ninja-build.org.
Prepare an isolated Python environment with the Python build dependencies.
Required to regenerate the Python API wrappers under auto/Wrap/, which is
needed for any change that touches the C++ API. Download from
swig.org/download.html, unpack the ZIP,
and add the folder containing swig.exe (e.g. C:\swigwin) to PATH.
buildcache.exe or another compiler launcher reduces rebuild times.
The BornAgain dependencies are installed into two prefixes:
C:/opt/vcpkg/installed/x64-windows for standard libraries and C:/opt/x64
for the MLZ-maintained ones.
Standard libraries (fftw3 and gsl) are installed via
vcpkg into
C:/opt/vcpkg/installed/x64-windows, as the CI does. Follow the official
vcpkg setup guide, install it under C:/opt/vcpkg, and run:
C:/opt/vcpkg/vcpkg.exe install fftw3 gsl --triplet x64-windows
Alternatively, the prebuilt zips from the WinLibs archive
can be unpacked into C:/opt/x64/include and C:/opt/x64/lib.
Relevant WinLibs packages are:
libfftw3.win64.zipgsl_*_win64_shared.zipMLZ-specific libraries must be installed into C:/opt/x64:
libcerf: download cerfcpp-*-win64.zip from the latest
libcerf release, then unpack it into C:/opt/x64.
libformfactor 0.5.1 or newer: download formfactor-*-win64.zip from
the latest libformfactor release, then unpack it into
C:/opt/x64.
libheinz 4.1 or newer: download the source from the latest libheinz release and build:
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX="C:/opt/x64"
cmake --build . --config Release
cmake --install . --config Release
Make sure the executable directories for Python, CMake, Ninja, and SWIG are
available in PATH. The dependency prefixes are passed to CMake through
CMAKE_PREFIX_PATH; their runtime DLL directories must also be visible when
running tests.
For example:
$PYTHON = "C:/path/to/venv/Scripts/python.exe"
$OPT_DIR = "C:/opt/x64"
$VCPKG_DIR = "C:/opt/vcpkg/installed/x64-windows"
$SWIG_DIR = "C:/swigwin"
$PYTHON_DIR = Split-Path "$PYTHON"
$env:PATH = "$PYTHON_DIR;$SWIG_DIR;$VCPKG_DIR/bin;$OPT_DIR/lib;$env:PATH"
If CMake cannot find headers or libraries, check that
C:/opt/x64/include, C:/opt/x64/lib, and the vcpkg prefix are covered by the
CMAKE_PREFIX_PATH used below.
Open a PowerShell with the Visual Studio x64 build environment loaded. One way
is to use Visual Studio’s x64 Native Tools shell. The CI does the equivalent
with vswhere and Enter-VsDevShell.
Set the local paths:
$PYTHON = "C:/path/to/venv/Scripts/python.exe"
$OPT_DIR = "C:/opt/x64"
$VCPKG_DIR = "C:/opt/vcpkg/installed/x64-windows"
$BUILD_DIR = Join-Path $PWD "build"
Create and enter the build directory:
mkdir -Force "$BUILD_DIR"
cd "$BUILD_DIR"
Configure with Ninja:
cmake .. -G "Ninja" -DCMAKE_BUILD_TYPE=Release `
-DCMAKE_PREFIX_PATH="$OPT_DIR;$VCPKG_DIR" `
-DPython3_EXECUTABLE="$PYTHON" `
-DBA_PY_PACK=ON
When using buildcache.exe, add
-DCMAKE_CXX_COMPILER_LAUNCHER="buildcache.exe" to the command.
cmake --build . --config Release --parallel 20
cmake --build . --config Release --target ba_wheel
Before running tests, make the freshly built Python package and DLLs visible:
$env:PYTHONPATH = "$BUILD_DIR/py/src/"
$PYTHON_DIR = Split-Path "$PYTHON"
$env:PATH = "$PYTHON_DIR;$VCPKG_DIR/bin;$OPT_DIR/lib;$env:PATH"
Then run:
ctest -C Release --parallel 20 --output-on-failure
The wheel is placed under build/py/wheel/.