1{
2 lib,
3 stdenv,
4 apple-sdk_11,
5 buildPythonPackage,
6 darwinMinVersionHook,
7 fetchFromGitHub,
8 pythonOlder,
9
10 # build-system
11 cmake,
12 ninja,
13 pathspec,
14 scikit-build-core,
15
16 # dependencies
17 eigen,
18
19 # tests
20 pytestCheckHook,
21 numpy,
22 scipy,
23 torch,
24 tensorflow-bin,
25 jax,
26 jaxlib,
27}:
28buildPythonPackage rec {
29 pname = "nanobind";
30 version = "2.2.0";
31 pyproject = true;
32
33 src = fetchFromGitHub {
34 owner = "wjakob";
35 repo = "nanobind";
36 rev = "refs/tags/v${version}";
37 hash = "sha256-HtZfpMVz/7VMVrFg48IkitK6P3tA+swOeaLLiKguXXk=";
38 fetchSubmodules = true;
39 };
40
41 disabled = pythonOlder "3.8";
42
43 build-system = [
44 cmake
45 ninja
46 pathspec
47 scikit-build-core
48 ];
49
50 dependencies = [ eigen ];
51
52 buildInputs = lib.optionals stdenv.hostPlatform.isDarwin [
53 # error: aligned deallocation function of type 'void (void *, std::align_val_t) noexcept' is only available on macOS 10.13 or newer
54 (darwinMinVersionHook "10.13")
55
56 apple-sdk_11
57 ];
58
59 dontUseCmakeBuildDir = true;
60
61 preCheck = ''
62 # TODO: added 2.2.0, re-enable on next bump
63 # https://github.com/wjakob/nanobind/issues/754
64 # "generated stubs do not match their references"
65 # > -import tensorflow.python.framework.ops
66 # > +import tensorflow
67 rm tests/test_ndarray_ext.pyi.ref
68
69 # build tests
70 make -j $NIX_BUILD_CORES
71 '';
72
73 nativeCheckInputs =
74 [
75 pytestCheckHook
76 numpy
77 scipy
78 torch
79 ]
80 ++ lib.optionals (!(builtins.elem stdenv.hostPlatform.system tensorflow-bin.meta.badPlatforms)) [
81 tensorflow-bin
82 jax
83 jaxlib
84 ];
85
86 meta = {
87 homepage = "https://github.com/wjakob/nanobind";
88 changelog = "https://github.com/wjakob/nanobind/blob/${src.rev}/docs/changelog.rst";
89 description = "Tiny and efficient C++/Python bindings";
90 longDescription = ''
91 nanobind is a small binding library that exposes C++ types in Python and
92 vice versa. It is reminiscent of Boost.Python and pybind11 and uses
93 near-identical syntax. In contrast to these existing tools, nanobind is
94 more efficient: bindings compile in a shorter amount of time, produce
95 smaller binaries, and have better runtime performance.
96 '';
97 license = lib.licenses.bsd3;
98 maintainers = with lib.maintainers; [ parras ];
99 };
100}