Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions nphash/_build_utils/_ffi_builders.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
21 changes: 12 additions & 9 deletions nphash/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Comment thread
datumbox marked this conversation as resolved.
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,
)

Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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]
Expand Down
Loading