MaaAssistantArknights / MaaDeps

Collection of build scripts to build MAA dependencies for popular platforms
10 stars 10 forks source link

Need Help with `protobuf` for `maa-onnxruntime` #26

Open KokeCacao opened 1 month ago

KokeCacao commented 1 month ago

TLDR: In configuring -- Configuring x64-linux with python ./build.py --target x64-linux, I got a protobuf dependency error and later a linking error. Dug the issue for a while without a clear solution, thus appreciate some guidance.

Running python ./build.py --target x64-linux caused the error:

CMake Error at scripts/cmake/vcpkg_execute_required_process.cmake:127

Here is the log config-x64-linux-out.log

CMake Error at onnxruntime.cmake:225 (target_link_libraries):
  Target "onnxruntime" links to:

    protobuf::libprotobuf-lite

  but the target was not found.  Possible reasons include:

    * There is a typo in the target name.
    * A find_package call is missing for an IMPORTED target.
    * An ALIAS target is missing.

Call Stack (most recent call first):
  CMakeLists.txt:1759 (include)

CMake Error at xxxx/vcpkg/installed/x64-linux/share/onnx/ONNXTargets.cmake:69 (set_target_properties):
  The link interface of target "ONNX::onnx_proto" contains:

    protobuf::libprotobuf

  but the target was not found.  Possible reasons include:

    * There is a typo in the target name.
    * A find_package call is missing for an IMPORTED target.
    * An ALIAS target is missing.

Call Stack (most recent call first):
  xxxxvcpkg/installed/x64-linux/share/onnx/ONNXConfig.cmake:12 (include)
  xxxx/vcpkg/scripts/buildsystems/vcpkg.cmake:857 (_find_package)
  external/onnxruntime_external_deps.cmake:481 (find_package)
  CMakeLists.txt:586 (include)

