Skip to content

Commit ad38d23

Browse files
committed
chore: add rules_buf
it comes from aspect-forks until bufbuild/rules_buf#42 is merged, hopefully for the next release
1 parent cea9064 commit ad38d23

5 files changed

Lines changed: 136 additions & 0 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"Bazel module definition for bzlmod"
2+
module(
3+
name = "rules_buf",
4+
version = "0.1.1", # Replaced when publishing
5+
compatibility_level = 1,
6+
)
7+
8+
bazel_dep(name = "platforms", version = "0.0.4")
9+
# Only needed because rules_proto doesn't provide the protoc toolchain yet.
10+
# TODO(alex/sahin): remove in the future
11+
bazel_dep(name = "protobuf", version = "21.7", repo_name = "com_google_protobuf")
12+
bazel_dep(name = "rules_proto", version = "5.3.0-21.7")
13+
14+
ext = use_extension("//buf:extensions.bzl", "ext")
15+
use_repo(ext, "rules_buf_toolchains")
16+
register_toolchains("@rules_buf_toolchains//:all")
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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")
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
bcr_test_module:
2+
module_path: 'examples/bzlmod'
3+
matrix:
4+
platform: ['ubuntu2004']
5+
tasks:
6+
run_tests:
7+
name: 'Run test module'
8+
platform: ${{ platform }}
9+
build_targets:
10+
- '//...'
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"integrity": "sha256-CjfiYuajROyN2Cu4mYd+aY6zCNziwig8DFx/fUH+Cqw=",
3+
"strip_prefix": "rules_buf-abbbfce7c3fccf1d4b87afa28140d9ce53f80057",
4+
"patch_strip": 1,
5+
"patches": {
6+
"bzlmod.patch": "sha256-SgWKiK9J19MKX0Vf2YB3H7aRJNpoWqDCDUaiAkMxH/g="
7+
},
8+
"url": "https://github.com/bufbuild/rules_buf/archive/abbbfce7c3fccf1d4b87afa28140d9ce53f80057.zip"
9+
}

modules/rules_buf/metadata.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"homepage": "https://github.com/bufbuild/rules_buf",
3+
"maintainers": [
4+
{
5+
"email": "alex@aspect.dev",
6+
"github": "alexeagle",
7+
"name": "Alex Eagle"
8+
}
9+
],
10+
"repository": [
11+
"github:aspect-forks/rules_buf"
12+
],
13+
"versions": [
14+
"0.1.1"
15+
],
16+
"yanked_versions": {}
17+
}

0 commit comments

Comments
 (0)