python313Packages.pybind11: 2.13.6 -> 3.0.1 (#442242)

This commit is contained in:
Emily
2025-09-15 22:43:03 +01:00
committed by GitHub
2 changed files with 60 additions and 69 deletions
@@ -6,13 +6,14 @@
fetchFromGitHub,
cmake,
ninja,
setuptools,
scikit-build-core,
pybind11,
boost,
eigen,
python,
catch2,
numpy,
pytestCheckHook,
pytest,
libxcrypt,
makeSetupHook,
}:
@@ -29,84 +30,83 @@ let
in
buildPythonPackage rec {
pname = "pybind11";
version = "2.13.6";
version = "3.0.1";
pyproject = true;
src = fetchFromGitHub {
owner = "pybind";
repo = "pybind11";
tag = "v${version}";
hash = "sha256-SNLdtrOjaC3lGHN9MAqTf51U9EzNKQLyTMNPe0GcdrU=";
hash = "sha256-ZiwNGsE1FOkhnWv/1ib1akhQ4FZvrXRCDnnBZoPp6r4=";
};
build-system = [
cmake
ninja
setuptools
pybind11.passthru.scikit-build-core-no-tests
];
buildInputs = [
# Used only for building tests - something we do even when cross
# compiling.
catch2
boost
eigen
];
buildInputs = lib.optionals (pythonOlder "3.9") [ libxcrypt ];
propagatedNativeBuildInputs = [ setupHook ];
dontUseCmakeBuildDir = true;
nativeCheckInputs = [
numpy
pytest
];
# Don't build tests if not needed, read the doInstallCheck value at runtime
preConfigure = ''
if [ -n "$doInstallCheck" ]; then
cmakeFlagsArray+=("-DBUILD_TESTING=ON")
fi
'';
pypaBuildFlags = [
# Keep the build directory around to run the tests.
"-Cbuild-dir=build"
];
cmakeFlags = [
"-DBoost_INCLUDE_DIR=${lib.getDev boost}/include"
"-DCATCH_INCLUDE_DIR=${lib.getDev catch2}/include/catch2"
"-DEIGEN3_INCLUDE_DIR=${lib.getDev eigen}/include/eigen3"
]
++ lib.optionals (python.isPy3k && !stdenv.cc.isClang) [ "-DPYBIND11_CXX_STANDARD=-std=c++17" ];
# Always build tests, because even when cross compiling building the tests
# is another confirmation that everything is OK.
(lib.cmakeBool "BUILD_TESTING" true)
postBuild = ''
# build tests
make -j $NIX_BUILD_CORES
'';
# Override the `PYBIND11_NOPYTHON = true` in `pyproject.toml`. This
# is required to build the tests.
(lib.cmakeBool "PYBIND11_NOPYTHON" false)
];
dontUseCmakeConfigure = true;
ninjaFlags = [
"-C"
"build"
];
checkTarget = "check";
checkPhase = "ninjaCheckPhase";
# Make the headers and CMake/pkg-config files inside the wheel
# discoverable. This simulates the effect of the `pybind11[global]`
# installation but works better for our build.
postInstall = ''
make install
# Symlink the CMake-installed headers to the location expected by setuptools
mkdir -p $out/include/${python.libPrefix}
ln -sf $out/include/pybind11 $out/include/${python.libPrefix}/pybind11
ln -s $out/${python.sitePackages}/pybind11/{include,share} $out/
'';
nativeCheckInputs = [
catch2
numpy
pytestCheckHook
];
disabledTestPaths = [
# require dependencies not available in nixpkgs
"tests/test_embed/test_trampoline.py"
"tests/test_embed/test_interpreter.py"
# numpy changed __repr__ output of numpy dtypes
"tests/test_numpy_dtypes.py"
# no need to test internal packaging
"tests/extra_python_package/test_files.py"
# tests that try to parse setuptools stdout
"tests/extra_setuptools/test_setuphelper.py"
];
disabledTests = lib.optionals stdenv.hostPlatform.isDarwin [
# expects KeyError, gets RuntimeError
# https://github.com/pybind/pybind11/issues/4243
"test_cross_module_exception_translator"
];
postCheck = ''
make cpptest
'';
passthru = {
# scikit-build-core's tests depend upon pybind11, and hence introduce
# infinite recursion. To avoid this, we define here a scikit-build-core
# derivation that doesn't depend on pybind11, and use it for pybind11's
# build-system.
scikit-build-core-no-tests = scikit-build-core.overridePythonAttrs {
doCheck = false;
};
};
hardeningDisable = lib.optional stdenv.hostPlatform.isMusl "fortify";
meta = with lib; {
meta = {
homepage = "https://github.com/pybind/pybind11";
changelog = "https://github.com/pybind/pybind11/blob/${src.rev}/docs/changelog.rst";
description = "Seamless operability between C++11 and Python";
@@ -116,8 +116,8 @@ buildPythonPackage rec {
C++ types in Python and vice versa, mainly to create Python
bindings of existing C++ code.
'';
license = licenses.bsd3;
maintainers = with maintainers; [
license = lib.licenses.bsd3;
maintainers = with lib.maintainers; [
yuriaisaka
dotlambda
];
@@ -1,18 +1,9 @@
scikitBuildFlagsHook() {
OLD_IFS="$IFS"
IFS=';'
concatTo flagsArray cmakeFlags cmakeFlagsArray
local args=()
if [[ -n "$SKBUILD_CMAKE_ARGS" ]]; then
read -ra existing_args <<< "$SKBUILD_CMAKE_ARGS"
args+=("${existing_args[@]}")
fi
args+=($cmakeFlags)
args+=("${cmakeFlagsArray[@]}")
export SKBUILD_CMAKE_ARGS="${args[*]}"
IFS="$OLD_IFS"
unset OLD_IFS
for arg in "${flagsArray[@]}"; do
appendToVar pypaBuildFlags "-Ccmake.args=$arg"
done
}
preConfigureHooks+=(scikitBuildFlagsHook)