Reputation: 1246
I am working on a linux open-embedded project (Yocto), and I need to use gRPC.
Below are my recipes that try to invoke the gRPC python module. (grpcio-tools)
In local.conf
TOOLCHAIN_HOST_TASK_append = " nativesdk-python3-grpcio-tools"
TOOLCHAIN_TARGET_TASK_append = " python3-grpcio-tools"
Then is my .bb file, I try to add it as Depends.
DEPENDS += " python3-grpcio-tools"
do_compile(){
python3 -m grpc_tools.protoc -I ${S} --python_out=. --grpc_python_out=. ${S}/tests/rcu_ser.proto
}
But it fails to find the python module during bitbake. Below is the failure code:
Please teach me how to invoke the python module during bitbake. Thank you very much.
Upvotes: 3
Views: 6162
Reputation: 11
This thread helped me so I thought I would share a complete .bb recipe that's working for cross-compiling a proto file into the necessary files for a Petalinux / Yocto Zeus gRPC server using python. I'm no bitbake expert. This installs the resulting pb2 files in /usr/bin and compiles them using python3-grpcio-tools for the target device (which may be an older/different version than what you have on your build machine). The proto file includes protobuf definitions as well as rpc definitions, hence the generated _pb2_grpc.py file.
SUMMARY = "My summary."
SECTION = "PETALINUX/apps"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
SRC_URI = " \
file://my_proto.proto \
"
inherit python3native
RDEPENDS_${PN} = " \
python3-core \
python3-protobuf \
python3-grpcio \
"
DEPENDS += " \
python3-grpcio-tools-native \
"
do_compile() {
python3 -m grpc.tools.protoc -I${WORKDIR} --python_out=${WORKDIR}/. --grpc_python_out=${WORKDIR}/. ${WORKDIR}/my_proto.proto
}
do_install() {
install -Dm 0755 ${WORKDIR}/my_proto_pb2.py ${D}/${bindir}/my_proto_pb2.py
install -Dm 0755 ${WORKDIR}/my_proto_pb2_grpc.py ${D}/${bindir}/my_proto_pb2_grpc.py
}
FILES_${PN} = " \
${bindir}/my_proto_pb2.py \
${bindir}/my_proto_pb2_grpc.py \
"
Upvotes: 1
Reputation: 1474
If you want to use dependency on the host during compile time you must always depend to native version of a recipe. Modify your recipe as following:
inherit python3native
DEPENDS += "python3-grpcio-tools-native"
RDEPENDS_${PN} += "python3 python3-grpcio-tools"
Upvotes: 4