bufbuild / rules_buf

Bazel rules for Buf.
Apache License 2.0
47 stars 17 forks source link

Include the the buf cli binary as a target so it can be used as a tool for build scripts. #38

Closed echochamber closed 1 year ago

echochamber commented 1 year ago

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 the buf 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.

siennathesane commented 1 year ago

Same, I was surprised that I can't generate protos from Buf as part of Bazel

srikrsna-buf commented 1 year ago

The cli is included as a toolchain: @rules_buf//tools/buf:toolchain_type

alexeagle commented 1 year ago

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

alexeagle commented 1 year ago

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.

benmcginnis commented 3 months ago

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!