Skip to content

Commit c0b84f8

Browse files
dwscopybara-github
authored andcommitted
allow Bazel to build with --incompatible_disable_target_default_provider_fields
We here address obstacles to building Bazel with `--incompatible_disable_target_default_provider_fields` enabled. This includes patches representing - bazelbuild/apple_support#413 - bazelbuild/rules_java#303 - grpc/grpc-java#12148 which should be removed once these PRs have been included in releases of their respective repos. All of these pull requests have been approved and merged into their respective repositories. Once #26276 is cherry-picked into a Bazel 8 release, we should be able to update `.bazelversion` to that release, and in conjunction with the changes herein, we should be able to enable `--incompatible_disable_target_default_provider_fields` in `.bazelrc` in order to prevent regressions. Ideally, we could also flip the default value of this flag once #26297 also lands. Note that #26293 is related, but not strictly needed for builds. Closes #26272. PiperOrigin-RevId: 772542631 Change-Id: Ib5db3ffa3f4857199a6f8d838078d7ced2281ba3
1 parent 6961259 commit c0b84f8

File tree

5 files changed

+229
-0
lines changed

5 files changed

+229
-0
lines changed

BUILD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ genrule(
7272
"MODULE.bazel",
7373
"//third_party/remoteapis:MODULE.bazel",
7474
"//third_party:BUILD",
75+
"//third_party:apple_support.patch",
76+
"//third_party:grpc-java.patch",
7577
"//third_party:grpc_remove_provides_strings.patch",
78+
"//third_party:rules_java.patch",
7679
"//third_party:rules_jvm_external_6.5.patch",
7780
"//third_party:rules_graalvm_fix.patch",
7881
"//third_party:rules_graalvm_unicode.patch",

MODULE.bazel

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,30 @@ single_version_override(
9595
version = "0.15.0",
9696
)
9797

98+
# Remove once https://github.com/bazelbuild/apple_support/pull/413 is available in an apple_support release.
99+
single_version_override(
100+
module_name = "apple_support",
101+
patch_strip = 1,
102+
patches = ["//third_party:apple_support.patch"],
103+
version = "1.21.1",
104+
)
105+
106+
# Remove once https://github.com/bazelbuild/rules_java/pull/303 is available in a rules_java release.
107+
single_version_override(
108+
module_name = "rules_java",
109+
patch_strip = 1,
110+
patches = ["//third_party:rules_java.patch"],
111+
version = "8.12.0",
112+
)
113+
114+
# Remove once https://github.com/grpc/grpc-java/pull/12148 is available in a grpc-java release.
115+
single_version_override(
116+
module_name = "grpc-java",
117+
patch_strip = 1,
118+
patches = ["//third_party:grpc-java.patch"],
119+
version = "1.66.0",
120+
)
121+
98122
local_path_override(
99123
module_name = "remoteapis",
100124
path = "./third_party/remoteapis",

third_party/apple_support.patch

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
commit c8fecc0002e6fc03419cf106a3c02294e4a67896
2+
Author: David Sanderson <[email protected]>
3+
Date: Wed Jun 11 15:28:14 2025 -0400
4+
5+
use DefaultInfo in apple_support
6+
7+
We here address the following obstacles in apple_support to using
8+
Bazel's --incompatible_disable_target_default_provider_fields flag:
9+
10+
ERROR: /private/var/tmp/_bazel_dws/7fd3cd5077fbf76d9e2ae421c39ef7ed/external/apple_support+/crosstool/BUILD:25:20: in apple_genrule rule @@apple_support+//crosstool:exec_wrapped_clang_pp.target_config:
11+
Traceback (most recent call last):
12+
File "/private/var/tmp/_bazel_dws/7fd3cd5077fbf76d9e2ae421c39ef7ed/external/apple_support+/rules/private/apple_genrule.bzl", line 52, column 45, in _apple_genrule_impl
13+
resolved_srcs = depset(transitive = [dep.files for dep in ctx.attr.srcs])
14+
Error: Accessing the default provider in this manner is deprecated and will be removed soon. It may be temporarily re-enabled by setting --incompatible_disable_target_default_provider_fields=false. See https://github.com/bazelbuild/bazel/issues/20183 for details.
15+
ERROR: /private/var/tmp/_bazel_dws/7fd3cd5077fbf76d9e2ae421c39ef7ed/external/apple_support+/crosstool/BUILD:25:20: Analysis of target '@@apple_support+//crosstool:exec_wrapped_clang_pp.target_config' failed
16+
ERROR: Analysis of target '//src:bazel' failed; build aborted: Analysis failed
17+
18+
ERROR: /private/var/tmp/_bazel_dws/7fd3cd5077fbf76d9e2ae421c39ef7ed/external/apple_support++apple_cc_configure_extension+local_config_apple_cc/BUILD:78:24: in cc_toolchain_config rule @@apple_support++apple_cc_configure_extension+local_config_apple_cc//:darwin_x86_64:
19+
Traceback (most recent call last):
20+
File "/private/var/tmp/_bazel_dws/7fd3cd5077fbf76d9e2ae421c39ef7ed/external/apple_support++apple_cc_configure_extension+local_config_apple_cc/cc_toolchain_config.bzl", line 2506, column 37, in _impl
21+
modulemaps = ctx.attr.module_map.files.to_list()
22+
Error: Accessing the default provider in this manner is deprecated and will be removed soon. It may be temporarily re-enabled by setting --incompatible_disable_target_default_provider_fields=false. See https://github.com/bazelbuild/bazel/issues/20183 for details.
23+
ERROR: /private/var/tmp/_bazel_dws/7fd3cd5077fbf76d9e2ae421c39ef7ed/external/apple_support++apple_cc_configure_extension+local_config_apple_cc/BUILD:78:24: Analysis of target '@@apple_support++apple_cc_configure_extension+local_config_apple_cc//:darwin_x86_64' failed
24+
ERROR: Analysis of target '//src:bazel' failed; build aborted: Analysis failed
25+
26+
diff --git a/crosstool/cc_toolchain_config.bzl b/crosstool/cc_toolchain_config.bzl
27+
index 3bb7c26..1ae7198 100644
28+
--- a/crosstool/cc_toolchain_config.bzl
29+
+++ b/crosstool/cc_toolchain_config.bzl
30+
@@ -2503,7 +2503,7 @@ please file an issue at https://github.com/bazelbuild/apple_support/issues/new
31+
],
32+
)
33+
34+
- modulemaps = ctx.attr.module_map.files.to_list()
35+
+ modulemaps = ctx.attr.module_map[DefaultInfo].files.to_list()
36+
if modulemaps:
37+
if len(modulemaps) != 1:
38+
fail("internal error: expected 1 modulemap got:", modulemaps)
39+
diff --git a/rules/private/apple_genrule.bzl b/rules/private/apple_genrule.bzl
40+
index b00395e..cdfd501 100644
41+
--- a/rules/private/apple_genrule.bzl
42+
+++ b/rules/private/apple_genrule.bzl
43+
@@ -49,8 +49,8 @@ def _apple_genrule_impl(ctx):
44+
attr = "executable",
45+
)
46+
47+
- resolved_srcs = depset(transitive = [dep.files for dep in ctx.attr.srcs])
48+
- label_dict = {dep.label: dep.files.to_list() for dep in ctx.attr.srcs}
49+
+ resolved_srcs = depset(transitive = [dep[DefaultInfo].files for dep in ctx.attr.srcs])
50+
+ label_dict = {dep.label: dep[DefaultInfo].files.to_list() for dep in ctx.attr.srcs}
51+
52+
xcode_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig]
53+

