Closed echochamber closed 1 year ago
Same, I was surprised that I can't generate protos from Buf as part of Bazel
The cli is included as a toolchain: @rules_buf//tools/buf:toolchain_type
Confirmed, this works fine and I am able to use it in my actions: https://github.com/aspect-build/rules_lint/blob/04eac8060760793a85b23d36c57e6f79dfbe772c/lint/buf.bzl
By the way, @com_google_protobuf//:protoc
is actually a bad example of how it should work - because that's a target and not a toolchain, everyone ends up having to re-compile protoc
from source all the time.
if anyone else wants to know the proper syntax for calling buf via bazel it's:
bazel run @rules_buf_toolchains//:buf -- [command to run and or flags]
bazel run @rules_buf_toolchains//:buf -- --version
should print the version
bazel run @rules_buf_toolchains//:buf -- config init
would init your config
Thanks to @srikrsna-buf for helping me on slack!
Similar to how "@com_google_protobuf//:protoc" is available to use as a tool for a genrule or buildscript via
"$(location @com_google_protobuf//:protoc)"
. I have a build script which would like to call buf directly (so it can use the thebuf generate
command). Currently my build script needs to use the local machines installation at/usr/local/bin/buf
rather than a version that is controlled/managed by bazel.