简体   繁体   English

构建依赖于 grpc 的 Yocto bitbake 配方,grpc-native 失败说 grpc_cpp_plugin 不存在

[英]Building a Yocto bitbake recipe, which depends on grpc, grpc-native fails saying the the grpc_cpp_plugin does not exist

I am developing a C++ component that uses gRPC and use the following definitions in my bitbase recipe (Yocto dunfell ) to build it with CMake:我正在开发一个使用 gRPC 的 C++ 组件,并在我的 bitbase 配方 (Yocto dunfell ) 中使用以下定义来使用 CMake 构建它:

DEPENDS += "\
    grpc \
    grpc-native \
    ...
    "

inherit cmake pkgconfig

I included grpc-native to be able to use the protoc compiler to generate stubs and grpc to link my component with the gRPC libraries for the target host.我包含grpc-native以便能够使用protoc编译器生成存根和grpc以将我的组件与目标主机的 gRPC 库链接起来。

In my CMakeLists.txt I use the following CMake functions to find the libraries/cpp-plugin在我的 CMakeLists.txt 中,我使用以下 CMake 函数来查找 libraries/cpp-plugin

find_package(Protobuf REQUIRED)
find_package(gRPC CONFIG REQUIRED)
find_program(GRPC_CPP_PLUGIN grpc_cpp_plugin REQUIRED)

However, building the recipe fails with the following error:但是,构建配方失败并出现以下错误:

| CMake Error at /home/jayjay/build-master/build/tmp/work/corei7-64-mbient-linux/mycomponent/git-r0/recipe-sysroot/usr/lib/cmake/grpc/gRPCTargets.cmake:197 (message):
|   The imported target "gRPC::grpc_cpp_plugin" references the file
|
|      "/home/jayjay/build-master/build/tmp/work/corei7-64-mbient-linux/mycomponent/git-r0/recipe-sysroot/usr/bin/grpc_cpp_plugin"
|
|   but this file does not exist.

And it is true, the grpc_cpp_plugin does not exist in this directory, as well as all the other plugins like grpc_node_plugin , grpc_php_plugin , etc. However, these plugins exist in the corresponding "recipe-sysroot -native /usr/bin/" directory, which is correct as they must be compiled for the build-host (rather than the target host), so that they can be used with protoc to generate stubs.确实,这个目录中不存在grpc_cpp_plugin ,以及所有其他插件,如grpc_node_plugingrpc_php_plugin等。但是,这些插件存在于相应的“recipe-sysroot -native /usr/bin/”目录中,这是正确的,因为它们必须为构建主机(而不是目标主机)编译,以便它们可以与protoc一起使用以生成存根。

What I do not understand is, that why the existence of these plugin files are checked, although they are not created?我不明白的是,为什么检查这些插件文件的存在,尽管它们没有创建?

If I remove grpc from DEPENDS then everything works fine, unless the build host architecture is different from the target host architecture (ie for cross compiling).如果我从DEPENDS grpc一切正常,除非构建主机架构与目标主机架构不同(即交叉编译)。 In this case I get a linker error "file in wrong format", which is OK, as I used the libraries compiled for the build host (grpc-native) and not the target host.在这种情况下,我收到 linker 错误“文件格式错误”,这没关系,因为我使用的是为构建主机 (grpc-native) 而不是目标主机编译的库。

As a workaround I simply create all required plugin files in the desired directory like so:作为解决方法,我只需在所需目录中创建所有必需的插件文件,如下所示:

do_configure_prepend() {
  touch ${STAGING_BINDIR}/grpc_cpp_plugin
  touch ${STAGING_BINDIR}/grpc_csharp_plugin
  touch ${STAGING_BINDIR}/grpc_node_plugin
  ...
}

This works, as only the existence of the files is checked.这是可行的,因为只检查文件是否存在。 They are not used.他们没有被使用。

To be able to find the correct location of the directory with the "native" plugins I pass the following extra parameter to CMake:为了能够使用“本机”插件找到目录的正确位置,我将以下额外参数传递给 CMake:

EXTRA_OECMAKE = "\
    -DSTAGING_BINDIR_NATIVE=${STAGING_BINDIR_NATIVE} \
    "

Needless to say that this does not feel right.不用说,这感觉不对。

I do not really grasp what am I doing wrong here (sorry for the long explanation)?我真的不明白我在这里做错了什么(抱歉解释很长)?

I have a workaround for Yocto Gatesgarth and gRPC version 1.24.x.我有 Yocto Gatesgarth 和 gRPC 1.24.x 版的解决方法。

Basically I symlink the plugin binaries from recipe-sysroot-native/ to recipe-sysroot/ to make the CMake file happy.基本上,我将插件二进制文件从 recipe-sysroot-native/ 符号链接到 recipe-sysroot/ 以使 CMake 文件满意。

Excerpt from my recipe file for a custom software project with CMake and grpc:摘自我的自定义软件项目的配方文件,其中包含 CMake 和 grpc:

DEPENDS += "grpc"
DEPENDS += "grpc-native"

do_configure_prepend() {
    ln -f -s ${STAGING_BINDIR_NATIVE}/grpc_cpp_plugin ${STAGING_BINDIR}/grpc_cpp_plugin
    ln -f -s ${STAGING_BINDIR_NATIVE}/grpc_csharp_plugin ${STAGING_BINDIR}/grpc_csharp_plugin
    ln -f -s ${STAGING_BINDIR_NATIVE}/grpc_node_plugin ${STAGING_BINDIR}/grpc_node_plugin
    ln -f -s ${STAGING_BINDIR_NATIVE}/grpc_objective_c_plugin ${STAGING_BINDIR}/grpc_objective_c_plugin
    ln -f -s ${STAGING_BINDIR_NATIVE}/grpc_python_plugin ${STAGING_BINDIR}/grpc_python_plugin
    ln -f -s ${STAGING_BINDIR_NATIVE}/grpc_ruby_plugin ${STAGING_BINDIR}/grpc_ruby_plugin
    ln -f -s ${STAGING_BINDIR_NATIVE}/grpc_php_plugin ${STAGING_BINDIR}/grpc_php_plugin
}

Note that PROBABLY this will no longer work on later gRPC versions, as they seem to have fixed a lot of things regarding cross compilation in gRPC with version 1.35 and above (see oe-core changelog for grpc_*.bb).请注意,这可能不再适用于以后的 gRPC 版本,因为它们似乎已经修复了很多关于 1.35 及更高版本的 gRPC 中交叉编译的问题(请参阅 grpc_*.bb 的 oe-core 变更日志)。

Thanks goes out to all these sources!感谢所有这些来源!

Yocto Lists Yocto 列表

Another Yocto Mailinglist 另一个 Yocto 邮件列表

gRPC Issue on GitHub GitHub 上的 gRPC 问题

gRPC Pull request with one solution一种解决方案的 gRPC 拉取请求

gRPC Pull request with another solution gRPC Pull request with another solution

Solution is very simple: use kirkstone解决方案非常简单:使用 kirkstone

On dunfell, the gRPC recipe does not include https://github.com/grpc/grpc/pull/31525 which I believe fixes the build on Yocto.在 dunfell 上,gRPC 配方不包括https://github.com/grpc/grpc/pull/31525 ,我相信它修复了 Yocto 上的构建。 So technically you could also just update/patch/make your own gRPC recipe.所以从技术上讲,你也可以只更新/修补/制作你自己的 gRPC 配方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM