microsoft / onnxruntime

ONNX Runtime: cross-platform, high performance ML inferencing and training accelerator
https://onnxruntime.ai
MIT License
14.51k stars 2.9k forks source link

[Build] Can't build on Arch using protobuf packages #22569

Closed vlovich closed 4 hours ago

vlovich commented 5 hours ago

Describe the issue

Arch by default installs the latest protobuf which is incompatible due to removal of ReleaseCleared in v26 & above (as noted in #21308 ). So I install the protobuf-21 package which is the preferred version for ONNX. I then set the protoc path to ONNX_CUSTOM_PROTOC_EXECUTABLE=/usr/bin/protoc-21 but then that fails because the build picks up the /usr/include/google/protobuf which is incompatible - the protobuf-21 package installs the includes into /usr/include/protobuf-21/google/protobuf so as not to conflict with any other version. I'm at a loss as to how to get ONNX to compile against the system protobuf-21 package (i.e. how do I override the protobuf library include path).

Urgency

No response

Target platform

Arch Linux

Build script

NVCC_CCBIN='/usr/bin/g++-13' CUDA_PATH=/opt/cuda PATH=/opt/cuda/bin:$PATH CC=gcc-13 CXX=g++-13 ./build.sh --use_cuda --cudnn_home /usr --cuda_home /opt/cuda --cmake_extra_defines CMAKE_CUDA_ARCHITECTURES=75 --cmake_extra_defines onnxruntime_ENABLE_NVTX_PROFILE=ON --cmake_extra_defines ONNX_CUSTOM_PROTOC_EXECUTABLE=/usr/bin/protoc-21 --enable_cuda_line_info

Error / output

If building against normal protobuf,

~/projects/onnxruntime/onnxruntime/core/graph/graph.cc:1291:58: error: ‘class google::protobuf::RepeatedPtrField<onnx::SparseTensorProto>’ has no member named ‘ReleaseCleared’
 1291 |       delete graph_proto_->mutable_sparse_initializer()->ReleaseCleared();

If building against protobuf-21 (--cmake_extra_defines ONNX_CUSTOM_PROTOC_EXECUTABLE=/usr/bin/protoc-21)

In file included from ~/projects/onnxruntime/build/Linux/Debug/_deps/onnx-build/onnx/onnx-ml.pb.cc:4:
~/projects/onnxruntime/build/Linux/Debug/_deps/onnx-build/onnx/onnx-ml.pb.h:12:2: error: #error This file was generated by a newer version of protoc which is
   12 | #error This file was generated by a newer version of protoc which is
      |  ^~~~~
~/projects/onnxruntime/build/Linux/Debug/_deps/onnx-build/onnx/onnx-ml.pb.h:13:2: error: #error incompatible with your Protocol Buffer headers. Please update
   13 | #error incompatible with your Protocol Buffer headers. Please update
      |  ^~~~~
~/projects/onnxruntime/build/Linux/Debug/_deps/onnx-build/onnx/onnx-ml.pb.h:14:2: error: #error your headers.
   14 | #error your headers.
      |  ^~~~~

Visual Studio Version

No response

GCC / Compiler Version

gcc-13

vlovich commented 4 hours ago

Found the magic variable I think: --cmake_extra_defines PROTOBUF_INCLUDE_DIRS=/usr/include/protobuf-21/