1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6
7 # build-system
8 cmake,
9 ninja,
10 pathspec,
11 scikit-build-core,
12
13 # dependencies
14 eigen,
15
16 # tests
17 pytestCheckHook,
18 numpy,
19 scipy,
20 torch,
21 tensorflow-bin,
22 jax,
23 jaxlib,
24
25 nanobind,
26}:
27buildPythonPackage rec {
28 pname = "nanobind";
29 version = "2.9.2";
30 pyproject = true;
31
32 src = fetchFromGitHub {
33 owner = "wjakob";
34 repo = "nanobind";
35 tag = "v${version}";
36 fetchSubmodules = true;
37 hash = "sha256-cC+sf2FUm1jdGMRdDoaQK8rjUVkWjn/53c1HQ5gsUWs=";
38 };
39
40 build-system = [
41 cmake
42 ninja
43 pathspec
44 scikit-build-core
45 ];
46
47 dependencies = [ eigen ];
48
49 dontUseCmakeBuildDir = true;
50
51 # nanobind check requires heavy dependencies such as tensorflow
52 # which are less than ideal to be imported in children packages that
53 # use it as build-system parameter.
54 doCheck = false;
55
56 preCheck = ''
57 # build tests
58 make -j $NIX_BUILD_CORES
59 '';
60
61 nativeCheckInputs = [
62 pytestCheckHook
63 numpy
64 scipy
65 torch
66 ]
67 ++ lib.optionals (lib.meta.availableOn stdenv.hostPlatform tensorflow-bin) [
68 tensorflow-bin
69 jax
70 jaxlib
71 ];
72
73 passthru.tests = {
74 pytest = nanobind.overridePythonAttrs { doCheck = true; };
75 };
76
77 meta = {
78 homepage = "https://github.com/wjakob/nanobind";
79 changelog = "https://github.com/wjakob/nanobind/blob/${src.tag}/docs/changelog.rst";
80 description = "Tiny and efficient C++/Python bindings";
81 longDescription = ''
82 nanobind is a small binding library that exposes C++ types in Python and
83 vice versa. It is reminiscent of Boost.Python and pybind11 and uses
84 near-identical syntax. In contrast to these existing tools, nanobind is
85 more efficient: bindings compile in a shorter amount of time, produce
86 smaller binaries, and have better runtime performance.
87 '';
88 license = lib.licenses.bsd3;
89 maintainers = with lib.maintainers; [ parras ];
90 };
91}