Skip to content

Commit 6f3840e

Browse files
authored
Add load statements after disabling autoloads (#391)
Explicitly loads all symbols affected by `--incompatible_disable_autoloads_in_main_repo` to fix `last_green` Bazel builds. Adds the flag to `.bazelrc`, adds `rules_shell` as a dependency, and contains lots of other Buildifier formatting touch ups. bazelbuild/bazel@d87eaf5 from 2025-05-08 at 8:03am EDT flipped `--incompatible_disable_autoloads_in_main_repo` to `true` to prepare for Bazel 9. See also bazel-contrib/rules_scala#1738. Before this change, setting the flag caused these errors: ```txt $ bazel build --incompatible_disable_autoloads_in_main_repo //... ERROR: java/com/engflow/notificationqueue/demoserver/BUILD:5:1: name 'proto_library' is not defined ERROR: /demoserver/BUILD:10:1: name 'java_proto_library' is not defined (did you mean 'java_grpc_library'?) ERROR: docker/network/BUILD:19:10: //docker/network:docker-network-test: no such attribute 'srcs' in 'java_test' rule ERROR: docker/network/BUILD:19:10: //docker/network:docker-network-test: no such attribute 'test_class' in 'java_test' rule ERROR: docker/sandbox/BUILD:15:12: //docker/sandbox:hello-java: no such attribute 'srcs' in 'java_binary' rule ERROR: docker/sandbox/BUILD:15:12: //docker/sandbox:hello-java: no such attribute 'main_class' in 'java_binary' rule ERROR: docker/sysbox/dind_test/BUILD:15:1: name 'sh_test' is not defined (did you mean 'cc_test'?) ERROR: package contains errors: docker/sysbox/dind_test ERROR: python/pytest/BUILD:3:1: name 'py_library' is not defined (did you mean 'cc_library'?) ERROR: package contains errors: docker/sandbox ERROR: package contains errors: java/com/engflow/notificationqueue/demoserver ERROR: docker/network/BUILD:39:13: //docker/network:jdk: no such attribute 'java_home' in 'java_runtime' rule ERROR: package contains errors: docker/network ERROR: package contains errors: python/pytest ERROR: java/com/engflow/example/BUILD:3:13: //java/com/engflow/example:example: no such attribute 'srcs' in 'java_library' rule ERROR: java/com/engflow/example/BUILD:8:10: //java/com/engflow/example:ExampleTest: no such attribute 'srcs' in 'java_test' rule ERROR: java/com/engflow/example/BUILD:8:10: //java/com/engflow/example:ExampleTest: no such attribute 'deps' in 'java_test' rule ERROR: package contains errors: java/com/engflow/example ERROR: java/com/engflow/notificationqueue/BUILD:5:12: //java/com/engflow/notificationqueue:client: no such attribute 'srcs' in 'java_binary' rule ERROR: java/com/engflow/notificationqueue/BUILD:5:12: //java/com/engflow/notificationqueue:client: no such attribute 'main_class' in 'java_binary' rule ERROR: java/com/engflow/notificationqueue/BUILD:5:12: //java/com/engflow/notificationqueue:client: no such attribute 'deps' in 'java_binary' rule ERROR: package contains errors: java/com/engflow/notificationqueue WARNING: Target pattern parsing failed. ERROR: Skipping '//...': Error evaluating '//...': error loading package 'docker/network': Package 'docker/network' contains errors ERROR: Error evaluating '//...': error loading package 'docker/network': Package 'docker/network' contains errors INFO: Elapsed time: 2.821s INFO: 0 processes. ERROR: Build did NOT complete successfully ``` Applied the fixes using Buildifier 8.2.0 with the following script: ```bash WARNINGS=( $(buildifier --lint=warn -r . 2>&1 | grep -- native- | awk '{print $2}' | sort | uniq | sed -e 's/:$//') ) IFS=, WARNINGS="${WARNINGS[*]}" echo "warnings: ${WARNINGS}" buildifier --lint=fix --warnings="$WARNINGS" -r . ```
1 parent 0a3ea9d commit 6f3840e

File tree

36 files changed

+167
-111
lines changed

36 files changed

+167
-111
lines changed

.bazelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
common --@aspect_rules_ts//ts:skipLibCheck=honor_tsconfig
33
common --@aspect_rules_ts//ts:default_to_tsc_transpiler
44
common --noincompatible_check_sharding_support
5+
common --incompatible_disable_autoloads_in_main_repo
56

67
# Remove once proto toolchainization becomes the default
78
# - https://bazel.build/reference/command-line-reference#flag--incompatible_enable_proto_toolchain_resolution

MODULE.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,5 @@ scala_protoc = use_extension(
174174
dev_dependency = True,
175175
)
176176
use_repo(scala_protoc, "rules_scala_protoc_toolchains")
177+
178+
bazel_dep(name = "rules_shell", version = "0.4.1")

MODULE.bazel.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

buck2/cpp/platforms/defs.bzl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ platforms = rule(
6161
attrs = {
6262
"cpu_configuration": attrs.dep(providers = [ConfigurationInfo]),
6363
"os_configuration": attrs.dep(providers = [ConfigurationInfo]),
64-
},
65-
impl = _platforms
64+
},
65+
impl = _platforms,
6666
)
6767

