Scripts

pyrat/scripts/build_wheel.py builds a portable wheel in one command, on every platform: build, repair, check (see Build).

Important

Tested on Windows only (rat-all v3.004.5, MSVC, vcpkg, MKL, CUDA 13). The Linux (auditwheel) and macOS (delocate) paths are written but have not been run yet.

Requirements

  • UV on PATH: it runs the script, the build and the repair tools, with the Python versions they need.

  • RAT built and installed, from one of the three sources below.

  • On Windows: an MSVC developer shell. With RAT linking Intel oneAPI MKL, load oneAPI’s environment first (setvars.bat, or set MKLROOT).

See Setup for the versions required.

Run

From a clone of the pyRat repository:

git clone https://gitlab.com/project-rat-extras/pyrat.git
cd pyrat

The script only needs Python’s standard library and pefile (read on Windows), which uv run installs. Pick where RAT comes from:

# A rat-all build (configured, built and installed)
uv run scripts/build_wheel.py --rat-all C:\path\to\rat-all\build -p 3.14 --stubs

# A vcpkg installation in classic mode (root given, VCPKG_ROOT, or vcpkg on PATH)
uv run scripts/build_wheel.py --vcpkg --triplet x64-linux-dynamic-release -p 3.13

# RAT installed under a prefix, its dependencies found by CMake
uv run scripts/build_wheel.py --prefix /opt/rat -p 3.13

The wheel ends up in wheelhouse/.

Options

Option

Meaning

--rat-all BUILD_DIR

A rat-all build directory. Its CMakeCache.txt gives the vcpkg toolchain, triplet and installed tree, and RAT’s install prefix: the wheel links exactly what RAT was built against, so the rat-all build and install directories must stay in place.

--vcpkg [ROOT]

A vcpkg installation in classic mode, with RAT installed in it or under --rat-prefix. Without ROOT: VCPKG_ROOT, then vcpkg on PATH.

--prefix DIR

RAT installed under DIR, its dependencies found by CMake.

--rat-prefix DIR

Where RAT is installed: overrides rat-all’s install prefix, or tells --vcpkg where RAT is when it is not in the vcpkg tree.

--triplet TRIPLET

vcpkg triplet for --vcpkg. Default: x64-windows-release on Windows, x64-linux-dynamic-release on Linux; none on macOS, where it must be given.

-p, --python PYTHON

Python version of the wheel. Default: the Python running the script.

-s, --stubs

Generate the .pyi stubs into the wheel.

-D NAME=VALUE

Extra CMake definition, repeatable (e.g. -D BLA_VENDOR=OpenBLAS, or the options of Manual build).

-o, --wheelhouse DIR

Output directory. Default: wheelhouse/ in the repository.

--no-repair

Keep the wheel as built: not portable, and not checked.

--no-check

Skip the import check.

uv run scripts/build_wheel.py --help prints the same list.

What it does

  1. Build: uv build --wheel for the requested Python, with Ninja as the default CMake generator (CMAKE_GENERATOR overrides it). CMake only compiles pyRat’s sources, RAT is linked, in build/<wheel tag>: a later build for the same Python only recompiles what changed.

  2. CUDA version (Windows): read from the CUDA runtime that RAT’s DLLs import (cudart64_13.dll gives 13), since RAT’s CMake package does not tell. Elsewhere it comes from rat-all’s RAT_ALL_ENABLE_CUDA. -D PYRAT2_CUDA_VERSION=... overrides both. The wheel reports it in pyrat --version and pyrat.meta.CUDA_VERSION.

  3. Repair: delvewheel, auditwheel or delocate, run with uvx, bundle the libraries found in the directories listed by build/<wheel tag>/pyrat_runtime.json: RAT, vcpkg, CUDA and MKL. On Windows with MKL from oneAPI, MKL’s CPU kernels (mkl_def, mkl_avx2, …), which MKL loads by name at runtime and no tool can see, are added explicitly, and the MKL DLL names are kept as they are so that they still find each other.

  4. Check: the wheel must contain the examples (and the stubs, with --stubs); it is then imported in a fresh environment without the build’s library directories, printing the pyRat, RAT and CUDA versions compiled into the module.

Note

With --rat-all and VTK, CMake may warn that “the detected C++ compiler (MSVC) is unsupported for correct builds under cross-compilation”: it concerns VTK’s own tools, which pyRat does not use.