|
| 1 | +commit 99af4b12716531021b9160fa2c622df4c5e8a0de |
| 2 | +Author: Alex Eagle <alex@aspect.dev> |
| 3 | +Date: Wed Oct 11 15:04:35 2023 -0700 |
| 4 | + |
| 5 | + feat: support bzlmod |
| 6 | + |
| 7 | + Bazel modules are moving away from setup in WORKSPACE files, towards a 'package manager' called bzlmod. |
| 8 | + Such modules are published on https://registry.bazel.build and are easier for developers to consume in their Bazel projects. |
| 9 | + |
| 10 | +diff --git a/MODULE.bazel b/MODULE.bazel |
| 11 | +new file mode 100644 |
| 12 | +index 0000000..973e2ba |
| 13 | +--- /dev/null |
| 14 | ++++ b/MODULE.bazel |
| 15 | +@@ -0,0 +1,16 @@ |
| 16 | ++"Bazel module definition for bzlmod" |
| 17 | ++module( |
| 18 | ++ name = "rules_buf", |
| 19 | ++ version = "0.1.1", |
| 20 | ++ compatibility_level = 1, |
| 21 | ++) |
| 22 | ++ |
| 23 | ++bazel_dep(name = "platforms", version = "0.0.4") |
| 24 | ++# Only needed because rules_proto doesn't provide the protoc toolchain yet. |
| 25 | ++# TODO(alex/sahin): remove in the future |
| 26 | ++bazel_dep(name = "protobuf", version = "21.7", repo_name = "com_google_protobuf") |
| 27 | ++bazel_dep(name = "rules_proto", version = "5.3.0-21.7") |
| 28 | ++ |
| 29 | ++ext = use_extension("//buf:extensions.bzl", "ext") |
| 30 | ++use_repo(ext, "rules_buf_toolchains") |
| 31 | ++register_toolchains("@rules_buf_toolchains//:all") |
| 32 | +diff --git a/buf/extensions.bzl b/buf/extensions.bzl |
| 33 | +new file mode 100644 |
| 34 | +index 0000000..472dfad |
| 35 | +--- /dev/null |
| 36 | ++++ b/buf/extensions.bzl |
| 37 | +@@ -0,0 +1,16 @@ |
| 38 | ++"""Define module extensions for using rules_buf with bzlmod. |
| 39 | ++See https://bazel.build/docs/bzlmod#extension-definition |
| 40 | ++""" |
| 41 | ++ |
| 42 | ++load("//buf/internal:toolchain.bzl", "buf_download_releases") |
| 43 | ++ |
| 44 | ++def _extension_impl(module_ctx): |
| 45 | ++ buf_download_releases( |
| 46 | ++ name = "rules_buf_toolchains", |
| 47 | ++ # TODO: get desired version from the attr |
| 48 | ++ version = "v1.27.0", |
| 49 | ++ ) |
| 50 | ++ |
| 51 | ++ext = module_extension( |
| 52 | ++ implementation = _extension_impl, |
| 53 | ++) |
| 54 | +diff --git a/buf/internal/toolchain.bzl b/buf/internal/toolchain.bzl |
| 55 | +index 33d3564..6fda129 100644 |
| 56 | +--- a/buf/internal/toolchain.bzl |
| 57 | ++++ b/buf/internal/toolchain.bzl |
| 58 | +@@ -63,7 +63,7 @@ def declare_buf_toolchains(os, cpu, rules_buf_repo_name): |
| 59 | + native.toolchain( |
| 60 | + name = cmd + "_toolchain", |
| 61 | + toolchain = ":" + toolchain_impl, |
| 62 | +- toolchain_type = "@{}//tools/{}:toolchain_type".format(rules_buf_repo_name, cmd), |
| 63 | ++ toolchain_type = "@@{}//tools/{}:toolchain_type".format(rules_buf_repo_name, cmd), |
| 64 | + exec_compatible_with = [ |
| 65 | + "@platforms//os:" + os, |
| 66 | + "@platforms//cpu:" + cpu, |
| 67 | +@@ -199,7 +199,7 @@ def _buf_download_releases_impl(ctx): |
| 68 | + ) |
| 69 | + return update_attrs(ctx.attr, ["version"], {"version": version}) |
| 70 | + |
| 71 | +-_buf_download_releases = repository_rule( |
| 72 | ++buf_download_releases = repository_rule( |
| 73 | + implementation = _buf_download_releases_impl, |
| 74 | + attrs = { |
| 75 | + "version": attr.string( |
| 76 | +@@ -217,7 +217,7 @@ def rules_buf_toolchains(name = _TOOLCHAINS_REPO, version = None): |
| 77 | + version: Release version, eg: `v.1.0.0-rc12`. If `None` defaults to latest |
| 78 | + """ |
| 79 | + |
| 80 | +- _buf_download_releases(name = name, version = version) |
| 81 | ++ buf_download_releases(name = name, version = version) |
| 82 | + |
| 83 | + _register_toolchains(name, "buf") |
| 84 | + _register_toolchains(name, "protoc-gen-buf-breaking") |
0 commit comments