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

Viewed 704

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:

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.

In my CMakeLists.txt I use the following CMake functions to find the 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.

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 (i.e. for cross compiling). 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.

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:

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)?

0 Answers
Related