Manual build

Scripts only chains standard tools. This page describes them, for a build without the script, and the CMake options of the project, for a superbuild.

Without the script

Build

The build alone, against RAT installed under a prefix:

PYRAT_STUBS=1 uv build --wheel --python 3.14 -C cmake.define.CMAKE_PREFIX_PATH=/opt/rat

-C cmake.define.<NAME>=<VALUE> passes any CMake definition (a vcpkg toolchain, a triplet, the options below). PYRAT_STUBS=1 in the environment turns the stubs on: it adds numpy and pybind11-stubgen to the build requirements and sets PYRAT2_STUBS. pip install . builds the same way.

pybind11 and scikit-build-core come from the isolated build environment (pyproject.toml), never from vcpkg: a vcpkg-installed pybind11 would bring vcpkg’s own Python, and the module would be built for the wrong interpreter.

Repair

The wheel built above only holds pyRat. CMake lists the directories of the libraries it links in build/<wheel tag>/pyrat_runtime.json:

{
    "runtime_dirs": [
        "C:/path/to/rat/bin",
        "C:/path/to/vcpkg_installed/x64-windows-release/bin",
        "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v13.0/bin/x64"
    ],
    "mkl_bin": null
}

mkl_bin is the directory of an MKL found outside vcpkg (Windows only). Give these directories to the repair tool:

For Windows:

uvx delvewheel repair <wheel> -w wheelhouse --add-path "<dir1>;<dir2>;..."

For Linux:

LD_LIBRARY_PATH="<dir1>:<dir2>:$LD_LIBRARY_PATH" uvx --with patchelf auditwheel repair <wheel> -w wheelhouse

For macOS:

DYLD_LIBRARY_PATH="<dir1>:<dir2>:$DYLD_LIBRARY_PATH" uvx --from delocate delocate-wheel -w wheelhouse <wheel>

With an MKL from oneAPI on Windows, delvewheel also needs MKL’s CPU kernels (--include) and the MKL names kept (--no-mangle): the script works these out, which is a good reason to use it.

CMake options

Option

Default

Meaning

PYRAT2_COMMON, PYRAT2_DMSH, PYRAT2_MAT, PYRAT2_MATH, PYRAT2_MLFMM, PYRAT2_NL, PYRAT2_MODELS

ON

Build the bindings of one Rat library each, and define the preprocessor macro of the same name for the sources. Dependencies are switched on as needed (Models needs MLFMM and Math; Distmesh, Materials, Math and MLFMM need Common). In rat-all, PYRAT2_NL follows RAT_ALL_ENABLE_NL_SOLVER.

PYRAT2_STUBS

OFF

Generate the .pyi stubs with pybind11-stubgen after each build and install them next to the module (pyrat/py.typed marks the package as typed).

PYRAT2_BUILD_TESTING

OFF

Register the Python tests with CTest (see Tests).

PYRAT2_INSTALL

ON, OFF nested

Install the module with cmake --install. Off when nested in a superbuild such as rat-all, whose install tree holds the RAT libraries only.

PYRAT2_PCH

ON

Precompile the prelude header every source includes first.

PYRAT2_NATIVE_ARCH

OFF

-march=native (GCC, Clang): only for a build that never leaves the machine, a wheel built with it stops with “illegal instruction” on an older CPU.

PYRAT2_CUDA_VERSION

detected

CUDA major version RAT was built with, reported by the module; empty without CUDA.

PYRAT2_RUNTIME_DIRS

empty

Extra runtime library directories (;-separated), added to pyrat_runtime.json and to the tests’ PYRAT_DLL_DIRS. PYRAT2_TEST_DLL_DIRS, its former name, is still read.

PYRAT2_TEST_PYTHON

the build’s Python

Interpreter that runs the tests: it needs numpy, and the same minor version as the module.

In a superbuild

rat-all configures pyRat with add_subdirectory: the module is built next to RAT, not installed, and with PYRAT2_BUILD_TESTING the CTest suite checks that the bindings still match the RAT libraries. The build tree is not a wheel: to import the module from it on Windows, point PYRAT_DLL_DIRS at the RAT, vcpkg, CUDA and MKL DLL directories (os.pathsep-separated); import pyrat adds them with os.add_dll_directory before loading the module. The CTest tests set it themselves.