Skip to content

Commit 7e9cd2c

Browse files
committed
simplify version handling since we support only one
1 parent de2df64 commit 7e9cd2c

File tree

5 files changed

+10
-35
lines changed

5 files changed

+10
-35
lines changed

.github/workflows/release_prep.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ mkdir -p ${PREFIX}/bazel/private
3737
cat >${INTEGRITY_FILE} <<EOF
3838
"Generated during release by release_prep.sh"
3939
40+
RELEASE_VERSION="${TAG}"
4041
RELEASED_BINARY_INTEGRITY = $(
4142
curl -s https://api.github.com/repos/protocolbuffers/protobuf/releases/tags/${TAG} \
4243
| jq -f <(echo "$filter_releases")
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
"Module extensions for use under bzlmod"
22

3+
load("@bazel_skylib//lib:modules.bzl", "modules")
34
load("//toolchain:platforms.bzl", "PROTOBUF_PLATFORMS")
45
load("//bazel/private:prebuilt_protoc_toolchain.bzl", "prebuilt_protoc_repo")
56

6-
def create_all_toolchain_repos(name, version):
7+
def create_all_toolchain_repos(name = "prebuilt_protoc"):
78
for platform in PROTOBUF_PLATFORMS.keys():
89
prebuilt_protoc_repo(
910
# We must replace hyphen with underscore to workaround rules_python py_proto_library constraint
1011
name = ".".join([name, platform.replace("-", "_")]),
1112
platform = platform,
12-
version = version,
1313
)
1414

15-
protoc = module_extension(
16-
# TODO: replace version number here during release, maybe with git archive .gitattributes config
17-
implementation = lambda module_ctx: create_all_toolchain_repos("prebuilt_protoc", "v33.0")
18-
)
15+
protoc = modules.as_extension(create_all_toolchain_repos)

bazel/private/prebuilt_protoc_toolchain.bzl

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"Repository rule that downloads a pre-compiled protoc from our official release for a single platform."
22

3-
load(":prebuilt_tool_integrity.bzl", "RELEASED_BINARY_INTEGRITY")
3+
load(":prebuilt_tool_integrity.bzl", "RELEASED_BINARY_INTEGRITY", "RELEASE_VERSION")
44
load("//toolchain:platforms.bzl", "PROTOBUF_PLATFORMS")
55

66
def release_version_to_artifact_name(release_version, platform):
@@ -18,14 +18,13 @@ def release_version_to_artifact_name(release_version, platform):
1818
)
1919

2020
def _prebuilt_protoc_repo_impl(rctx):
21-
release_version = rctx.attr.version
2221
filename = release_version_to_artifact_name(
23-
release_version,
22+
RELEASE_VERSION,
2423
rctx.attr.platform,
2524
)
2625
rctx.download_and_extract(
2726
url = "https://github.com/protocolbuffers/protobuf/releases/download/{}/{}".format(
28-
release_version,
27+
RELEASE_VERSION,
2928
filename,
3029
),
3130
sha256 = RELEASED_BINARY_INTEGRITY[filename],
@@ -54,9 +53,5 @@ prebuilt_protoc_repo = repository_rule(
5453
mandatory = True,
5554
values = PROTOBUF_PLATFORMS.keys(),
5655
),
57-
"version": attr.string(
58-
doc = "Release tag from protocolbuffers/protobuf repo, e.g. 'v25.3'",
59-
mandatory = True,
60-
),
6156
},
6257
)

bazel/private/prebuilt_tool_integrity.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ so that the integrity of the prebuilt tools is included in the release artifact.
66
The checked in content is only here to allow load() statements in the sources to resolve.
77
"""
88

9+
RELEASE_VERSION = "v33.0"
10+
911
# Fetched from the last release of protobuf, so the example can work
1012
RELEASED_BINARY_INTEGRITY = {
1113
"MODULE.bazel.intoto.jsonl": "32ee438bf7e3a210a6b7d5e2d272900a2e7f4a1b4f0992fdf0490281771cac3e",

bazel/private/toolchains/prebuilt/BUILD.bazel

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,7 @@
11
"""Create lazy definitions to reference the pre-built protoc toolchains.
22
33
Ensures that Bazel only downloads required binaries for selected toolchains.
4-
5-
This follows guidance here:
6-
https://docs.bazel.build/versions/main/skylark/deploying.html#registering-toolchains
7-
"
8-
Note that in order to resolve toolchains in the analysis phase
9-
Bazel needs to analyze all toolchain targets that are registered.
10-
Bazel will not need to analyze all targets referenced by toolchain.toolchain attribute.
11-
If in order to register toolchains you need to perform complex computation in the repository,
12-
consider splitting the repository with toolchain targets
13-
from the repository with <LANG>_toolchain targets.
14-
Former will be always fetched,
15-
and the latter will only be fetched when user actually needs to build <LANG> code.
16-
"
17-
18-
The "complex computation" in our case is simply downloading our pre-built protoc binaries.
19-
This guidance tells us how to avoid that: we put the toolchain targets in the alias repository
20-
with only the toolchain attribute pointing into the platform-specific repositories.
21-
22-
These can be registered in the workspace file or passed to --extra_toolchains flag.
23-
By default all these toolchains are registered by the protoc module extension
24-
so users don't normally need to interact with these targets.
4+
In particular, see comment below on the toolchain#toolchain attribute.
255
"""
266

277
load("//toolchain:platforms.bzl", "PROTOBUF_PLATFORMS")

0 commit comments

Comments
 (0)