Coverage for cpp_inference_ext/setup.py: 100%
15 statements
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-22 12:55 +0000
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-22 12:55 +0000
1"""Build script for the optional cpp_inference accelerator - never a hard
2dependency (see development/Problems.md #32 and inference/exported_model.py's
3_linear_batched() for the fallback contract). Install with:
5 pip install -e cpp_inference_ext/
7Requires a C++ compiler (MSVC on Windows, via the "Desktop development
8with C++" / Build Tools workload - `cl.exe` must resolve, e.g. by running
9this from a "Developer Command Prompt" or after vcvarsall.bat) and
10pybind11 (`requirements/lock/build-ext.txt`).
12`AQ_SANITIZE=address,undefined` builds with AddressSanitizer and UBSan (GCC/Clang; CI job `cpp-sanitizers`, #380), and
13`AQ_ASAN_CANARY=1` adds `asan_canary()`, a deliberate heap overflow that proves the sanitizer is live.
14"""
16import os
18from pybind11.setup_helpers import Pybind11Extension, build_ext
19from setuptools import setup
22def extension_options(environ=os.environ) -> dict:
23 options: dict = {"cxx_std": 17}
24 sanitizers = environ.get("AQ_SANITIZE", "").strip()
25 if sanitizers:
26 flag = f"-fsanitize={sanitizers}"
27 options["extra_compile_args"] = [flag, "-fno-sanitize-recover=all", "-fno-omit-frame-pointer", "-g", "-O1"]
28 options["extra_link_args"] = [flag]
29 if environ.get("AQ_ASAN_CANARY") == "1":
30 options["define_macros"] = [("AQ_ASAN_CANARY", "1")]
31 return options
34ext_modules = [
35 Pybind11Extension(
36 "cpp_inference",
37 ["src/linear_batched.cpp"],
38 **extension_options(),
39 ),
40]
42setup(
43 name="cpp_inference",
44 version="0.1.0",
45 description="Optional C++/pybind11 accelerator for inference/exported_model.py's batched linear layer",
46 ext_modules=ext_modules,
47 cmdclass={"build_ext": build_ext},
48)