1{ stdenv
2, lib
3, buildPythonPackage
4, fetchFromGitHub
5, fetchpatch
6, python
7, pytest
8, cmake
9, catch
10, numpy
11, eigen
12, scipy
13}:
14
15buildPythonPackage rec {
16 pname = "pybind11";
17 version = "2.4.3";
18
19 src = fetchFromGitHub {
20 owner = "pybind";
21 repo = pname;
22 rev = "v${version}";
23 sha256 = "0k89w4bsfbpzw963ykg1cyszi3h3nk393qd31m6y46pcfxkqh4rd";
24 };
25
26 nativeBuildInputs = [ cmake ];
27
28 buildInputs = [ catch ];
29
30 cmakeFlags = [
31 "-DEIGEN3_INCLUDE_DIR=${eigen}/include/eigen3"
32 ] ++ lib.optionals (python.isPy3k && !stdenv.cc.isClang) [
33 # Enable some tests only on Python 3. The "test_string_view" test
34 # 'testTypeError: string_view16_chars(): incompatible function arguments'
35 # fails on Python 2.
36 "-DPYBIND11_CPP_STANDARD=-std=c++17"
37 ];
38
39 dontUseSetuptoolsBuild = true;
40 dontUsePipInstall = true;
41 dontUseSetuptoolsCheck = true;
42
43 patches = [
44 ./0001-Find-include-directory.patch
45 ];
46
47 postPatch = ''
48 substituteInPlace pybind11/__init__.py --subst-var-by include "$out/include"
49 '';
50
51 preFixup = ''
52 pushd ..
53 export PYBIND11_USE_CMAKE=1
54 setuptoolsBuildPhase
55 pipInstallPhase
56 # Symlink the CMake-installed headers to the location expected by setuptools
57 mkdir -p $out/include/${python.libPrefix}
58 ln -sf $out/include/pybind11 $out/include/${python.libPrefix}/pybind11
59 popd
60 '';
61
62 checkInputs = [
63 pytest
64 numpy
65 scipy
66 ];
67
68 meta = {
69 homepage = https://github.com/pybind/pybind11;
70 description = "Seamless operability between C++11 and Python";
71 longDescription = ''
72 Pybind11 is a lightweight header-only library that exposes
73 C++ types in Python and vice versa, mainly to create Python
74 bindings of existing C++ code.
75 '';
76 license = lib.licenses.bsd3;
77 maintainers = [ lib.maintainers.yuriaisaka ];
78 };
79}