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
This commit is contained in:
Jamie Magee
2026-03-29 21:16:25 -07:00
parent a52afa73af
commit 18a283c05f
+4 -1
View File
@@ -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"