dep-protobuf/bazel/flags/java/BUILD
Joshua Haberman f1c23cb216 Prepare Protobuf for a future version of Bazel which will lack the proto fragment
The ultimate effect of this change will be that both the native flags and Starlark flags will continue to work with future versions of Bazel that lack the proto fragment, until such time as we deprecate or remove the flags in a Protobuf release.  This decouples Bazel releases from Protobuf behavior changes.

1. Builds on the Bazel 8-compatible abstraction layer we submitted in cl/955468205 by setting `HAS_NATIVE_PROTO_FLAGS` properly in Bazel.  We do this by adding a `rules.has_proto_fragment` setting to the `proto_bazel_features.bzl` mechanism: we know that the fragment no longer needs to be read in Bazel 9+, because we can use `flag_alias()` instead.
2. Adds `flag_alias()` declarations in MODULE.bazel for all compat layer flags.  This will work in Bazel 9, but is ignored in Bazel 8.

This leads to a slight inconsistency.  Consider the following set of flags set by a user:

```
--@protobuf//bazel/flags:protocopt=foo --protocopt=bar
```

In Bazel 9+, where the flag alias is respected, the final value of the flag will be `bar`.  In Bazel 8, where we emulate `flag_alias()` by reconciling the two different values at analysis time, we always prefer the Starlark version (and cannot tell the relative order), so the final value of the flag will be `foo`.

To avoid this, prefer setting the Starlark version of the flag whenever possible.

PiperOrigin-RevId: 970834999
2026-08-25 15:30:42 -07:00

27 lines
767 B
Text

load("//bazel/private:compat_flag.bzl", "compat_label_flag")
package(
default_applicable_licenses = ["//:license"],
default_visibility = [
"//bazel/private:__pkg__",
"//bazel/tests:__subpackages__",
"//devtools/blaze/exoblaze/mac/integration:__subpackages__",
"//devtools/blaze/integration:__subpackages__",
],
)
exports_files(
["BUILD"],
)
compat_label_flag(
name = "proto_toolchain_for_java",
build_setting_default = "@bazel_tools//tools/proto:java_toolchain",
fragment_field = "proto_toolchain_for_java",
)
compat_label_flag(
name = "proto_toolchain_for_javalite",
build_setting_default = "@bazel_tools//tools/proto:javalite_toolchain",
fragment_field = "proto_toolchain_for_javalite",
)