Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions buf/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library")

package(default_visibility = ["//visibility:public"])


toolchain_type(
name = "toolchain_type",
)

bzl_library(
name = "defs",
srcs = ["defs.bzl"],
Expand Down
27 changes: 27 additions & 0 deletions buf/internal/BUILD.dist.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
load("@bazel_skylib//rules:native_binary.bzl", "native_binary")
load("@rules_buf//buf/internal:toolchain.bzl", "buf_toolchain")

native_binary(
name = "buf",
src = "bin/buf%BIN_SUFFIX%",
out = "buf%BIN_SUFFIX%",
)

native_binary(
name = "protoc_gen_buf_breaking",
src = "bin/protoc-gen-buf-breaking%BIN_SUFFIX%",
out = "protoc-gen-buf-breaking%BIN_SUFFIX%",
)

native_binary(
name = "protoc_gen_buf_lint",
src = "bin/protoc-gen-buf-lint%BIN_SUFFIX%",
out = "protoc-gen-buf-lint%BIN_SUFFIX%",
)

buf_toolchain(
name = "toolchain",
buf = ":buf",
protoc_breaking = ":protoc_gen_buf_breaking",
protoc_lint = ":protoc_gen_buf_lint",
)
24 changes: 24 additions & 0 deletions buf/internal/BUILD.toolchains.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
OS = [
"macos",
"linux",
"windows",
]

ARCHS = [
"x86_64",
"arm64",
]

[
toolchain(
name = "buf_toolchain_{}_{}".format(os, arch),
exec_compatible_with = [
"@platforms//os:{}".format(os),
"@platforms//cpu:{}".format(arch),
],
toolchain = "@%NAME%_dist_{}_{}//:toolchain".format(os, arch),
toolchain_type = "@rules_buf//buf:toolchain_type",
)
for arch in ARCHS
for os in OS
]
4 changes: 2 additions & 2 deletions buf/internal/lint.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ _DOC = """
For more info please refer to the [`buf_lint_test` section](https://docs.buf.build/build-systems/bazel#buf-lint-test) of the docs.
"""

_TOOLCHAIN = str(Label("//tools/protoc-gen-buf-lint:toolchain_type"))
_TOOLCHAIN = "@rules_buf//buf:toolchain_type"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't using @rules_buf fail when the imported repository is not named that?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the rule repo name should be consistent, it's part of your API essentially...


def _buf_lint_test_impl(ctx):
proto_infos = [t[ProtoInfo] for t in ctx.attr.targets]
Expand All @@ -33,7 +33,7 @@ def _buf_lint_test_impl(ctx):
files_to_include = []
if ctx.file.config != None:
files_to_include.append(ctx.file.config)
return protoc_plugin_test(ctx, proto_infos, ctx.executable._protoc, ctx.toolchains[_TOOLCHAIN].cli, config, files_to_include)
return protoc_plugin_test(ctx, proto_infos, ctx.executable._protoc, ctx.toolchains[_TOOLCHAIN].buf.protoc_lint_tool, config, files_to_include)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buf_breaking_test and buf_dependencies should also be updated in a similar way.


buf_lint_test = rule(
implementation = _buf_lint_test_impl,
Expand Down
Loading