1{ 2 stdenv, 3 lib, 4 buildPythonPackage, 5 pythonOlder, 6 fetchFromGitHub, 7 cmake, 8 ninja, 9 setuptools, 10 boost, 11 eigen, 12 python, 13 catch, 14 numpy, 15 pytestCheckHook, 16 libxcrypt, 17 makeSetupHook, 18}: 19let 20 setupHook = makeSetupHook { 21 name = "pybind11-setup-hook"; 22 substitutions = { 23 out = placeholder "out"; 24 pythonInterpreter = python.pythonOnBuildForHost.interpreter; 25 pythonIncludeDir = "${python}/include/python${python.pythonVersion}"; 26 pythonSitePackages = "${python}/${python.sitePackages}"; 27 }; 28 } ./setup-hook.sh; 29in 30buildPythonPackage rec { 31 pname = "pybind11"; 32 version = "2.13.6"; 33 pyproject = true; 34 35 src = fetchFromGitHub { 36 owner = "pybind"; 37 repo = "pybind11"; 38 tag = "v${version}"; 39 hash = "sha256-SNLdtrOjaC3lGHN9MAqTf51U9EzNKQLyTMNPe0GcdrU="; 40 }; 41 42 build-system = [ 43 cmake 44 ninja 45 setuptools 46 ]; 47 48 buildInputs = lib.optionals (pythonOlder "3.9") [ libxcrypt ]; 49 propagatedNativeBuildInputs = [ setupHook ]; 50 51 dontUseCmakeBuildDir = true; 52 53 # Don't build tests if not needed, read the doInstallCheck value at runtime 54 preConfigure = '' 55 if [ -n "$doInstallCheck" ]; then 56 cmakeFlagsArray+=("-DBUILD_TESTING=ON") 57 fi 58 ''; 59 60 cmakeFlags = [ 61 "-DBoost_INCLUDE_DIR=${lib.getDev boost}/include" 62 "-DEIGEN3_INCLUDE_DIR=${lib.getDev eigen}/include/eigen3" 63 ] ++ lib.optionals (python.isPy3k && !stdenv.cc.isClang) [ "-DPYBIND11_CXX_STANDARD=-std=c++17" ]; 64 65 postBuild = '' 66 # build tests 67 make -j $NIX_BUILD_CORES 68 ''; 69 70 postInstall = '' 71 make install 72 # Symlink the CMake-installed headers to the location expected by setuptools 73 mkdir -p $out/include/${python.libPrefix} 74 ln -sf $out/include/pybind11 $out/include/${python.libPrefix}/pybind11 75 ''; 76 77 nativeCheckInputs = [ 78 catch 79 numpy 80 pytestCheckHook 81 ]; 82 83 disabledTestPaths = [ 84 # require dependencies not available in nixpkgs 85 "tests/test_embed/test_trampoline.py" 86 "tests/test_embed/test_interpreter.py" 87 # numpy changed __repr__ output of numpy dtypes 88 "tests/test_numpy_dtypes.py" 89 # no need to test internal packaging 90 "tests/extra_python_package/test_files.py" 91 # tests that try to parse setuptools stdout 92 "tests/extra_setuptools/test_setuphelper.py" 93 ]; 94 95 disabledTests = lib.optionals stdenv.hostPlatform.isDarwin [ 96 # expects KeyError, gets RuntimeError 97 # https://github.com/pybind/pybind11/issues/4243 98 "test_cross_module_exception_translator" 99 ]; 100 101 hardeningDisable = lib.optional stdenv.hostPlatform.isMusl "fortify"; 102 103 meta = with lib; { 104 homepage = "https://github.com/pybind/pybind11"; 105 changelog = "https://github.com/pybind/pybind11/blob/${src.rev}/docs/changelog.rst"; 106 description = "Seamless operability between C++11 and Python"; 107 mainProgram = "pybind11-config"; 108 longDescription = '' 109 Pybind11 is a lightweight header-only library that exposes 110 C++ types in Python and vice versa, mainly to create Python 111 bindings of existing C++ code. 112 ''; 113 license = licenses.bsd3; 114 maintainers = with maintainers; [ 115 yuriaisaka 116 dotlambda 117 ]; 118 }; 119}