6868
action_keys = rule(
69-
attrs = {
69+
attrs = {
7070
"cell": attrs.string(),
7171
"mode": attrs.string(),
72-
},
73-
impl = _action_keys
72+
},
73+
impl = _action_keys,
7474
)

buck2/golang/platforms/defs.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ def _action_keys(ctx):
5858

5959
platforms = rule(
6060
attrs = {},
61-
impl = _platforms
61+
impl = _platforms,
6262
)
6363

6464
action_keys = rule(
65-
attrs = {
65+
attrs = {
6666
"cell": attrs.string(),
6767
"mode": attrs.string(),
68-
},
69-
impl = _action_keys
68+
},
69+
impl = _action_keys,
7070
)

buck2/golang/toolchains/defs.bzl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ load("@prelude//go_bootstrap:go_bootstrap.bzl", "GoBootstrapToolchainInfo")
1717
load("@prelude//utils:cmd_script.bzl", "ScriptOs", "cmd_script")
1818

1919
def _remote_go_bootstrap_toolchain_impl(ctx):
20-
go_arch = "amd64"
20+
go_arch = "amd64"
2121
go_os = "linux"
2222

2323
script_os = ScriptOs("unix")
@@ -47,7 +47,7 @@ remote_go_bootstrap_toolchain = rule(
4747
)
4848

4949
def _remote_go_toolchain_impl(ctx):
50-
go_arch = "amd64"
50+
go_arch = "amd64"
5151
go_os = "linux"
5252

5353
script_os = ScriptOs("unix")
@@ -76,7 +76,6 @@ def _remote_go_toolchain_impl(ctx):
7676
compiler_flags = [],
7777
),
7878
]
79-
8079

8180
remote_go_toolchain = rule(
8281
impl = _remote_go_toolchain_impl,

buck2/python/platforms/defs.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ def _action_keys(ctx):
5656

5757
platforms = rule(
5858
attrs = {},
59-
impl = _platforms
59+
impl = _platforms,
6060
)
6161

6262
action_keys = rule(
63-
attrs = {
63+
attrs = {
6464
"cell": attrs.string(),
6565
"mode": attrs.string(),
66-
},
67-
impl = _action_keys
66+
},
67+
impl = _action_keys,
6868
)

buck2/python/toolchains/defs.bzl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ remote_python_toolchain = rule(
5959
"_make_source_db": attrs.default_only(attrs.dep(providers = [RunInfo], default = "prelude//python/tools:make_source_db")),
6060
"_make_source_db_no_deps": attrs.default_only(attrs.dep(providers = [RunInfo], default = "prelude//python/tools:make_source_db_no_deps")),
6161
"_runtime_library": attrs.default_only(attrs.dep(providers = [ArtifactGroupInfo], default = "prelude//python/runtime:bootstrap_files")),
62-
6362
},
6463
is_toolchain_rule = True,
6564
)

