Skip to content

Commit 8c66239

Browse files
Move module_ctx.watch to after lockfile repin (#3932)
In bazel 9, module_ctx.read verifies digests for files already read. If repin is requested, the content of the lockfile may change and cause bazel to hard crash. relates to: bazelbuild/bazel#29114
1 parent 5bad824 commit 8c66239

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

crate_universe/extensions.bzl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,18 +1112,15 @@ def _crate_impl(module_ctx):
11121112
fail("Spec specified for repo {}, but the module defined repositories {}".format(repo, local_repos))
11131113

11141114
for cfg in mod.tags.from_cargo + mod.tags.from_specs:
1115-
# Preload all external repositories. Calling `module_ctx.watch` will cause restarts of the implementation
1116-
# function of the module extension when the file has changed.
1115+
# Watch inputs not modified by the generator. Calling `module_ctx.watch` will cause restarts of
1116+
# the implementation function of the module extension when the file has changed.
11171117
if cfg.cargo_lockfile:
11181118
module_ctx.watch(cfg.cargo_lockfile)
1119-
if cfg.lockfile:
1120-
module_ctx.watch(cfg.lockfile)
11211119
if cfg.cargo_config:
11221120
module_ctx.watch(cfg.cargo_config)
11231121
if hasattr(cfg, "manifests"):
11241122
for m in cfg.manifests:
11251123
module_ctx.watch(m)
1126-
11271124
cargo_path, rustc_path = _get_host_cargo_rustc(module_ctx, host_triple, cfg.host_tools)
11281125
cargo_bazel_fn = new_cargo_bazel_fn(
11291126
repository_ctx = module_ctx,
@@ -1180,6 +1177,12 @@ def _crate_impl(module_ctx):
11801177
strip_internal_dependencies_from_cargo_lockfile = cfg.strip_internal_dependencies_from_cargo_lockfile,
11811178
)
11821179

1180+
# Watch cfg.lockfile AFTER generation. The generator may modify it during
1181+
# repin, and in Bazel 9 module_ctx.read verifies digests for files already
1182+
# read, which would crash if the lockfile changed between watch and read.
1183+
if cfg.lockfile:
1184+
module_ctx.watch(cfg.lockfile)
1185+
11831186
metadata_kwargs = {}
11841187
if bazel_features.external_deps.extension_metadata_has_reproducible:
11851188
metadata_kwargs["reproducible"] = reproducible

0 commit comments

Comments
 (0)