Skip to content

Commit 0522f8e

Browse files
comiuscopybara-github
authored andcommitted
Disable autoloads for Python, Java, Proto, Shell and Android
For Bazel 9 release, all the loads should be explicitly added to the repositories. To temporary reenable pass in flag: ``` --incompatible_autoload_externally=@rules_python,+java_common,+JavaInfo,+JavaPluginInfo,ProguardSpecProvider,java_binary,java_import,java_library,java_plugin,java_test,java_runtime,java_toolchain,java_package_configuration,@com_google_protobuf,@rules_shell,@rules_android,+@rules_cc ``` Downstream test: https://buildkite.com/bazel/bazel-at-head-plus-downstream/builds/4929 New failures: - Bazelisk Upstream fixes: bazelbuild/bazel-central-registry#5818 RELNOTES[INC]: autoloads are disabled, issue #23043 Closes #26906. PiperOrigin-RevId: 804886816 Change-Id: I36b2636926351e3d07bab3921e25ed9d4eeb6ff2
1 parent 5409637 commit 0522f8e

File tree

17 files changed

+728
-195
lines changed

17 files changed

+728
-195
lines changed

BUILD

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,18 @@ genrule(
7272
"MODULE.bazel",
7373
"//third_party/remoteapis:MODULE.bazel",
7474
"//third_party:BUILD",
75+
"//third_party:chicory.patch",
7576
"//third_party:protobuf.patch",
77+
"//third_party:protoc-gen-validate.patch",
78+
"//third_party:googleapis.patch",
7679
"//third_party:grpc-java.patch",
7780
"//third_party:grpc-java-12207.patch",
7881
"//third_party:grpc-java-12222.patch",
82+
"//third_party:grpc-java-addloads.patch",
7983
"//third_party:rules_jvm_external_6.5.patch",
8084
"//third_party:rules_graalvm_fix.patch",
8185
"//third_party:rules_graalvm_unicode.patch",
86+
"//third_party:zstd-jni.patch",
8287
],
8388
outs = ["MODULE.bazel.lock.dist"],
8489
cmd = " && ".join([

MODULE.bazel

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ bazel_dep(name = "platforms", version = "1.0.0")
2727
bazel_dep(name = "protobuf", version = "32.0", repo_name = "com_google_protobuf")
2828
bazel_dep(name = "rules_graalvm", version = "0.11.1")
2929
bazel_dep(name = "rules_java", version = "8.15.2")
30-
bazel_dep(name = "rules_jvm_external", version = "6.5")
30+
bazel_dep(name = "rules_jvm_external", version = "6.6")
3131
bazel_dep(name = "rules_license", version = "1.0.0")
3232
bazel_dep(name = "rules_pkg", version = "1.0.1")
3333
bazel_dep(name = "rules_python", version = "1.4.1")
3434
bazel_dep(name = "rules_shell", version = "0.3.0")
3535
bazel_dep(name = "rules_testing", version = "0.6.0")
3636
bazel_dep(name = "stardoc", version = "0.7.2", repo_name = "io_bazel_skydoc")
37-
bazel_dep(name = "with_cfg.bzl", version = "0.6.0")
37+
bazel_dep(name = "with_cfg.bzl", version = "0.10.3")
3838
bazel_dep(name = "zlib", version = "1.3.1.bcr.5")
3939
bazel_dep(name = "zstd-jni", version = "1.5.6-9")
4040

@@ -63,7 +63,7 @@ single_version_override(
6363
module_name = "rules_jvm_external",
6464
patch_strip = 1,
6565
patches = ["//third_party:rules_jvm_external_6.5.patch"],
66-
version = "6.5",
66+
version = "6.6",
6767
)
6868

6969
# TODO(pcloudy): Remove once the next version of rules_graalvm is available.
@@ -76,6 +76,32 @@ single_version_override(
7676
],
7777
)
7878

79+
single_version_override(
80+
module_name = "zstd-jni",
81+
patch_strip = 1,
82+
patches = ["//third_party:zstd-jni.patch"],
83+
)
84+
85+
single_version_override(
86+
module_name = "chicory",
87+
patch_strip = 1,
88+
patches = ["//third_party:chicory.patch"],
89+
)
90+
91+
single_version_override(
92+
module_name = "googleapis",
93+
patch_strip = 1,
94+
patches = ["//third_party:googleapis.patch"],
95+
version = "0.0.0-20250604-de157ca3",
96+
)
97+
98+
single_version_override(
99+
module_name = "protoc-gen-validate",
100+
patch_strip = 1,
101+
patches = ["//third_party:protoc-gen-validate.patch"],
102+
version = "1.2.1.bcr.1",
103+
)
104+
79105
# 1. Expose @com_google_protobuf//java/core:lite_runtime_only
80106
# due to https://github.com/protocolbuffers/protobuf/commit/079be27925955348d1b3cb30ffbfa33dcec5778c
81107
# We need to package the lite runtime jar for Bazel's bootstrap build
@@ -99,6 +125,7 @@ single_version_override(
99125
"//third_party:grpc-java.patch",
100126
"//third_party:grpc-java-12207.patch",
101127
"//third_party:grpc-java-12222.patch",
128+
"//third_party:grpc-java-addloads.patch",
102129
],
103130
)
104131

