From eebf21e788eb71d96038a99535c2e167131c1425 Mon Sep 17 00:00:00 2001 From: Patrick Scott Date: Thu, 26 Mar 2026 09:05:41 -0400 Subject: [PATCH] Move module_ctx.watch to after lockfile repin 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. --- crate_universe/extensions.bzl | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/crate_universe/extensions.bzl b/crate_universe/extensions.bzl index 4e078c01e2..e240e41973 100644 --- a/crate_universe/extensions.bzl +++ b/crate_universe/extensions.bzl @@ -1112,18 +1112,6 @@ def _crate_impl(module_ctx): fail("Spec specified for repo {}, but the module defined repositories {}".format(repo, local_repos)) for cfg in mod.tags.from_cargo + mod.tags.from_specs: - # Preload all external repositories. Calling `module_ctx.watch` will cause restarts of the implementation - # function of the module extension when the file has changed. - if cfg.cargo_lockfile: - module_ctx.watch(cfg.cargo_lockfile) - if cfg.lockfile: - module_ctx.watch(cfg.lockfile) - if cfg.cargo_config: - module_ctx.watch(cfg.cargo_config) - if hasattr(cfg, "manifests"): - for m in cfg.manifests: - module_ctx.watch(m) - cargo_path, rustc_path = _get_host_cargo_rustc(module_ctx, host_triple, cfg.host_tools) cargo_bazel_fn = new_cargo_bazel_fn( repository_ctx = module_ctx, @@ -1180,6 +1168,19 @@ def _crate_impl(module_ctx): strip_internal_dependencies_from_cargo_lockfile = cfg.strip_internal_dependencies_from_cargo_lockfile, ) + # Preload all external repositories. Calling `module_ctx.watch` will cause restarts of the implementation + # function of the module extension when the file has changed. Watch inputs after generation so bazel 9 does + # not crash. If the lockfile is repinned, module_ctx.read will crash with a digest mismatch. + if cfg.cargo_lockfile: + module_ctx.watch(cfg.cargo_lockfile) + if cfg.lockfile: + module_ctx.watch(cfg.lockfile) + if cfg.cargo_config: + module_ctx.watch(cfg.cargo_config) + if hasattr(cfg, "manifests"): + for m in cfg.manifests: + module_ctx.watch(m) + metadata_kwargs = {} if bazel_features.external_deps.extension_metadata_has_reproducible: metadata_kwargs["reproducible"] = reproducible