From 18a283c05f5ace80cf393b60c199daa7764483c0 Mon Sep 17 00:00:00 2001 From: Jamie Magee Date: Sun, 29 Mar 2026 21:16:25 -0700 Subject: [PATCH] onnxruntime: fix cross-compilation Three things break the cross build: - doCheck was true, so CMake tried to build tests and fetch GTest. FETCHCONTENT_FULLY_DISCONNECTED blocks the download, and the tests can't run on the build machine anyway. Disable doCheck when host != build. - pythonSupport defaulted to true, but FindPython runs the build-platform Python, which can't find target-platform NumPy headers. Default to false when not canExecute. - protobuf was only in nativeBuildInputs (for protoc), so the linker found the build-platform libprotobuf-lite.so. Add it to buildInputs too. Resolves NixOS#462791 --- pkgs/by-name/on/onnxruntime/package.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkgs/by-name/on/onnxruntime/package.nix b/pkgs/by-name/on/onnxruntime/package.nix index b01633221af1..08514fbd6c7c 100644 --- a/pkgs/by-name/on/onnxruntime/package.nix +++ b/pkgs/by-name/on/onnxruntime/package.nix @@ -21,7 +21,7 @@ protobuf, microsoft-gsl, darwinMinVersionHook, - pythonSupport ? true, + pythonSupport ? (stdenv.buildPlatform.canExecute stdenv.hostPlatform), cudaSupport ? config.cudaSupport, ncclSupport ? cudaSupport && cudaPackages.nccl.meta.available, rocmSupport ? config.rocmSupport, @@ -165,6 +165,7 @@ effectiveStdenv.mkDerivation (finalAttrs: { libpng nlohmann_json microsoft-gsl + protobuf zlib ] ++ lib.optionals (lib.meta.availableOn effectiveStdenv.hostPlatform cpuinfo) [ @@ -313,6 +314,8 @@ effectiveStdenv.mkDerivation (finalAttrs: { !( cudaSupport || rocmSupport + # cross-compiled test binaries can't execute on the build platform + || (effectiveStdenv.hostPlatform != effectiveStdenv.buildPlatform) || builtins.elem effectiveStdenv.buildPlatform.system [ # aarch64-linux fails cpuinfo test, because /sys/devices/system/cpu/ does not exist in the sandbox "aarch64-linux"