Skip to content

Commit 84a30b5

Browse files
author
Rachel Goldfinger
committed
Breaking Change: Change @protobuf//bazel/flags:prefer_prebuilt_proto flag to True.
PiperOrigin-RevId: 871890409
1 parent b4b1a0b commit 84a30b5

File tree

4 files changed

+48
-27
lines changed

4 files changed

+48
-27
lines changed

.github/workflows/test_bazel.yml

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ jobs:
3030
bazelversion: [ '8.0.0' ]
3131
bzlmod: [ true, false ]
3232
toolchain_resolution:
33-
# Default flags, uses from-source protoc
33+
# Default flags, uses from prebuilt protoc
3434
- ""
35-
# still uses from-source protoc unless
36-
# --@com_google_protobuf//bazel/flags:prefer_prebuilt_protoc is set
37-
- "--incompatible_enable_proto_toolchain_resolution=true"
35+
# Still uses prebuilt protoc
36+
- "--incompatible_enable_proto_toolchain_resolution=false"
37+
# Uses protoc from source.
38+
- "--@com_google_protobuf//bazel/flags:prefer_prebuilt_protoc=false"
3839
runs-on: ${{ matrix.runner }}-latest
3940
name: ${{ matrix.continuous-only && inputs.continuous-prefix || '' }} Examples ${{ matrix.runner }} ${{ matrix.bazelversion }}${{ matrix.bzlmod && ' (bzlmod)' || '' }} ${{ matrix.toolchain_resolution && ' (toolchain resolution)' || '' }}
4041
steps:
@@ -78,8 +79,27 @@ jobs:
7879
cd examples;
7980
bazel build //... @com_google_protobuf-examples-with-hyphen//... $BAZEL_FLAGS --enable_bzlmod=${{ matrix.bzlmod }} --enable_workspace=${{ !matrix.bzlmod }} ${{ matrix.toolchain_resolution }};
8081
81-
- name: Prebuilt test
82-
if: ${{ matrix.bzlmod && (!matrix.continuous-only || inputs.continuous-run) }}
82+
prebuilt-protoc:
83+
strategy:
84+
fail-fast: false
85+
matrix:
86+
runner: [ ubuntu, windows, macos ]
87+
bazelversion: [ '8.0.0' ]
88+
bzlmod: [ true ]
89+
toolchain_resolution:
90+
# Default flags, uses from prebuilt protoc
91+
- ""
92+
runs-on: ${{ matrix.runner }}-latest
93+
name: ${{ matrix.continuous-only && inputs.continuous-prefix || '' }} Prebuilt test ${{ matrix.runner }} ${{ matrix.bazelversion }} ${{ matrix.toolchain_resolution && ' (toolchain resolution)' || '' }}
94+
steps:
95+
- name: Checkout pending changes
96+
if: ${{ !matrix.continuous-only || inputs.continuous-run }}
97+
uses: protocolbuffers/protobuf-ci/checkout@v5
98+
with:
99+
ref: ${{ inputs.safe-checkout }}
100+
101+
- name: Run tests
102+
if: ${{ !matrix.continuous-only || inputs.continuous-run }}
83103
uses: protocolbuffers/protobuf-ci/bazel@v5
84104
with:
85105
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}

MODULE.bazel

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@ use_repo(
120120
"prebuilt_protoc.win64",
121121
)
122122

123-
# However this registration only matters if the config_setting for prefer_prebuilt_protoc is true,
124-
# using --@protobuf//bazel/flags:prefer_prebuilt_protoc
123+
# This registration applies when the config_setting for prefer_prebuilt_protoc is true.
124+
# This is now enabled by default.
125+
# It can be disabled using --@protobuf//bazel/flags:prefer_prebuilt_protoc=false
125126
register_toolchains("//bazel/private/oss/toolchains/prebuilt:all")
126127

127128
# From-source protobuf toolchains

bazel/flags/BUILD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ label_flag(
3737
)
3838

3939
# When set to true, we will use a prebuilt protoc binary from GitHub if it's available.
40+
# This is now enabled by default.
4041
bool_flag(
4142
name = "prefer_prebuilt_protoc",
42-
# TODO: this should be True after the feature is vetted with some adoption
43-
build_setting_default = False,
43+
build_setting_default = True,
4444
visibility = ["//bazel/toolchains:__pkg__"],
4545
)
4646