third_party/grpc-java.patch

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
commit 2bf1b927a4d24b6869d7247f91d4af2b50c39a9f
2+
Author: David Sanderson <[email protected]>
3+
Date: Wed Jun 11 17:46:26 2025 -0400
4+
5+
use DefaultInfo in grpc-java
6+
7+
We here address the following obstacles in grpc-java to using Bazel's
8+
--incompatible_disable_target_default_provider_fields flag:
9+
10+
ERROR: /private/var/tmp/_bazel_dws/7fd3cd5077fbf76d9e2ae421c39ef7ed/external/googleapis+/google/devtools/build/v1/BUILD.bazel:81:18: in _java_grpc_library rule @@googleapis+//google/devtools/build/v1:build_java_grpc:
11+
Traceback (most recent call last):
12+
File "/private/var/tmp/_bazel_dws/7fd3cd5077fbf76d9e2ae421c39ef7ed/external/grpc-java+/java_grpc_library.bzl", line 94, column 30, in _java_rpc_library_impl
13+
args.add(toolchain.plugin.files_to_run.executable, format = "--plugin=protoc-gen-rpc-plugin=%s")
14+
Error: Accessing the default provider in this manner is deprecated and will be removed soon. It may be temporarily re-enabled by setting --incompatible_disable_target_default_provider_fields=false. See https://github.com/bazelbuild/bazel/issues/20183 for details.
15+
ERROR: /private/var/tmp/_bazel_dws/7fd3cd5077fbf76d9e2ae421c39ef7ed/external/googleapis+/google/devtools/build/v1/BUILD.bazel:81:18: Analysis of target '@@googleapis+//google/devtools/build/v1:build_java_grpc' failed
16+
ERROR: Analysis of target '//src:bazel' failed; build aborted: Analysis failed
17+
18+
diff --git a/java_grpc_library.bzl b/java_grpc_library.bzl
19+
index 630ced383..e7d133a27 100644
20+
--- a/java_grpc_library.bzl
21+
+++ b/java_grpc_library.bzl
22+
@@ -91,15 +91,15 @@ def _java_rpc_library_impl(ctx):
23+
srcjar = ctx.actions.declare_file("%s-proto-gensrc.jar" % ctx.label.name)
24+
25+
args = ctx.actions.args()
26+
- args.add(toolchain.plugin.files_to_run.executable, format = "--plugin=protoc-gen-rpc-plugin=%s")
27+
+ args.add(toolchain.plugin[DefaultInfo].files_to_run.executable, format = "--plugin=protoc-gen-rpc-plugin=%s")
28+
args.add("--rpc-plugin_out={0}:{1}".format(toolchain.plugin_arg, srcjar.path))
29+
args.add_joined("--descriptor_set_in", descriptor_set_in, join_with = ctx.configuration.host_path_separator)
30+
args.add_all(srcs, map_each = _path_ignoring_repository)
31+
32+
ctx.actions.run(
33+
- inputs = depset(srcs, transitive = [descriptor_set_in, toolchain.plugin.files]),
34+
+ inputs = depset(srcs, transitive = [descriptor_set_in, toolchain.plugin[DefaultInfo].files]),
35+
outputs = [srcjar],
36+
- executable = toolchain.protoc.files_to_run,
37+
+ executable = toolchain.protoc[DefaultInfo].files_to_run,
38+
arguments = [args],
39+
use_default_shell_env = True,
40+
toolchain = None,

third_party/rules_java.patch

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
commit c02b7724a5dcf85bb9c87bc06c1cd0504c0507f9
2+
Author: David Sanderson <[email protected]>
3+
Date: Wed Jun 11 17:35:01 2025 -0400
4+
5+
use DefaultInfo in rules_java
6+
7+
We here address the following obstacles in rules_java to using
8+
Bazel's --incompatible_disable_target_default_provider_fields flag:
9+
10+
ERROR: /private/var/tmp/_bazel_dws/7fd3cd5077fbf76d9e2ae421c39ef7ed/external/rules_java+/toolchains/BUILD:359:27: in java_toolchain rule @@rules_java+//toolchains:toolchain_jdk_21:
11+
Traceback (most recent call last):
12+
File "/private/var/tmp/_bazel_dws/7fd3cd5077fbf76d9e2ae421c39ef7ed/external/rules_java+/java/common/rules/java_toolchain.bzl", line 100, column 45, in _java_toolchain_impl
13+
jacocorunner = ctx.attr.jacocorunner.files_to_run if ctx.attr.jacocorunner else None,
14+
Error: Accessing the default provider in this manner is deprecated and will be removed soon. It may be temporarily re-enabled by setting --incompatible_disable_target_default_provider_fields=false. See https://github.com/bazelbuild/bazel/issues/20183 for details.
15+
ERROR: /private/var/tmp/_bazel_dws/7fd3cd5077fbf76d9e2ae421c39ef7ed/external/rules_java+/toolchains/BUILD:359:27: Analysis of target '@@rules_java+//toolchains:toolchain_jdk_21' failed
16+
ERROR: Analysis of target '//src:bazel' failed; build aborted: Analysis failed
17+
18+
ERROR: /Users/dws/src/bazel-dws/third_party/BUILD:578:20: in java_import rule //third_party:netty_tcnative_checked_in:
19+
Traceback (most recent call last):
20+
File "/private/var/tmp/_bazel_dws/7fd3cd5077fbf76d9e2ae421c39ef7ed/external/rules_java+/java/bazel/rules/bazel_java_import.bzl", line 25, column 34, in _proxy
21+
return bazel_java_import_rule(
22+
File "/private/var/tmp/_bazel_dws/7fd3cd5077fbf76d9e2ae421c39ef7ed/external/rules_java+/java/common/rules/impl/bazel_java_import_impl.bzl", line 132, column 35, in bazel_java_import_rule
23+
collected_jars = _collect_jars(ctx, jars)
24+
File "/private/var/tmp/_bazel_dws/7fd3cd5077fbf76d9e2ae421c39ef7ed/external/rules_java+/java/common/rules/impl/bazel_java_import_impl.bzl", line 38, column 24, in _collect_jars
25+
for jar in info.files.to_list():
26+
Error: Accessing the default provider in this manner is deprecated and will be removed soon. It may be temporarily re-enabled by setting --incompatible_disable_target_default_provider_fields=false. See https://github.com/bazelbuild/bazel/issues/20183 for details.
27+
ERROR: /Users/dws/src/bazel-dws/third_party/BUILD:578:20: Analysis of target '//third_party:netty_tcnative_checked_in' failed
28+
ERROR: Analysis of target '//src:bazel' failed; build aborted: Analysis failed
29+
30+
diff --git a/java/common/rules/impl/bazel_java_import_impl.bzl b/java/common/rules/impl/bazel_java_import_impl.bzl
31+
index 4465670..ce338cb 100644
32+
--- a/java/common/rules/impl/bazel_java_import_impl.bzl
33+
+++ b/java/common/rules/impl/bazel_java_import_impl.bzl
34+
@@ -35,7 +35,7 @@ def _collect_jars(ctx, jars):
35+
for info in jars:
36+
if JavaInfo in info:
37+
fail("'jars' attribute cannot contain labels of Java targets")
38+
- for jar in info.files.to_list():
39+
+ for jar in info[DefaultInfo].files.to_list():
40+
jar_path = jar.dirname + jar.basename
41+
if jars_dict.get(jar_path) != None:
42+
fail("in jars attribute of java_import rule //" + ctx.label.package + ":" + ctx.attr.name + ": " + jar.basename + " is a duplicate")
43+
@@ -179,7 +179,7 @@ def bazel_java_import_rule(
44+
# TODO(kotlaja): Revise if collected_runtimes can be added into construct_defaultinfo directly.
45+
collected_runtimes = []
46+
for runtime_dep in ctx.attr.runtime_deps:
47+
- collected_runtimes.extend(runtime_dep.files.to_list())
48+
+ collected_runtimes.extend(runtime_dep[DefaultInfo].files.to_list())
49+
50+
target["DefaultInfo"] = construct_defaultinfo(
51+
ctx,
52+
diff --git a/java/common/rules/java_toolchain.bzl b/java/common/rules/java_toolchain.bzl
53+
index 2e4fc67..fe32fc3 100644
54+
--- a/java/common/rules/java_toolchain.bzl
55+
+++ b/java/common/rules/java_toolchain.bzl
56+
@@ -96,13 +96,13 @@ def _java_toolchain_impl(ctx):
57+
oneversion_allowlist = ctx.file.oneversion_allowlist if ctx.file.oneversion_allowlist else ctx.file.oneversion_whitelist
58+
java_toolchain_info = _new_javatoolchaininfo(
59+
bootclasspath = bootclasspath_info.bootclasspath,
60+
- ijar = ctx.attr.ijar.files_to_run if ctx.attr.ijar else None,
61+
- jacocorunner = ctx.attr.jacocorunner.files_to_run if ctx.attr.jacocorunner else None,
62+
+ ijar = ctx.attr.ijar[DefaultInfo].files_to_run if ctx.attr.ijar else None,
63+
+ jacocorunner = ctx.attr.jacocorunner[DefaultInfo].files_to_run if ctx.attr.jacocorunner else None,
64+
java_runtime = java_runtime,
65+
jvm_opt = depset(get_internal_java_common().expand_java_opts(ctx, "jvm_opts", tokenize = False, exec_paths = True)),
66+
label = ctx.label,
67+
- proguard_allowlister = ctx.attr.proguard_allowlister.files_to_run if ctx.attr.proguard_allowlister else None,
68+
- single_jar = ctx.attr.singlejar.files_to_run,
69+
+ proguard_allowlister = ctx.attr.proguard_allowlister[DefaultInfo].files_to_run if ctx.attr.proguard_allowlister else None,
70+
+ single_jar = ctx.attr.singlejar[DefaultInfo].files_to_run,
71+
source_version = ctx.attr.source_version,
72+
target_version = ctx.attr.target_version,
73+
tools = depset(ctx.files.tools),
74+
@@ -131,7 +131,7 @@ def _java_toolchain_impl(ctx):
75+
_javac_supports_worker_multiplex_sandboxing = ctx.attr.javac_supports_worker_multiplex_sandboxing,
76+
_jspecify_info = _get_jspecify_info(ctx),
77+
_local_java_optimization_config = ctx.files._local_java_optimization_configuration,
78+
- _one_version_tool = ctx.attr.oneversion.files_to_run if ctx.attr.oneversion else None,
79+
+ _one_version_tool = ctx.attr.oneversion[DefaultInfo].files_to_run if ctx.attr.oneversion else None,
80+
_one_version_allowlist = oneversion_allowlist,
81+
_one_version_allowlist_for_tests = ctx.file.oneversion_allowlist_for_tests,
82+
_package_configuration = [dep[JavaPackageConfigurationInfo] for dep in ctx.attr.package_configuration],
83+
@@ -171,7 +171,7 @@ def _get_javac_opts(ctx):
84+
def _get_android_lint_tool(ctx):
85+
if not ctx.attr.android_lint_runner:
86+
return None
87+
- files_to_run = ctx.attr.android_lint_runner.files_to_run
88+
+ files_to_run = ctx.attr.android_lint_runner[DefaultInfo].files_to_run
89+
if not files_to_run or not files_to_run.executable:
90+
fail(ctx.attr.android_lint_runner.label, "does not refer to a valid executable target")
91+
return struct(
92+
@@ -186,7 +186,7 @@ def _get_tool_from_ctx(ctx, tool_attr, data_attr, opts_attr):
93+
dep = getattr(ctx.attr, tool_attr)
94+
if not dep:
95+
return None
96+
- files_to_run = dep.files_to_run
97+
+ files_to_run = dep[DefaultInfo].files_to_run
98+
if not files_to_run or not files_to_run.executable:
99+
fail(dep.label, "does not refer to a valid executable target")
100+
data = getattr(ctx.attr, data_attr)
101+
@@ -200,7 +200,7 @@ def _get_tool_from_executable(ctx, attr_name, data = [], jvm_opts = []):
102+
dep = getattr(ctx.attr, attr_name)
103+
if not dep:
104+
return None
105+
- files_to_run = dep.files_to_run
106+
+ files_to_run = dep[DefaultInfo].files_to_run
107+
if not files_to_run or not files_to_run.executable:
108+
fail(dep.label, "does not refer to a valid executable target")
109+
return struct(tool = files_to_run, data = depset(data), jvm_opts = depset(jvm_opts))

0 commit comments

Comments
 (0)