Skip to content

Commit e86afb4

Browse files
authored
Merge pull request #25286 from protocolbuffers/bazel_fix
Bazel binary fix 4986a77 75196cd
2 parents 202d9e3 + 47b3385 commit e86afb4

File tree

4 files changed

+33
-17
lines changed

4 files changed

+33
-17
lines changed

.bcr/source.template.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"integrity": "**leave this alone**",
33
"strip_prefix": "{REPO}-{VERSION}",
4-
"url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/{REPO}-{VERSION}.tar.gz"
4+
"url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/{REPO}-{VERSION}.bazel.tar.gz"
55
}

.github/workflows/release_bazel_module.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
release:
1919
uses: bazel-contrib/.github/.github/workflows/release_ruleset.yaml@v7.2.3
2020
with:
21-
release_files: protobuf-*.tar.gz
21+
release_files: protobuf-*.bazel.tar.gz
2222
prerelease: false
2323
tag_name: ${{ inputs.tag_name }}
2424
# The release was already created by Google-internal mechanism,

.github/workflows/release_prep.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ set -o errexit -o nounset -o pipefail
77
# https://github.com/bazel-contrib/.github/blob/v7.2.3/.github/workflows/release_ruleset.yaml#L104
88
TAG=$1
99
PREFIX="protobuf-${TAG:1}"
10-
ARCHIVE="$PREFIX.tar.gz"
10+
ARCHIVE="$PREFIX.bazel.tar.gz"
1111
ARCHIVE_TMP=$(mktemp)
1212
INTEGRITY_FILE=${PREFIX}/bazel/private/prebuilt_tool_integrity.bzl
1313

protobuf.bzl

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
load("@bazel_skylib//lib:versions.bzl", "versions")
22
load("@rules_cc//cc:defs.bzl", "objc_library")
33
load("@rules_python//python:defs.bzl", "py_library")
4+
load("//bazel/common:proto_common.bzl", "proto_common")
45
load("//bazel/common:proto_info.bzl", "ProtoInfo")
6+
load("//bazel/private:toolchain_helpers.bzl", "toolchains")
57

68
def _GetPath(ctx, path):
79
if ctx.label.workspace_root:
@@ -71,6 +73,26 @@ def _CsharpOuts(srcs):
7173
for src in srcs
7274
]
7375

76+
_PROTOC_ATTRS = toolchains.if_legacy_toolchain({
77+
"_proto_compiler": attr.label(
78+
cfg = "exec",
79+
executable = True,
80+
allow_files = True,
81+
default = configuration_field("proto", "proto_compiler"),
82+
),
83+
})
84+
_PROTOC_FRAGMENTS = ["proto"]
85+
_PROTOC_TOOLCHAINS = toolchains.use_toolchain(toolchains.PROTO_TOOLCHAIN)
86+
87+
def _protoc_files_to_run(ctx):
88+
if proto_common.INCOMPATIBLE_ENABLE_PROTO_TOOLCHAIN_RESOLUTION:
89+
toolchain = ctx.toolchains[toolchains.PROTO_TOOLCHAIN]
90+
if not toolchain:
91+
fail("Protocol compiler toolchain could not be resolved.")
92+
return toolchain.proto.proto_compiler
93+
else:
94+
return ctx.attr._proto_compiler[DefaultInfo].files_to_run
95+
7496
ProtoGenInfo = provider(
7597
fields = ["srcs", "import_flags", "deps"],
7698
)
@@ -310,7 +332,7 @@ def _internal_gen_well_known_protos_java_impl(ctx):
310332
args.add_all([src.path[offset:] for src in dep.direct_sources])
311333

312334
ctx.actions.run(
313-
executable = ctx.executable._protoc,
335+
executable = _protoc_files_to_run(ctx),
314336
inputs = descriptors,
315337
outputs = [srcjar],
316338
arguments = [args],
@@ -334,12 +356,9 @@ internal_gen_well_known_protos_java = rule(
334356
"javalite": attr.bool(
335357
default = False,
336358
),
337-
"_protoc": attr.label(
338-
executable = True,
339-
cfg = "exec",
340-
default = "//:protoc",
341-
),
342-
},
359+
} | _PROTOC_ATTRS,
360+
fragments = _PROTOC_FRAGMENTS,
361+
toolchains = _PROTOC_TOOLCHAINS,
343362
)
344363

345364
def _internal_gen_kt_protos(ctx):
@@ -373,7 +392,7 @@ def _internal_gen_kt_protos(ctx):
373392
args.add_all([src.path[offset:] for src in dep.direct_sources])
374393

375394
ctx.actions.run(
376-
executable = ctx.executable._protoc,
395+
executable = _protoc_files_to_run(ctx),
377396
inputs = descriptors,
378397
outputs = [srcjar],
379398
arguments = [args],
@@ -397,12 +416,9 @@ internal_gen_kt_protos = rule(
397416
"lite": attr.bool(
398417
default = False,
399418
),
400-
"_protoc": attr.label(
401-
executable = True,
402-
cfg = "exec",
403-
default = "//:protoc",
404-
),
405-
},
419+
} | _PROTOC_ATTRS,
420+
fragments = _PROTOC_FRAGMENTS,
421+
toolchains = _PROTOC_TOOLCHAINS,
406422
)
407423

408424
def internal_objc_proto_library(

0 commit comments

Comments
 (0)