Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
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; 29 30 # clang 16 defaults to C++17, which results in the use of aligned allocations by pybind11. 31 # libc++ supports aligned allocations via `posix_memalign`, which is available since 10.6, 32 # but clang has a check hard-coded requiring 10.13 because that’s when Apple first shipped a 33 # support for C++17 aligned allocations on macOS. 34 # Tell clang we’re targeting 10.13 on x86_64-darwin while continuing to use the default SDK. 35 stdenv' = 36 if stdenv.isDarwin && stdenv.isx86_64 then 37 python.stdenv.override (oldStdenv: { 38 buildPlatform = oldStdenv.buildPlatform // { 39 darwinMinVersion = "10.13"; 40 }; 41 targetPlatform = oldStdenv.targetPlatform // { 42 darwinMinVersion = "10.13"; 43 }; 44 hostPlatform = oldStdenv.hostPlatform // { 45 darwinMinVersion = "10.13"; 46 }; 47 }) 48 else 49 python.stdenv; 50in 51buildPythonPackage rec { 52 pname = "pybind11"; 53 version = "2.13.1"; 54 pyproject = true; 55 56 src = fetchFromGitHub { 57 owner = "pybind"; 58 repo = "pybind11"; 59 rev = "v${version}"; 60 hash = "sha256-sQUq39CmgsDEMfluKMrrnC5fio//pgExcyqJAE00UjU="; 61 }; 62 63 build-system = [ 64 cmake 65 ninja 66 setuptools 67 ]; 68 69 buildInputs = lib.optionals (pythonOlder "3.9") [ libxcrypt ]; 70 propagatedNativeBuildInputs = [ setupHook ]; 71 72 stdenv = stdenv'; 73 74 dontUseCmakeBuildDir = true; 75 76 # Don't build tests if not needed, read the doInstallCheck value at runtime 77 preConfigure = '' 78 if [ -n "$doInstallCheck" ]; then 79 cmakeFlagsArray+=("-DBUILD_TESTING=ON") 80 fi 81 ''; 82 83 cmakeFlags = [ 84 "-DBoost_INCLUDE_DIR=${lib.getDev boost}/include" 85 "-DEIGEN3_INCLUDE_DIR=${lib.getDev eigen}/include/eigen3" 86 ] ++ lib.optionals (python.isPy3k && !stdenv.cc.isClang) [ "-DPYBIND11_CXX_STANDARD=-std=c++17" ]; 87 88 postBuild = '' 89 # build tests 90 make -j $NIX_BUILD_CORES 91 ''; 92 93 postInstall = '' 94 make install 95 # Symlink the CMake-installed headers to the location expected by setuptools 96 mkdir -p $out/include/${python.libPrefix} 97 ln -sf $out/include/pybind11 $out/include/${python.libPrefix}/pybind11 98 ''; 99 100 nativeCheckInputs = [ 101 catch 102 numpy 103 pytestCheckHook 104 ]; 105 106 disabledTestPaths = [ 107 # require dependencies not available in nixpkgs 108 "tests/test_embed/test_trampoline.py" 109 "tests/test_embed/test_interpreter.py" 110 # numpy changed __repr__ output of numpy dtypes 111 "tests/test_numpy_dtypes.py" 112 # no need to test internal packaging 113 "tests/extra_python_package/test_files.py" 114 # tests that try to parse setuptools stdout 115 "tests/extra_setuptools/test_setuphelper.py" 116 ]; 117 118 disabledTests = lib.optionals stdenv.isDarwin [ 119 # expects KeyError, gets RuntimeError 120 # https://github.com/pybind/pybind11/issues/4243 121 "test_cross_module_exception_translator" 122 ]; 123 124 hardeningDisable = lib.optional stdenv.hostPlatform.isMusl "fortify"; 125 126 meta = with lib; { 127 homepage = "https://github.com/pybind/pybind11"; 128 changelog = "https://github.com/pybind/pybind11/blob/${src.rev}/docs/changelog.rst"; 129 description = "Seamless operability between C++11 and Python"; 130 mainProgram = "pybind11-config"; 131 longDescription = '' 132 Pybind11 is a lightweight header-only library that exposes 133 C++ types in Python and vice versa, mainly to create Python 134 bindings of existing C++ code. 135 ''; 136 license = licenses.bsd3; 137 maintainers = with maintainers; [ 138 yuriaisaka 139 dotlambda 140 ]; 141 }; 142}