After looking at it, I found that although ${Protobuf_FOUND} = 1, almost all other variables (including ${Protobuf_INCLUDE_DIRS}, ${Protobuf_LIBRARIES}, ${Protobuf_VERSION} are unset. This is very strange to me. A potential solution I found is to add a line include(FindProtobuf) in front of set_target_properties code.

# Add this
include(FindProtobuf)
find_package(Protobuf REQUIRED)
# Finish Add this

# Create imported target ONNX::onnx_proto
add_library(ONNX::onnx_proto STATIC IMPORTED)

target_link_libraries(ONNX::onnx_proto INTERFACE
  "${Protobuf_LIBRARIES}"
)

set_target_properties(ONNX::onnx_proto PROPERTIES
  INTERFACE_COMPILE_DEFINITIONS "ONNX_NAMESPACE=onnx;ONNX_ML=1"
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
  INTERFACE_LINK_LIBRARIES "protobuf::libprotobuf"
)

This solves the compilation but there are still some undefined reference issues related to

function `google::protobuf::internal::TcParser::FastSS1(google::protobuf::MessageLite*, char const*, google::protobuf::internal::ParseContext*, google::protobuf::internal::TcFieldData, google::protobuf::internal::TcParseTableBase const*, unsigned long)'

and

`absl::lts_20240116::FailedPreconditionError(std::basic_string_view<char, std::char_traits<char> >)'

I am not sure whether adding include(FindProtobuf) is in the correct path. And I don't understand the purpose and complications of your .patch files applied to maa-onnxruntime. It would be very helpful if you can provide some guidance or insights into the issue. Thanks!

dantmnf commented 1 month ago

The latest commit is known broken, use 2024-05-30 tag for now.

KokeCacao commented 1 month ago

The latest commit is known broken, use 2024-05-30 tag for now.

The 2024-05-30 tag might also have some issue? (maa-fastdeploy)

Run Build Command(s): /usr/local/vcpkg-downloads/tools/ninja/1.10.2-linux/ninja -v -v -j25 install
[1/71] /usr/bin/c++  -I/workspaces/MaaAssistantArknights/MaaDeps/vcpkg/buildtrees/maa-fastdeploy/src/773373fa8b-35db4875e8.clean -fPIC -g -std=gnu++17 -MD -MT CMakeFiles/FastDeploy_Vision_Common.dir/fastdeploy/vision/common/processors/center_crop.cc.o -MF CMakeFiles/FastDeploy_Vision_Common.dir/fastdeploy/vision/common/processors/center_crop.cc.o.d -o CMakeFiles/FastDeploy_Vision_Common.dir/fastdeploy/vision/common/processors/center_crop.cc.o -c /workspaces/MaaAssistantArknights/MaaDeps/vcpkg/buildtrees/maa-fastdeploy/src/773373fa8b-35db4875e8.clean/fastdeploy/vision/common/processors/center_crop.cc
FAILED: CMakeFiles/FastDeploy_Vision_Common.dir/fastdeploy/vision/common/processors/center_crop.cc.o 
/usr/bin/c++  -I/workspaces/MaaAssistantArknights/MaaDeps/vcpkg/buildtrees/maa-fastdeploy/src/773373fa8b-35db4875e8.clean -fPIC -g -std=gnu++17 -MD -MT CMakeFiles/FastDeploy_Vision_Common.dir/fastdeploy/vision/common/processors/center_crop.cc.o -MF CMakeFiles/FastDeploy_Vision_Common.dir/fastdeploy/vision/common/processors/center_crop.cc.o.d -o CMakeFiles/FastDeploy_Vision_Common.dir/fastdeploy/vision/common/processors/center_crop.cc.o -c /workspaces/MaaAssistantArknights/MaaDeps/vcpkg/buildtrees/maa-fastdeploy/src/773373fa8b-35db4875e8.clean/fastdeploy/vision/common/processors/center_crop.cc
In file included from /workspaces/MaaAssistantArknights/MaaDeps/vcpkg/buildtrees/maa-fastdeploy/src/773373fa8b-35db4875e8.clean/fastdeploy/vision/common/processors/mat.h:16,
                 from /workspaces/MaaAssistantArknights/MaaDeps/vcpkg/buildtrees/maa-fastdeploy/src/773373fa8b-35db4875e8.clean/fastdeploy/vision/common/processors/base.h:18,
                 from /workspaces/MaaAssistantArknights/MaaDeps/vcpkg/buildtrees/maa-fastdeploy/src/773373fa8b-35db4875e8.clean/fastdeploy/vision/common/processors/center_crop.h:17,
                 from /workspaces/MaaAssistantArknights/MaaDeps/vcpkg/buildtrees/maa-fastdeploy/src/773373fa8b-35db4875e8.clean/fastdeploy/vision/common/processors/center_crop.cc:15:
/workspaces/MaaAssistantArknights/MaaDeps/vcpkg/buildtrees/maa-fastdeploy/src/773373fa8b-35db4875e8.clean/fastdeploy/vision/common/processors/utils.h:19:10: fatal error: opencv2/core/core.hpp: No such file or directory
   19 | #include "opencv2/core/core.hpp"
      |          ^~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
KokeCacao commented 1 month ago

The latest commit is known broken, use 2024-05-30 tag for now.

The 2024-05-30 tag might also have some issue? (maa-fastdeploy)

Run Build Command(s): /usr/local/vcpkg-downloads/tools/ninja/1.10.2-linux/ninja -v -v -j25 install
[1/71] /usr/bin/c++  -I/workspaces/MaaAssistantArknights/MaaDeps/vcpkg/buildtrees/maa-fastdeploy/src/773373fa8b-35db4875e8.clean -fPIC -g -std=gnu++17 -MD -MT CMakeFiles/FastDeploy_Vision_Common.dir/fastdeploy/vision/common/processors/center_crop.cc.o -MF CMakeFiles/FastDeploy_Vision_Common.dir/fastdeploy/vision/common/processors/center_crop.cc.o.d -o CMakeFiles/FastDeploy_Vision_Common.dir/fastdeploy/vision/common/processors/center_crop.cc.o -c /workspaces/MaaAssistantArknights/MaaDeps/vcpkg/buildtrees/maa-fastdeploy/src/773373fa8b-35db4875e8.clean/fastdeploy/vision/common/processors/center_crop.cc
FAILED: CMakeFiles/FastDeploy_Vision_Common.dir/fastdeploy/vision/common/processors/center_crop.cc.o 
/usr/bin/c++  -I/workspaces/MaaAssistantArknights/MaaDeps/vcpkg/buildtrees/maa-fastdeploy/src/773373fa8b-35db4875e8.clean -fPIC -g -std=gnu++17 -MD -MT CMakeFiles/FastDeploy_Vision_Common.dir/fastdeploy/vision/common/processors/center_crop.cc.o -MF CMakeFiles/FastDeploy_Vision_Common.dir/fastdeploy/vision/common/processors/center_crop.cc.o.d -o CMakeFiles/FastDeploy_Vision_Common.dir/fastdeploy/vision/common/processors/center_crop.cc.o -c /workspaces/MaaAssistantArknights/MaaDeps/vcpkg/buildtrees/maa-fastdeploy/src/773373fa8b-35db4875e8.clean/fastdeploy/vision/common/processors/center_crop.cc
In file included from /workspaces/MaaAssistantArknights/MaaDeps/vcpkg/buildtrees/maa-fastdeploy/src/773373fa8b-35db4875e8.clean/fastdeploy/vision/common/processors/mat.h:16,
                 from /workspaces/MaaAssistantArknights/MaaDeps/vcpkg/buildtrees/maa-fastdeploy/src/773373fa8b-35db4875e8.clean/fastdeploy/vision/common/processors/base.h:18,
                 from /workspaces/MaaAssistantArknights/MaaDeps/vcpkg/buildtrees/maa-fastdeploy/src/773373fa8b-35db4875e8.clean/fastdeploy/vision/common/processors/center_crop.h:17,
                 from /workspaces/MaaAssistantArknights/MaaDeps/vcpkg/buildtrees/maa-fastdeploy/src/773373fa8b-35db4875e8.clean/fastdeploy/vision/common/processors/center_crop.cc:15:
/workspaces/MaaAssistantArknights/MaaDeps/vcpkg/buildtrees/maa-fastdeploy/src/773373fa8b-35db4875e8.clean/fastdeploy/vision/common/processors/utils.h:19:10: fatal error: opencv2/core/core.hpp: No such file or directory
   19 | #include "opencv2/core/core.hpp"
      |          ^~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

Submitted PR to fix above OpenCV issue.

Note: In addition to the documentation, here are additional things required to compile. Consider pack them into the container in the future.

1. apt install libopencv-dev (not sure if needed)
2. apt install gcc-12 g++-12
3. sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 12 --slave /usr/bin/g++ g++ /usr/bin/g++-12
4. also upgrade cmake
5. apt install libprotobuf-dev libprotoc23 protobuf-c-compiler (not sure if needed)
6. patch .cmake (https://github.com/MaaAssistantArknights/FastDeploy/pull/7)
7. pip install pyelftools
8. apt install patchelf
MistEO commented 1 month ago

https://github.com/MaaXYZ/MaaDeps/actions/runs/10226168335 我遇到了相同的问题,但这似乎是由于 vcpkg 的更新导致的。我的 onnxruntime 并没有修改(