MODULE.bazel.lock

Lines changed: 7 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/MODULE.tools

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ bazel_dep(name = "rules_cc", version = "0.2.3")
4242
bazel_dep(name = "rules_python", version = "1.4.1")
4343
bazel_dep(name = "rules_shell", version = "0.3.0")
4444
bazel_dep(name = "apple_support", version = "1.22.1", repo_name = None)
45+
bazel_dep(name = "rules_swift", version = "2.8.2", repo_name = None) # version bump, older versions don't load JavaInfo
4546
# add rules_android
4647

4748
register_toolchains(

src/main/java/com/google/devtools/build/lib/packages/semantics/FlagConstants.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,6 @@ private FlagConstants() {}
2626

2727
// TODO - ilist@: once Java providers are removed, the whole line can be compressed to "@rules_java"
2828
public static final String DEFAULT_INCOMPATIBLE_AUTOLOAD_EXTERNALLY =
29-
"@rules_python," +
30-
"+java_common,+JavaInfo,+JavaPluginInfo,ProguardSpecProvider," +
31-
"java_binary,java_import,java_library,java_plugin,java_test," +
32-
"java_runtime,java_toolchain,java_package_configuration," +
33-
"@com_google_protobuf," +
34-
"@rules_shell," +
35-
"@rules_android," +
3629
"+@rules_cc";
3730

3831
public static final String DEFAULT_EXPERIMENTAL_STARLARK_TYPES = "false";

src/test/py/bazel/bzlmod/bazel_module_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ def testLoadRulesJavaSymbolThroughBazelTools(self):
823823
self.RunBazel(['build', '@data//:data.txt'])
824824

825825
def testHttpJar(self):
826-
"""Tests that using http_jar does not require a bazel_dep on rules_java."""
826+
"""Tests that using http_jar works with a bazel_dep on rules_java."""
827827

828828
my_jar_path = self.ScratchFile('my_jar.jar')
829829
my_jar_uri = pathlib.Path(my_jar_path).as_uri()
@@ -846,6 +846,7 @@ def testHttpJar(self):
846846
')',
847847
],
848848
)
849+
self.AddBazelDep('rules_java')
849850

850851
self.RunBazel(['build', '@my_jar//jar'])
851852

src/test/py/bazel/bzlmod/bazel_repo_mapping_test.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,20 @@ def testBashRunfilesLibraryRepoMapping(self):
198198
)
199199

