2020-04-24 23:36:52 +00:00
|
|
|
|
{ stdenv
|
|
|
|
|
, lib
|
|
|
|
|
, buildPythonPackage
|
2022-10-30 15:09:59 +00:00
|
|
|
|
, pythonOlder
|
2020-04-24 23:36:52 +00:00
|
|
|
|
, fetchFromGitHub
|
|
|
|
|
, cmake
|
2024-04-21 15:54:59 +00:00
|
|
|
|
, ninja
|
|
|
|
|
, setuptools
|
2021-12-26 17:43:05 +00:00
|
|
|
|
, boost
|
2021-06-28 23:13:55 +00:00
|
|
|
|
, eigen
|
|
|
|
|
, python
|
2020-04-24 23:36:52 +00:00
|
|
|
|
, catch
|
|
|
|
|
, numpy
|
2022-02-10 20:34:41 +00:00
|
|
|
|
, pytestCheckHook
|
2022-10-30 15:09:59 +00:00
|
|
|
|
, libxcrypt
|
2023-04-29 16:46:19 +00:00
|
|
|
|
, makeSetupHook
|
|
|
|
|
}: let
|
|
|
|
|
setupHook = makeSetupHook {
|
|
|
|
|
name = "pybind11-setup-hook";
|
|
|
|
|
substitutions = {
|
|
|
|
|
out = placeholder "out";
|
2023-11-16 04:20:00 +00:00
|
|
|
|
pythonInterpreter = python.pythonOnBuildForHost.interpreter;
|
2023-04-29 16:46:19 +00:00
|
|
|
|
pythonIncludeDir = "${python}/include/python${python.pythonVersion}";
|
|
|
|
|
pythonSitePackages = "${python}/${python.sitePackages}";
|
|
|
|
|
};
|
|
|
|
|
} ./setup-hook.sh;
|
2023-11-16 04:20:00 +00:00
|
|
|
|
|
|
|
|
|
# clang 16 defaults to C++17, which results in the use of aligned allocations by pybind11.
|
|
|
|
|
# libc++ supports aligned allocations via `posix_memalign`, which is available since 10.6,
|
|
|
|
|
# but clang has a check hard-coded requiring 10.13 because that’s when Apple first shipped a
|
|
|
|
|
# support for C++17 aligned allocations on macOS.
|
|
|
|
|
# Tell clang we’re targeting 10.13 on x86_64-darwin while continuing to use the default SDK.
|
|
|
|
|
stdenv' = if stdenv.isDarwin && stdenv.isx86_64
|
|
|
|
|
then python.stdenv.override (oldStdenv: {
|
|
|
|
|
buildPlatform = oldStdenv.buildPlatform // { darwinMinVersion = "10.13"; };
|
|
|
|
|
targetPlatform = oldStdenv.targetPlatform // { darwinMinVersion = "10.13"; };
|
|
|
|
|
hostPlatform = oldStdenv.hostPlatform // { darwinMinVersion = "10.13"; };
|
|
|
|
|
})
|
|
|
|
|
else python.stdenv;
|
2023-04-29 16:46:19 +00:00
|
|
|
|
in buildPythonPackage rec {
|
2020-04-24 23:36:52 +00:00
|
|
|
|
pname = "pybind11";
|
2024-04-21 15:54:59 +00:00
|
|
|
|
version = "2.12.0";
|
|
|
|
|
pyproject = true;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
|
owner = "pybind";
|
2024-04-21 15:54:59 +00:00
|
|
|
|
repo = "pybind11";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
rev = "v${version}";
|
2024-04-21 15:54:59 +00:00
|
|
|
|
hash = "sha256-DVkI5NxM5uME9m3PFYVpJOOa2j+yjL6AJn76fCTv2nE=";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
|
postPatch = ''
|
2024-04-21 15:54:59 +00:00
|
|
|
|
substituteInPlace pyproject.toml \
|
|
|
|
|
--replace-fail "timeout=300" ""
|
2022-09-09 14:08:57 +00:00
|
|
|
|
'';
|
|
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
|
build-system = [
|
|
|
|
|
cmake
|
|
|
|
|
ninja
|
|
|
|
|
setuptools
|
|
|
|
|
];
|
|
|
|
|
|
2022-10-30 15:09:59 +00:00
|
|
|
|
buildInputs = lib.optionals (pythonOlder "3.9") [ libxcrypt ];
|
2024-04-21 15:54:59 +00:00
|
|
|
|
propagatedNativeBuildInputs = [ setupHook ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
2023-11-16 04:20:00 +00:00
|
|
|
|
stdenv = stdenv';
|
|
|
|
|
|
2021-06-28 23:13:55 +00:00
|
|
|
|
dontUseCmakeBuildDir = true;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
2022-12-17 10:02:37 +00:00
|
|
|
|
# Don't build tests if not needed, read the doInstallCheck value at runtime
|
|
|
|
|
preConfigure = ''
|
|
|
|
|
if [ -n "$doInstallCheck" ]; then
|
|
|
|
|
cmakeFlagsArray+=("-DBUILD_TESTING=ON")
|
|
|
|
|
fi
|
|
|
|
|
'';
|
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
|
cmakeFlags = [
|
2021-12-26 17:43:05 +00:00
|
|
|
|
"-DBoost_INCLUDE_DIR=${lib.getDev boost}/include"
|
|
|
|
|
"-DEIGEN3_INCLUDE_DIR=${lib.getDev eigen}/include/eigen3"
|
2020-04-24 23:36:52 +00:00
|
|
|
|
] ++ lib.optionals (python.isPy3k && !stdenv.cc.isClang) [
|
2021-06-28 23:13:55 +00:00
|
|
|
|
"-DPYBIND11_CXX_STANDARD=-std=c++17"
|
2020-04-24 23:36:52 +00:00
|
|
|
|
];
|
|
|
|
|
|
2021-06-28 23:13:55 +00:00
|
|
|
|
postBuild = ''
|
|
|
|
|
# build tests
|
2022-10-21 18:38:19 +00:00
|
|
|
|
make -j $NIX_BUILD_CORES
|
2021-06-28 23:13:55 +00:00
|
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
2021-06-28 23:13:55 +00:00
|
|
|
|
postInstall = ''
|
|
|
|
|
make install
|
2020-04-24 23:36:52 +00:00
|
|
|
|
# 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
|
|
|
|
|
'';
|
|
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
|
nativeCheckInputs = [
|
2021-06-28 23:13:55 +00:00
|
|
|
|
catch
|
2020-04-24 23:36:52 +00:00
|
|
|
|
numpy
|
2022-02-10 20:34:41 +00:00
|
|
|
|
pytestCheckHook
|
2020-04-24 23:36:52 +00:00
|
|
|
|
];
|
|
|
|
|
|
2022-02-10 20:34:41 +00:00
|
|
|
|
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"
|
2022-04-15 01:41:22 +00:00
|
|
|
|
# tests that try to parse setuptools stdout
|
|
|
|
|
"tests/extra_setuptools/test_setuphelper.py"
|
2022-02-10 20:34:41 +00:00
|
|
|
|
];
|
2021-06-28 23:13:55 +00:00
|
|
|
|
|
2023-08-10 07:59:29 +00:00
|
|
|
|
disabledTests = lib.optionals stdenv.isDarwin [
|
2023-01-20 10:41:00 +00:00
|
|
|
|
# expects KeyError, gets RuntimeError
|
|
|
|
|
# https://github.com/pybind/pybind11/issues/4243
|
|
|
|
|
"test_cross_module_exception_translator"
|
|
|
|
|
];
|
|
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
|
hardeningDisable = lib.optional stdenv.hostPlatform.isMusl "fortify";
|
|
|
|
|
|
2020-08-20 17:08:02 +00:00
|
|
|
|
meta = with lib; {
|
2020-04-24 23:36:52 +00:00
|
|
|
|
homepage = "https://github.com/pybind/pybind11";
|
2022-04-27 09:35:20 +00:00
|
|
|
|
changelog = "https://github.com/pybind/pybind11/blob/${src.rev}/docs/changelog.rst";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
description = "Seamless operability between C++11 and Python";
|
2024-04-21 15:54:59 +00:00
|
|
|
|
mainProgram = "pybind11-config";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
longDescription = ''
|
|
|
|
|
Pybind11 is a lightweight header-only library that exposes
|
|
|
|
|
C++ types in Python and vice versa, mainly to create Python
|
|
|
|
|
bindings of existing C++ code.
|
|
|
|
|
'';
|
2020-08-20 17:08:02 +00:00
|
|
|
|
license = licenses.bsd3;
|
2021-06-28 23:13:55 +00:00
|
|
|
|
maintainers = with maintainers; [ yuriaisaka dotlambda ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
|
|
|
|
}
|