bazel/tests/cc_toolchain_tests.bzl

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ def cc_toolchain_test_suite(name):
1818
test_suite(
1919
name = name,
2020
tests = [
21-
_test_cc_toolchain_uses_full_protoc_when_prefer_prebuilt_flag_set,
22-
_test_cc_toolchain_uses_protoc_minimal_by_default,
21+
_test_cc_toolchain_uses_protoc_minimal_when_prefer_prebuilt_flag_unset,
22+
_test_cc_toolchain_uses_full_protoc_by_default,
2323
],
2424
)
2525

26-
def _test_cc_toolchain_uses_full_protoc_when_prefer_prebuilt_flag_set(name):
26+
def _test_cc_toolchain_uses_protoc_minimal_when_prefer_prebuilt_flag_unset(name):
2727
util.helper_target(
2828
proto_library,
2929
name = name + "_proto",
@@ -39,21 +39,19 @@ def _test_cc_toolchain_uses_full_protoc_when_prefer_prebuilt_flag_set(name):
3939
analysis_test(
4040
name = name,
4141
target = name + "_compile",
42-
impl = _test_cc_toolchain_uses_full_protoc_when_prefer_prebuilt_flag_set_impl,
43-
config_settings = {_PREFER_PREBUILT_PROTOC: True},
42+
impl = _test_cc_toolchain_uses_protoc_minimal_when_prefer_prebuilt_flag_unset_impl,
43+
config_settings = {_PREFER_PREBUILT_PROTOC: False},
4444
)
4545

46-
def _test_cc_toolchain_uses_full_protoc_when_prefer_prebuilt_flag_set_impl(env, target):
46+
def _test_cc_toolchain_uses_protoc_minimal_when_prefer_prebuilt_flag_unset_impl(env, target):
4747
# Find the compile action
4848
action = env.expect.that_target(target).action_named("GenProto")
4949

50-
# When prefer_prebuilt_protoc is True, protoc_minimal_do_not_use is None,
51-
# so the cc_toolchain should use the full protoc (not protoc_minimal).
52-
# The protoc path should end with "/protoc" not contain "protoc_minimal"
53-
action.argv().contains_predicate(matching.str_matches("*/protoc"))
54-
action.argv().not_contains_predicate(matching.str_matches("*protoc_minimal*"))
50+
# When prefer_prebuilt_protoc is False, protoc_minimal_do_not_use is set,
51+
# so the cc_toolchain should use protoc_minimal.
52+
action.argv().contains_predicate(matching.str_matches("*protoc_minimal*"))
5553

56-
def _test_cc_toolchain_uses_protoc_minimal_by_default(name):
54+
def _test_cc_toolchain_uses_full_protoc_by_default(name):
5755
util.helper_target(
5856
proto_library,
5957
name = name + "_proto",
@@ -69,13 +67,15 @@ def _test_cc_toolchain_uses_protoc_minimal_by_default(name):
6967
analysis_test(
7068
name = name,
7169
target = name + "_compile",
72-
impl = _test_cc_toolchain_uses_protoc_minimal_by_default_impl,
70+
impl = _test_cc_toolchain_uses_full_protoc_by_default_impl,
7371
)
7472

75-
def _test_cc_toolchain_uses_protoc_minimal_by_default_impl(env, target):
73+
def _test_cc_toolchain_uses_full_protoc_by_default_impl(env, target):
7674
# Find the compile action
7775
action = env.expect.that_target(target).action_named("GenProto")
7876

79-
# By default (prefer_prebuilt_protoc is False), protoc_minimal_do_not_use is set,
80-
# so the cc_toolchain should use protoc_minimal.
81-
action.argv().contains_predicate(matching.str_matches("*protoc_minimal*"))
77+
# By default (prefer_prebuilt_protoc is True), protoc_minimal_do_not_use is None,
78+
# so the cc_toolchain should use the full protoc (not protoc_minimal).
79+
# The protoc path should end with "/protoc" not contain "protoc_minimal"
80+
action.argv().contains_predicate(matching.str_matches("*/protoc"))
81+
action.argv().not_contains_predicate(matching.str_matches("*protoc_minimal*"))

0 commit comments

Comments
 (0)