1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5
6 # build-system
7 cmake,
8 pybind11,
9 setuptools,
10
11 # buildInputs
12 abseil-cpp,
13 protobuf,
14 gtest,
15
16 # dependencies
17 ml-dtypes,
18 numpy,
19 typing-extensions,
20
21 # tests
22 google-re2,
23 nbval,
24 parameterized,
25 pillow,
26 pytestCheckHook,
27 tabulate,
28 writableTmpDirAsHomeHook,
29}:
30
31let
32 gtestStatic = gtest.override { static = true; };
33in
34buildPythonPackage rec {
35 pname = "onnx";
36 version = "1.19.0";
37 pyproject = true;
38
39 src = fetchFromGitHub {
40 owner = "onnx";
41 repo = "onnx";
42 tag = "v${version}";
43 hash = "sha256-dDc7ugzQHcArf9TRcF9Ofv16jc3gqhMWCZrYKJ7Udfw=";
44 };
45
46 build-system = [
47 cmake
48 protobuf
49 setuptools
50 ];
51
52 buildInputs = [
53 abseil-cpp
54 gtestStatic
55 pybind11
56 ];
57
58 dependencies = [
59 ml-dtypes
60 numpy
61 protobuf
62 typing-extensions
63 ];
64
65 nativeCheckInputs = [
66 google-re2
67 ml-dtypes
68 nbval
69 parameterized
70 pillow
71 pytestCheckHook
72 tabulate
73 writableTmpDirAsHomeHook
74 ];
75
76 preConfigure = ''
77 # Set CMAKE_INSTALL_LIBDIR to lib explicitly, because otherwise it gets set
78 # to lib64 and cmake incorrectly looks for the protobuf library in lib64
79 export CMAKE_ARGS="-DCMAKE_INSTALL_LIBDIR=lib -DONNX_USE_PROTOBUF_SHARED_LIBS=ON"
80 export CMAKE_ARGS+=" -Dgoogletest_STATIC_LIBRARIES=${gtestStatic}/lib/libgtest.a"
81 export ONNX_BUILD_TESTS=1
82 '';
83
84 preBuild = ''
85 export MAX_JOBS=$NIX_BUILD_CORES
86 '';
87
88 # The executables are just utility scripts that aren't too important
89 postInstall = ''
90 rm -r $out/bin
91 '';
92
93 # The setup.py does all the configuration
94 dontUseCmakeConfigure = true;
95
96 # detecting source dir as a python package confuses pytest
97 preCheck = ''
98 rm onnx/__init__.py
99 '';
100
101 enabledTestPaths = [
102 "onnx/test"
103 "examples"
104 ];
105
106 __darwinAllowLocalNetworking = true;
107
108 postCheck = ''
109 # run "cpp" tests
110 .setuptools-cmake-build/onnx_gtests
111 '';
112
113 pythonImportsCheck = [ "onnx" ];
114
115 meta = {
116 description = "Open Neural Network Exchange";
117 homepage = "https://onnx.ai";
118 changelog = "https://github.com/onnx/onnx/releases/tag/v${version}";
119 license = lib.licenses.asl20;
120 maintainers = with lib.maintainers; [ acairncross ];
121 };
122}