1{ stdenv
2, lib
3, buildPythonPackage
4, pythonOlder
5, fetchFromGitHub
6, cmake
7, boost
8, eigen
9, python
10, catch
11, numpy
12, pytestCheckHook
13, libxcrypt
14}:
15
16buildPythonPackage rec {
17 pname = "pybind11";
18 version = "2.10.0";
19
20 src = fetchFromGitHub {
21 owner = "pybind";
22 repo = pname;
23 rev = "v${version}";
24 hash = "sha256-/X8DZPFsNrKGbhjZ1GFOj17/NU6p4R+saCW3pLKVNeA=";
25 };
26
27 postPatch = ''
28 sed -i "/^timeout/d" pyproject.toml
29 '';
30
31 nativeBuildInputs = [ cmake ];
32 buildInputs = lib.optionals (pythonOlder "3.9") [ libxcrypt ];
33
34 dontUseCmakeBuildDir = true;
35
36 cmakeFlags = [
37 "-DBoost_INCLUDE_DIR=${lib.getDev boost}/include"
38 "-DEIGEN3_INCLUDE_DIR=${lib.getDev eigen}/include/eigen3"
39 "-DBUILD_TESTING=on"
40 "-DPYTHON_EXECUTABLE:FILEPATH=${python.pythonForBuild.interpreter}"
41 ] ++ lib.optionals (python.isPy3k && !stdenv.cc.isClang) [
42 "-DPYBIND11_CXX_STANDARD=-std=c++17"
43 ];
44
45 postBuild = ''
46 # build tests
47 make -j $NIX_BUILD_CORES
48 '';
49
50 postInstall = ''
51 make install
52 # Symlink the CMake-installed headers to the location expected by setuptools
53 mkdir -p $out/include/${python.libPrefix}
54 ln -sf $out/include/pybind11 $out/include/${python.libPrefix}/pybind11
55 '';
56
57 checkInputs = [
58 catch
59 numpy
60 pytestCheckHook
61 ];
62
63 disabledTestPaths = [
64 # require dependencies not available in nixpkgs
65 "tests/test_embed/test_trampoline.py"
66 "tests/test_embed/test_interpreter.py"
67 # numpy changed __repr__ output of numpy dtypes
68 "tests/test_numpy_dtypes.py"
69 # no need to test internal packaging
70 "tests/extra_python_package/test_files.py"
71 # tests that try to parse setuptools stdout
72 "tests/extra_setuptools/test_setuphelper.py"
73 ];
74
75 meta = with lib; {
76 homepage = "https://github.com/pybind/pybind11";
77 changelog = "https://github.com/pybind/pybind11/blob/${src.rev}/docs/changelog.rst";
78 description = "Seamless operability between C++11 and Python";
79 longDescription = ''
80 Pybind11 is a lightweight header-only library that exposes
81 C++ types in Python and vice versa, mainly to create Python
82 bindings of existing C++ code.
83 '';
84 license = licenses.bsd3;
85 maintainers = with maintainers; [ yuriaisaka dotlambda ];
86 };
87}