Closed akiradeveloper closed 2 years ago
I am also experiencing this behavior. To get past it I installed protoc
as the error says to get it to work. Would like to know what caused this and if it can be fixed
Related to this, I expect that some people will also be seeing something similar to the following:
error: failed to run custom build command for `tonic-types v0.6.0 (/tonic/tonic-types)`
Caused by:
process didn't exit successfully: `/tonic/target/debug/build/tonic-types-124bdc186e7641a9/build-script-build` (exit status: 101)
--- stdout
Running: "/usr/bin/protoc" "--include_imports" "--include_source_info" "-o" "/tmp/prost-buildaQyv1g/prost-descriptor-set" "-I" "proto/" "proto/status.proto"
--- stderr
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Custom { kind: Other, error: "protoc failed: google/protobuf/any.proto: File not found.\nstatus.proto:19:1: Import \"google/protobuf/any.proto\" was not found or had errors.\nstatus.proto:46:12: \"google.protobuf.Any\" is not defined.\n" }', tonic-types/build.rs:2:71
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
In the case of said related error, as per https://stackoverflow.com/a/61368354 it means that one has protoc installed but not the protobuf resource files.
On Ubuntu, if you are installing via the official repos, make sure both are installed:
apt update && apt upgrade -y
apt install -y protobuf-compiler libprotobuf-dev
On Alpine Linux, if you are installing via the official repos, make sure both are installed:
apk add protoc protobuf-dev
Or alternatively, if the version of protobuf in the repositories is too old then you could instead fetch a specific newer version from GitHub releases page of protobuf, and extract it into /usr
. This is what we are doing currently in my company for a CI pipeline where we want a specific version of protobuf.
PROTOC_VERSION=3.20.1
PB_REL="https://github.com/protocolbuffers/protobuf/releases"
which zip || apt update && apt upgrade -y && apt install zip -y
curl -sSLO "$PB_REL/download/v$PROTOC_VERSION/protoc-$PROTOC_VERSION-linux-x86_64.zip"
unzip -o protoc-$PROTOC_VERSION-linux-x86_64.zip -d "/usr"
(On an ordinary end-user machine, or on a long living server, or similar, you would not want to extract stuff into /usr
like that but in our case we are doing so on an ephemeral Docker container, so to us in that case it does no harm.)
Generating protobuf via prost
now requires protoc
in the path (or you can pass in a FileDescriptorSet
). The related change is here https://github.com/tokio-rs/prost/pull/657. I believe though that tonic
didn't get its docs as updated as prost
's so I've opened this issue https://github.com/hyperium/tonic/issues/1049 that we can follow up on.
If you need help with how to get CI working you can also take a look at how tonic
and prost
both do it. I am going to close this issue, please feel free to reopen if you have any more questions.
It feels unfortunate and heavy to require protoc as a dep with tools such as buf[1] around with rust support. I have designed my projects to intentionally NOT require protoc as a dep. Now it must be added to support a single proto required for reflection?
@hexfusion protoc
has always been a requirement, before it was just included as a binary in the published crate. But thi is a big security issue and was removed. There is support for buf at https://docs.rs/protoc-gen-tonic/0.2.0/protoc_gen_tonic/
Thanks for the clarification.
Bug Report
Version
0.8
Platform
5.4.0-104-generic #118-Ubuntu SMP Wed Mar 2 19:02:41 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Crates
Description
After upgrading from 0.7 to 0.8, build started to fail with this message.
This seems to me the change https://github.com/hyperium/tonic/pull/1021 makes it require protoc for some reason.
Because my project was ok with tonic 0.7, this is kind of a bug.