18 , pythonSupport ? false
25 # When enabling Python support a wheel is made and stored in a `dist` output.
26 # This wheel is then installed in a separate derivation.
28 assert pythonSupport -> lib.versionOlder protobuf.version "3.20";
32 # Note: keep URL in sync with `cmake/external/abseil-cpp.cmake`
34 url = "https://github.com/abseil/abseil-cpp/archive/refs/tags/20211102.0.zip";
35 sha256 = "sha256-pFZ/8C+spnG5XjHTFbqxi0K2xvGmDpHG6oTlohQhEsI=";
38 stdenv.mkDerivation rec {
39 pname = "onnxruntime";
42 src = fetchFromGitHub {
46 sha256 = "sha256-wwllEemiHTp9aJcCd1gsTS4WUVMp5wW+4i/+6DzmAeM=";
47 fetchSubmodules = true;
51 # Use dnnl from nixpkgs instead of submodules
53 name = "system-dnnl.patch";
54 url = "https://aur.archlinux.org/cgit/aur.git/plain/system-dnnl.diff?h=python-onnxruntime&id=0185531906bda3a9aba93bbb0f3dcfeb0ae671ad";
55 sha256 = "sha256-58RBrQnAWNtc/1pmFs+PkZ6qCsL1LfMY3P0exMKzotA=";
62 python3Packages.python
64 ] ++ lib.optionals pythonSupport (with python3Packages; [
79 ] ++ lib.optionals pythonSupport [
82 python3Packages.pybind11
85 # TODO: build server, and move .so's to lib output
86 # Python's wheel is stored in a separate dist output
87 outputs = [ "out" "dev" ] ++ lib.optionals pythonSupport [ "dist" ];
89 enableParallelBuilding = true;
91 cmakeDir = "../cmake";
94 "-Donnxruntime_PREFER_SYSTEM_LIB=ON"
95 "-Donnxruntime_BUILD_SHARED_LIB=ON"
96 "-Donnxruntime_ENABLE_LTO=ON"
97 "-Donnxruntime_BUILD_UNIT_TESTS=ON"
98 "-Donnxruntime_USE_PREINSTALLED_EIGEN=ON"
99 "-Donnxruntime_USE_MPI=ON"
100 "-Deigen_SOURCE_PATH=${eigen.src}"
101 "-Donnxruntime_USE_DNNL=YES"
102 ] ++ lib.optionals pythonSupport [
103 "-Donnxruntime_ENABLE_PYTHON=ON"
109 substituteInPlace cmake/external/abseil-cpp.cmake \
110 --replace "${abseil.url}" "${abseil}"
112 substituteInPlace cmake/libonnxruntime.pc.cmake.in \
113 --replace '$'{prefix}/@CMAKE_INSTALL_ @CMAKE_INSTALL_
116 postBuild = lib.optionalString pythonSupport ''
117 ${python3Packages.python.interpreter} ../setup.py bdist_wheel
121 # perform parts of `tools/ci_build/github/linux/copy_strip_binary.sh`
122 install -m644 -Dt $out/include \
123 ../include/onnxruntime/core/framework/provider_options.h \
124 ../include/onnxruntime/core/providers/cpu/cpu_provider_factory.h \
125 ../include/onnxruntime/core/session/onnxruntime_*.h
130 tests = lib.optionalAttrs pythonSupport {
131 python = python3Packages.onnxruntime;
136 description = "Cross-platform, high performance scoring engine for ML models";
138 ONNX Runtime is a performance-focused complete scoring engine
139 for Open Neural Network Exchange (ONNX) models, with an open
140 extensible architecture to continually address the latest developments
141 in AI and Deep Learning. ONNX Runtime stays up to date with the ONNX
142 standard with complete implementation of all ONNX operators, and
143 supports all ONNX releases (1.2+) with both future and backwards
146 homepage = "https://github.com/microsoft/onnxruntime";
147 changelog = "https://github.com/microsoft/onnxruntime/releases/tag/v${version}";
148 # https://github.com/microsoft/onnxruntime/blob/master/BUILD.md#architectures
149 platforms = platforms.unix;
150 license = licenses.mit;
151 maintainers = with maintainers; [ jonringer puffnfresh ck3d ];