at master 3.1 kB view raw
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 ] 64 ++ lib.optionals (python.isPy3k && !stdenv.cc.isClang) [ "-DPYBIND11_CXX_STANDARD=-std=c++17" ]; 65 66 postBuild = '' 67 # build tests 68 make -j $NIX_BUILD_CORES 69 ''; 70 71 postInstall = '' 72 make install 73 # Symlink the CMake-installed headers to the location expected by setuptools 74 mkdir -p $out/include/${python.libPrefix} 75 ln -sf $out/include/pybind11 $out/include/${python.libPrefix}/pybind11 76 ''; 77 78 nativeCheckInputs = [ 79 catch 80 numpy 81 pytestCheckHook 82 ]; 83 84 disabledTestPaths = [ 85 # require dependencies not available in nixpkgs 86 "tests/test_embed/test_trampoline.py" 87 "tests/test_embed/test_interpreter.py" 88 # numpy changed __repr__ output of numpy dtypes 89 "tests/test_numpy_dtypes.py" 90 # no need to test internal packaging 91 "tests/extra_python_package/test_files.py" 92 # tests that try to parse setuptools stdout 93 "tests/extra_setuptools/test_setuphelper.py" 94 ]; 95 96 disabledTests = lib.optionals stdenv.hostPlatform.isDarwin [ 97 # expects KeyError, gets RuntimeError 98 # https://github.com/pybind/pybind11/issues/4243 99 "test_cross_module_exception_translator" 100 ]; 101 102 hardeningDisable = lib.optional stdenv.hostPlatform.isMusl "fortify"; 103 104 meta = with lib; { 105 homepage = "https://github.com/pybind/pybind11"; 106 changelog = "https://github.com/pybind/pybind11/blob/${src.rev}/docs/changelog.rst"; 107 description = "Seamless operability between C++11 and Python"; 108 mainProgram = "pybind11-config"; 109 longDescription = '' 110 Pybind11 is a lightweight header-only library that exposes 111 C++ types in Python and vice versa, mainly to create Python 112 bindings of existing C++ code. 113 ''; 114 license = licenses.bsd3; 115 maintainers = with maintainers; [ 116 yuriaisaka 117 dotlambda 118 ]; 119 }; 120}