buck2/rust/platforms/defs.bzl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ platforms = rule(
6262
attrs = {
6363
"cpu_configuration": attrs.dep(providers = [ConfigurationInfo]),
6464
"os_configuration": attrs.dep(providers = [ConfigurationInfo]),
65-
},
66-
impl = _platforms
65+
},
66+
impl = _platforms,
6767
)
6868

6969
action_keys = rule(
70-
attrs = {
70+
attrs = {
7171
"cell": attrs.string(),
7272
"mode": attrs.string(),
73-
},
74-
impl = _action_keys
73+
},
74+
impl = _action_keys,
7575
)

buck2/rust/toolchains/defs.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
load("@prelude//cxx:cxx_toolchain_types.bzl", "LinkerType")
1516
load("@prelude//rust:rust_toolchain.bzl", "PanicRuntime", "RustToolchainInfo")
1617
load("@prelude//rust/tools:attrs.bzl", "internal_tool_attrs")
17-
load("@prelude//cxx:cxx_toolchain_types.bzl", "LinkerType")
1818
load("@prelude//toolchains:cxx.bzl", "CxxToolsInfo")
1919

2020
# This def is similar to the one in https://github.com/facebook/buck2/blob/804d62242214455d51787f7c8c96a1e12c75ec32/prelude/toolchains/cxx/clang/tools.bzl
@@ -42,7 +42,7 @@ path_clang_tools = rule(
4242
attrs = {},
4343
)
4444

45-
def _remote_rust_toolchain_impl(ctx):
45+
def _remote_rust_toolchain_impl(ctx):
4646
return [
4747
DefaultInfo(),
4848
RustToolchainInfo(

bzlmod/canonical-repo-name-injection/BUILD

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
# License for the specific language governing permissions and limitations under
1313
# the License.
1414

15+
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
16+
load("@rules_js//js:defs.bzl", "js_binary")
1517
load(
1618
"//:repo-names.bzl",
1719
"canonical_repo",
18-
"workspace_root",
19-
"repo_name_variable",
20-
"repo_dir_variable",
2120
"gen_js_constants",
21+
"repo_dir_variable",
22+
"repo_name_variable",
23+
"workspace_root",
2224
)
23-
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
24-
load("@rules_js//js:defs.bzl", "js_binary")
2525

2626
# This value propagates through the rules below.
2727
# Try it with other targets of your choosing!
@@ -37,8 +37,10 @@ genrule(
3737
name = "repo-macros",
3838
outs = ["repo-macros.txt"],
3939
cmd = "printf '%s\n canonical_name: %s\n workspace_root: %s\n' >$@" % (
40-
repo_target, canonical_repo(repo_target), workspace_root(repo_target)
41-
)
40+
repo_target,
41+
canonical_repo(repo_target),
42+
workspace_root(repo_target),
43+
),
4244
)
4345

4446
# Demonstrates the custom Make variable-based approach. Depends on the
@@ -54,7 +56,7 @@ genrule(
5456
toolchains = [
5557
":repo-name",
5658
":repo-dir",
57-
]
59+
],
5860
)
5961

