Skip to content

Commit cfe8991

Browse files
habermantonyliaoss
authored andcommitted
Moved prebuilt-related Bazel files to standard locations.
- Standard location for flags is `bazel/flags/` - Standard location for OSS-only internal files is `bazel/private/oss`. PiperOrigin-RevId: 862267301
1 parent d7dd1e1 commit cfe8991

File tree

12 files changed

+42
-42
lines changed

12 files changed

+42
-42
lines changed

.github/workflows/test_bazel.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
# Default flags, uses from-source protoc
3434
- ""
3535
# still uses from-source protoc unless
36-
# --@com_google_protobuf//bazel/toolchains:prefer_prebuilt_protoc is set
36+
# --@com_google_protobuf//bazel/flags:prefer_prebuilt_protoc is set
3737
- "--incompatible_enable_proto_toolchain_resolution=true"
3838
runs-on: ${{ matrix.runner }}-latest
3939
name: ${{ matrix.continuous-only && inputs.continuous-prefix || '' }} Examples ${{ matrix.runner }} ${{ matrix.bazelversion }}${{ matrix.bzlmod && ' (bzlmod)' || '' }} ${{ matrix.toolchain_resolution && ' (toolchain resolution)' || '' }}

BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ proto_lang_toolchain(
570570
# Set minimal protoc if prefer_prebuilt_protoc.flag_set is true since a prebuilt for protoc_minimal is not available
571571
# TODO: Add a flag to switch between minimal and full protoc with proto_lang_toolchain once we have a minimal protoc binary.
572572
# Setting this attribute to None will make the toolchain to pick the full protoc binary.
573-
"//bazel/toolchains:prefer_prebuilt_protoc.flag_set": None,
573+
"//bazel/flags:prefer_prebuilt_protoc.flag_set": None,
574574
"//conditions:default": "//src/google/protobuf/compiler:protoc_minimal",
575575
}),
576576
runtime = "//src/google/protobuf",

MODULE.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ register_toolchains(
120120
)
121121