200200
self.main_registry.createLocalPathModule(
201-
'test', '1.0', 'test', {'data': '1.0'}
201+
'test',
202+
'1.0',
203+
'test',
204+
{
205+
'data': '1.0',
206+
'rules_shell': self.GetModuleVersionFromDefaultLockFile(
207+
'rules_shell'
208+
),
209+
},
202210
)
203211
scratchFile(
204212
projects_dir.joinpath('test', 'BUILD'),
205213
[
214+
'load("@rules_shell//shell:sh_test.bzl", "sh_test")',
206215
'sh_test(',
207216
' name = "test",',
208217
' srcs = ["test.sh"],',
@@ -260,11 +269,18 @@ def testLegacyCppRunfilesLibraryRepoMapping(self):
260269
)
261270

262271
self.main_registry.createLocalPathModule(
263-
'test', '1.0', 'test', {'data': '1.0'}
272+
'test',
273+
'1.0',
274+
'test',
275+
{
276+
'data': '1.0',
277+
'rules_cc': self.GetModuleVersionFromDefaultLockFile('rules_cc'),
278+
},
264279
)
265280
scratchFile(
266281
projects_dir.joinpath('test', 'BUILD'),
267282
[
283+
'load("@rules_cc//cc:cc_test.bzl", "cc_test")',
268284
'cc_test(',
269285
' name = "test",',
270286
' srcs = ["test.cpp"],',
@@ -312,11 +328,18 @@ def testCppRunfilesLibraryRepoMapping(self):
312328
)
313329

314330
self.main_registry.createLocalPathModule(
315-
'test', '1.0', 'test', {'data': '1.0', 'rules_cc': '0.0.17'}
331+
'test',
332+
'1.0',
333+
'test',
334+
{
335+
'data': '1.0',
336+
'rules_cc': self.GetModuleVersionFromDefaultLockFile('rules_cc'),
337+
},
316338
)
317339
scratchFile(
318340
projects_dir.joinpath('test', 'BUILD'),
319341
[
342+
'load("@rules_cc//cc:cc_test.bzl", "cc_test")',
320343
'cc_test(',
321344
' name = "test",',
322345
' srcs = ["test.cpp"],',
@@ -364,11 +387,20 @@ def testJavaRunfilesLibraryRepoMapping(self):
364387
)
365388

366389
self.main_registry.createLocalPathModule(
367-
'test', '1.0', 'test', {'data': '1.0'}
390+
'test',
391+
'1.0',
392+
'test',
393+
{
394+
'data': '1.0',
395+
'rules_java': self.GetModuleVersionFromDefaultLockFile(
396+
'rules_java'
397+
),
398+
},
368399
)
369400
scratchFile(
370401
projects_dir.joinpath('test', 'BUILD'),
371402
[
403+
'load("@rules_java//java:java_test.bzl", "java_test")',
372404
'java_test(',
373405
' name = "test",',
374406
' srcs = ["Test.java"],',

src/test/shell/bazel/external_integration_test.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2583,6 +2583,8 @@ EOF
25832583

25842584
touch $test_repo1/REPO.bazel
25852585
cat > $test_repo1/a/BUILD <<'EOF'
2586+
load("@rules_java//java:java_library.bzl", "java_library")
2587+
25862588
package(default_visibility = ["//visibility:public"])
25872589
25882590
java_library(
@@ -2936,11 +2938,13 @@ local_repository(
29362938
path="other_repo",
29372939
)
29382940
EOF
2941+
add_rules_java "MODULE.bazel"
29392942

29402943
mkdir -p other_repo/external/java/a
29412944
touch other_repo/REPO.bazel
29422945

29432946
cat > other_repo/external/java/a/BUILD <<EOF
2947+
load("@rules_java//java:java_library.bzl", "java_library")
29442948
java_library(name='a', srcs=['A.java'])
29452949
EOF
29462950

@@ -2964,11 +2968,13 @@ local_repository(
29642968
path="other_repo",
29652969
)
29662970
EOF
2971+
add_rules_java "MODULE.bazel"
29672972

29682973
mkdir -p other_repo/external/java/a
29692974
touch other_repo/REPO.bazel
29702975

29712976
cat > other_repo/BUILD <<EOF
2977+
load("@rules_java//java:java_library.bzl", "java_library")
29722978
java_library(name='a', srcs=['external/java/a/A.java'])
29732979
EOF
29742980

src/test/shell/bazel/local_repository_test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,7 @@ public class A {
12911291
}
12921292
EOF
12931293
cat > a/BUILD <<EOF
1294-
load("@rules_java//java:java_library.bzl", "java_library")
1294+
load("@rules_java//java:java_binary.bzl", "java_binary")
12951295
12961296
java_binary(
12971297
name = "a",

src/test/shell/integration/incompatible_autoload_externally_test.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -569,11 +569,11 @@ my_java_library(
569569
)
570570
EOF
571571

572-
bazel query --noincompatible_disable_autoloads_in_main_repo //foo >&$TEST_log 2>&1 || fail "build failed"
573-
bazel query --incompatible_disable_autoloads_in_main_repo //foo >&$TEST_log 2>&1 && fail "build unexpectedly succeeded"
572+
bazel query --incompatible_autoload_externally=java_library --noincompatible_disable_autoloads_in_main_repo //foo >&$TEST_log 2>&1 || fail "build failed"
573+
bazel query --incompatible_autoload_externally=java_library --incompatible_disable_autoloads_in_main_repo //foo >&$TEST_log 2>&1 && fail "build unexpectedly succeeded"
574574
expect_log "name 'java_library' is not defined"
575-
bazel query --noincompatible_disable_autoloads_in_main_repo //bar >&$TEST_log 2>&1 || fail "build failed"
576-
bazel query --incompatible_disable_autoloads_in_main_repo //bar >&$TEST_log 2>&1 && fail "build unexpectedly succeeded"
575+
bazel query --incompatible_autoload_externally=java_library --noincompatible_disable_autoloads_in_main_repo //bar >&$TEST_log 2>&1 || fail "build failed"
576+
bazel query --incompatible_autoload_externally=java_library --incompatible_disable_autoloads_in_main_repo //bar >&$TEST_log 2>&1 && fail "build unexpectedly succeeded"
577577
expect_log "Error: no native function or rule 'java_library'"
578578
}
579579

0 commit comments

Comments
 (0)