6062
# This alias demonstrates how the rules from `repo-names.bzl` work with resolved
@@ -97,34 +99,34 @@ repo_dir_variable(
9799
# - where the repo dir is found when running under `bazel run` vs `node`
98100
js_binary(
99101
name = "repo-dir-check",
100-
entry_point = "repo-dir-check.mjs",
101102
data = [
102-
":constants-impl",
103-
repo_target,
103+
":constants-impl",
104+
repo_target,
104105
],
106+
entry_point = "repo-dir-check.mjs",
105107
)
106108

107109
# Determines which rule generates the `constants.js` module used by
108110
# `:repo-dir-check`, based on the value of the `--//:constants` flag.
109111
genrule(
110112
name = "constants-impl",
111-
outs = ["constants.js"],
112113
srcs = select({
113-
":genrule": [":genrule-constants"],
114+
":genrule": [":genrule-constants"],
114115
":custom-rule": [":custom-rule-constants"],
115116
}),
117+
outs = ["constants.js"],
116118
cmd = "cp $< $@",
117119
)
118120

119121
# The `--//:constants` command line flag determines whether `:constants-impl`
120122
# selects `:genrule-constants` or `:custom-rule-constants` as input.
121123
string_flag(
122124
name = "constants",
125+
build_setting_default = "genrule",
123126
values = [
124127
"genrule",
125128
"custom-rule",
126129
],
127-
build_setting_default = "genrule",
128130
)
129131

130132
config_setting(
@@ -152,7 +154,7 @@ genrule(
152154
name = "genrule-constants",
153155
srcs = [":repo-target"],
154156
outs = ["genrule-constants.js"],
155-
cmd = r"""printf 'module.exports.%%s;\n' \
157+
cmd = r"""printf 'module.exports.%%s;\n' \
156158
'ruleName = "genrule-constants"' \
157159
'target = "%s"' \
158160
'binDir = "$(BINDIR)"' \
@@ -161,10 +163,10 @@ genrule(
161163
'macroDir = "%s"' \
162164
'repoName = "$(repo-name)"' \
163165
'repoDir = "$(repo-dir)"' >$@""" % (
164-
repo_target,
165-
canonical_repo(repo_target),
166-
workspace_root(repo_target)
167-
),
166+
repo_target,
167+
canonical_repo(repo_target),
168+
workspace_root(repo_target),
169+
),
168170
toolchains = [
169171
":repo-name",
170172
":repo-dir",
@@ -191,14 +193,14 @@ genrule(
191193
# Replacing `repo_target` with the string ":repo-target" in the macros below
192194
# will produce the empty string, since the macros won't see the resolved alias.
193195
gen_js_constants(
194-
name = "custom-rule-constants",
195-
deps = [":repo-target"],
196-
vars = {
197-
"target": repo_target,
198-
"location": "$(rlocationpaths :repo-target)",
196+
name = "custom-rule-constants",
197+
repo_dirs = {":repo-target": "repoDir"},
198+
repo_names = {":repo-target": "repoName"},
199+
vars = {
200+
"target": repo_target,
201+
"location": "$(rlocationpaths :repo-target)",
199202
"macroName": canonical_repo(repo_target),
200-
"macroDir": workspace_root(repo_target),
203+
"macroDir": workspace_root(repo_target),
201204
},
202-
repo_names = {":repo-target": "repoName"},
203-
repo_dirs = {":repo-target": "repoDir"},
205+
deps = [":repo-target"],
204206
)

bzlmod/canonical-repo-name-injection/MODULE.bazel

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
"""Example module for canonical repo name injection"""
1616

1717
# Main module
18-
module(name = "frobozz", version = "1.2.3")
18+
module(
19+
name = "frobozz",
20+
version = "1.2.3",
21+
)
1922

2023
# aspect_rules_js
2124
bazel_dep(name = "aspect_rules_js", version = "2.0.1", repo_name = "rules_js")

bzlmod/canonical-repo-name-injection/repo-names.bzl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ def _variable_info(ctx, value):
3737

3838
repo_name_variable = rule(
3939
implementation = lambda ctx: _variable_info(
40-
ctx, ctx.attr.dep.label.repo_name
40+
ctx,
41+
ctx.attr.dep.label.repo_name,
4142
),
4243
doc = "Defines a custom variable for its dependency's repository name",
4344
attrs = {
@@ -50,7 +51,8 @@ repo_name_variable = rule(
5051

5152
repo_dir_variable = rule(
5253
implementation = lambda ctx: _variable_info(
53-
ctx, ctx.attr.dep.label.workspace_root
54+
ctx,
55+
ctx.attr.dep.label.workspace_root,
5456
),
5557
doc = "Defines a custom variable for its dependency's repository dir",
5658
attrs = {
@@ -96,7 +98,7 @@ def _runfiles(ctx, sources, deps):
9698

9799
def _gen_js_constants_impl(ctx):
98100
"""Generate a JavaScript module exporting specified constants."""
99-
items = {"ruleName": ctx.attr.name, "binDir": ctx.bin_dir.path}
101+
items = {"ruleName": ctx.attr.name, "binDir": ctx.bin_dir.path}
100102
items |= {k: ctx.expand_location(v) for k, v in ctx.attr.vars.items()}
101103
items |= {v: k.label.repo_name for k, v in ctx.attr.repo_names.items()}
102104
items |= {v: k.label.workspace_root for k, v in ctx.attr.repo_dirs.items()}
@@ -108,8 +110,8 @@ def _gen_js_constants_impl(ctx):
108110

109111
sources = depset([outfile])
110112
deps = ctx.attr.deps + \
111-
ctx.attr.repo_names.keys() + \
112-
ctx.attr.repo_dirs.keys()
113+
ctx.attr.repo_names.keys() + \
114+
ctx.attr.repo_dirs.keys()
113115

114116
return [
115117
_js_info(ctx.label, sources, deps),

cpp/BUILD

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
2+
load("@rules_cc//cc:cc_library.bzl", "cc_library")
3+
load("@rules_cc//cc:cc_test.bzl", "cc_test")
4+
15
cc_binary(
26
name = "cpp",
37
srcs = ["main.cc"],
@@ -14,7 +18,7 @@ cc_library(
1418

1519
cc_test(
1620
name = "cpp_test",
21+
size = "small",
1722
srcs = ["hello_test.cc"],
1823
deps = [":cpp_lib"],
19-
size = "small",
2024
)

docker/network/BUILD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
load("@rules_java//java:java_test.bzl", "java_test")
16+
load("@rules_java//java/toolchains:java_runtime.bzl", "java_runtime")
17+
1518
# Built from "Dockerfile"
1619
# TODO: edit this value to match your Docker registry, image name, and digest
1720
DOCKER_JDK_PSQL = "docker://gcr.io/YOUR-IMAGE-NAME@sha256:b6ed8f68abd6e23409ee7a500c2c50a8064cea11071ac447a59b88e6afa4c220"

docker/sandbox/BUILD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
2+
load("@rules_java//java:java_binary.bzl", "java_binary")
3+
14
genrule(
25
name = "hello",
36
srcs = ["dep%d" % i for i in range(3)],

docker/sysbox/dind_test/BUILD

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
load("@rules_shell//shell:sh_test.bzl", "sh_test")
16+
1517
sh_test(
1618
name = "check_docker",
1719
srcs = ["check_docker.sh"],
1820
exec_properties = {
1921
# Replace the container-image below to use the one you created.
2022
"container-image": "docker://645088952840.dkr.ecr.eu-west-1.amazonaws.com/engflow-ci/debian12-dind-x64@sha256:e9715893e041427c283808db96760634b47b276d35bef4fc2af3990553f94262",
2123
"dockerRuntime": "sysbox-runc",
22-
"Pool": "ci_sysbox_x64", # this can change depending on what pool has sysbox enabled
24+
"Pool": "ci_sysbox_x64", # this can change depending on what pool has sysbox enabled
2325
"dockerNetwork": "standard",
2426
# DO NOT ENABLE!!! "dockerSiblingContainers": "True",
2527
# it will cause the worker to mount /var/run/docker.sock
@@ -28,5 +30,5 @@ sh_test(
2830
# DO NOT ENABLE!!! "dockerPrivileged": "True",
2931
# sysbox containers will refuse to start
3032
},
31-
tags = ["manual"]
33+
tags = ["manual"],
3234
)

0 commit comments

Comments
 (0)