diff --git a/nphash/_build_utils/_ffi_builders.py b/nphash/_build_utils/_ffi_builders.py index 5c1b068b..664a4c3b 100644 --- a/nphash/_build_utils/_ffi_builders.py +++ b/nphash/_build_utils/_ffi_builders.py @@ -1,17 +1,17 @@ """Compiler utilities for building CFFI extensions for the nphash library. This module provides specialised CFFI (C Foreign Function Interface) setup -functions and a custom distutils build_ext command. These components are +functions and a custom setuptools build_ext command. These components are designed to correctly compile C and C++ sources, including those requiring specific compiler flags for features like OpenMP and C++11, particularly for the BLAKE3 TBB (Threading Building Blocks) integration. """ -from distutils.command.build_ext import build_ext as _build_ext from pathlib import Path from typing import Any from cffi import FFI +from setuptools.command.build_ext import build_ext as _build_ext from nphash._build_utils._blake3_builder import ( _compile_blake3_simd_objects, diff --git a/nphash/build.py b/nphash/build.py index 7d863f70..c95061bd 100644 --- a/nphash/build.py +++ b/nphash/build.py @@ -10,11 +10,13 @@ This will generate the _bytesearchffi, _npblake2bffi, _npblake3ffi and _npsha256ffi extension modules, which can be imported from Python code. """ -import distutils.command.build_ext import os import tempfile -from distutils.dist import Distribution from pathlib import Path +from typing import Callable, cast + +import setuptools.command.build_ext +from setuptools.dist import Distribution from nphash._build_utils._config_builder import _get_build_config from nphash._build_utils._ffi_builders import ( @@ -52,37 +54,38 @@ def main() -> None: ffibuilder_sha256 = _get_npsha256_ffi(config, build_dir) if config.tbb_enabled: - # Patch distutils' build_ext to ensure -std=c++11 is added only for .cpp files during CFFI builds. + # Patch setuptools' build_ext to ensure -std=c++11 is added only for .cpp files during CFFI builds. # This is required for BLAKE3/TBB on macOS, and avoids breaking C builds. # Using setattr avoids mypy errors and keeps the patch local to this build process. - setattr(distutils.command.build_ext, "build_ext", _build_ext_with_cpp11) + setattr(setuptools.command.build_ext, "build_ext", _build_ext_with_cpp11) # Compile FFI Modules with target and temp dir print("Compiling CFFI extensions...") dist = Distribution() - build_ext_cmd = distutils.command.build_ext.build_ext(dist) + build_ext_cmd = setuptools.command.build_ext.build_ext(dist) build_ext_cmd.initialize_options() + get_ext_filename = cast(Callable[[str], str], build_ext_cmd.get_ext_filename) # Compile the CFFI extensions ffibuilder_bytesearch.compile( tmpdir=str(build_dir), - target=str(nphash_dir / build_ext_cmd.get_ext_filename("_bytesearchffi")), + target=str(nphash_dir / get_ext_filename("_bytesearchffi")), verbose=True, ) ffibuilder_blake2b.compile( tmpdir=str(build_dir), - target=str(nphash_dir / build_ext_cmd.get_ext_filename("_npblake2bffi")), + target=str(nphash_dir / get_ext_filename("_npblake2bffi")), verbose=True, ) ffibuilder_npblake3.compile( tmpdir=str(build_dir), - target=str(nphash_dir / build_ext_cmd.get_ext_filename("_npblake3ffi")), + target=str(nphash_dir / get_ext_filename("_npblake3ffi")), verbose=True, ) ffibuilder_sha256.compile( tmpdir=str(build_dir), - target=str(nphash_dir / build_ext_cmd.get_ext_filename("_npsha256ffi")), + target=str(nphash_dir / get_ext_filename("_npsha256ffi")), verbose=True, ) diff --git a/pyproject.toml b/pyproject.toml index 7f939ea4..46f98509 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,6 +23,7 @@ dev = [ "sphinx>=8.1", "sphinx-autodoc-typehints>=3.0", "sphinx_rtd_theme>=3.0", + "types-setuptools>=80.9" ] numpy = [ "numpy>=2.2" @@ -35,7 +36,7 @@ cffi = [ vernamveil = "vernamveil._cli:main" [build-system] -requires = ["setuptools>=68.1", "wheel"] +requires = ["setuptools", "wheel"] build-backend = "setuptools.build_meta" [tool.black]