122122
# Define toolchains that use pre-built protoc binaries.
123-
prebuilt_protoc = use_extension("//bazel/private:prebuilt_protoc_extension.bzl", "protoc")
123+
prebuilt_protoc = use_extension("//bazel/private/oss/toolchains/prebuilt:protoc_extension.bzl", "protoc")
124124
use_repo(
125125
prebuilt_protoc,
126126
"prebuilt_protoc.linux_aarch_64",
@@ -135,7 +135,7 @@ use_repo(
135135
)
136136

137137
# However this registration only matters if the config_setting for prefer_prebuilt_protoc is true,
138-
# using --@protobuf//bazel/toolchains:prefer_prebuilt_protoc
138+
# using --@protobuf//bazel/flags:prefer_prebuilt_protoc
139139
register_toolchains("//bazel/private/oss/toolchains/prebuilt:all")
140140

141141
# From-source protobuf toolchains

bazel/flags/BUILD

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,36 @@ label_flag(
3636
build_setting_default = "@bazel_tools//tools/proto:protoc",
3737
)
3838

39+
# When set to true, we will use a prebuilt protoc binary from GitHub if it's available.
40+
bool_flag(
41+
name = "prefer_prebuilt_protoc",
42+
# TODO: this should be True after the feature is vetted with some adoption
43+
build_setting_default = False,
44+
visibility = ["//visibility:private"],
45+
)
46+
47+
config_setting(
48+
name = "prefer_prebuilt_protoc.flag_set",
49+
flag_values = {":prefer_prebuilt_protoc": "true"},
50+
visibility = [
51+
"//bazel/private/oss/toolchains/prebuilt:__pkg__",
52+
# Needed by cc_toolchain to switch between minimal and full protoc
53+
"//:__pkg__",
54+
],
55+
)
56+
57+
# The public API users set to disable the validation action failing.
58+
bool_flag(
59+
name = "allow_nonstandard_protoc",
60+
build_setting_default = False,
61+
)
62+
63+
config_setting(
64+
name = "allow_nonstandard_protoc.flag_set",
65+
flag_values = {":allow_nonstandard_protoc": "true"},
66+
visibility = ["//bazel/private/oss/toolchains/prebuilt:__pkg__"],
67+
)
68+
3969
# TODO: deprecate this flag.
4070
string_flag(
4171
name = "strict_proto_deps",

bazel/private/oss/toolchains/prebuilt/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ load(":protoc_authenticity.bzl", "protoc_authenticity")
1212
name = "{}_toolchain".format(platform.replace("-", "_")),
1313
exec_compatible_with = meta["compatible_with"],
1414
# Toolchain resolution will only permit this toolchain if the config_setting for prefer_prebuilt_protoc is true,
15-
target_settings = ["@com_google_protobuf//bazel/toolchains:prefer_prebuilt_protoc.flag_set"],
15+
target_settings = ["@com_google_protobuf//bazel/flags:prefer_prebuilt_protoc.flag_set"],
1616
# Bazel does not follow this attribute during analysis, so the referenced repo
1717
# will only be fetched if this toolchain is selected.
1818
toolchain = "@prebuilt_protoc.{}//:prebuilt_protoc_toolchain".format(platform.replace("-", "_")),
@@ -25,7 +25,7 @@ load(":protoc_authenticity.bzl", "protoc_authenticity")
2525
protoc_authenticity(
2626
name = "authenticity_validation",
2727
fail_on_mismatch = select({
28-
"//bazel/toolchains:allow_nonstandard_protoc.flag_set": False,
28+
"//bazel/flags:allow_nonstandard_protoc.flag_set": False,
2929
"//conditions:default": True,
3030
}),
3131
visibility = ["//visibility:public"],

bazel/private/oss/toolchains/prebuilt/protoc_authenticity.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"Validate that the protoc binary is authentic and not spoofed by a malicious actor."
22

33
load("//bazel/common:proto_common.bzl", "proto_common")
4-
load("//bazel/private:prebuilt_tool_integrity.bzl", "RELEASE_VERSION")
54
load("//bazel/private:toolchain_helpers.bzl", "toolchains")
5+
load(":tool_integrity.bzl", "RELEASE_VERSION")
66

77
def _protoc_authenticity_impl(ctx):
88
# When this flag is disabled, then users have no way to replace the protoc binary with their own toolchain registration.

bazel/private/prebuilt_protoc_extension.bzl renamed to bazel/private/oss/toolchains/prebuilt/protoc_extension.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"Module extensions for use under bzlmod"
22

33
load("@bazel_skylib//lib:modules.bzl", "modules")
4-
load("//bazel/private:prebuilt_protoc_toolchain.bzl", "prebuilt_protoc_repo")
54
load("//toolchain:platforms.bzl", "PROTOBUF_PLATFORMS")
5+
load(":protoc_toolchain.bzl", "prebuilt_protoc_repo")
66

77
def create_all_toolchain_repos(name = "prebuilt_protoc"):
88
for platform in PROTOBUF_PLATFORMS.keys():

bazel/private/prebuilt_protoc_toolchain.bzl renamed to bazel/private/oss/toolchains/prebuilt/protoc_toolchain.bzl

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

33
load("//toolchain:platforms.bzl", "PROTOBUF_PLATFORMS")
4-
load(":prebuilt_tool_integrity.bzl", "RELEASED_BINARY_INTEGRITY", "RELEASE_VERSION")
4+
load(":tool_integrity.bzl", "RELEASED_BINARY_INTEGRITY", "RELEASE_VERSION")
55

66
def release_version_to_artifact_name(release_version, platform):
77
# versions have a "v" prefix like "v28.0"
@@ -31,7 +31,7 @@ def _prebuilt_protoc_repo_impl(rctx):
3131
)
3232

3333
rctx.file("BUILD.bazel", """\
34-
# Generated by @protobuf//bazel/private:prebuilt_protoc_toolchain.bzl
34+
# Generated by @protobuf//bazel/private/oss/toolchains/prebuilt:protoc_toolchain.bzl
3535
load("@com_google_protobuf//bazel/toolchains:proto_toolchain.bzl", "proto_toolchain")
3636
3737
package(default_visibility = ["//visibility:public"])
File renamed without changes.

bazel/tests/cc_toolchain_tests.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ load("@rules_testing//lib:util.bzl", "util")
1212
load("//bazel:proto_library.bzl", "proto_library")
1313
load("//bazel/tests/testdata:compile_rule.bzl", "compile_rule")
1414

15-
_PREFER_PREBUILT_PROTOC = str(Label("//bazel/toolchains:prefer_prebuilt_protoc"))
15+
_PREFER_PREBUILT_PROTOC = str(Label("//bazel/flags:prefer_prebuilt_protoc"))
1616

1717
def cc_toolchain_test_suite(name):
1818
test_suite(

0 commit comments

Comments
 (0)