Skip to content

Commit a21f494

Browse files
authored
Fix monitoring input manifest/lockfile/srcs changes (#3313)
From a comment of @UebelAndre replacing the previous trick of calling `repository_ctx.path()` by the newly introduced `repository_ctx.watch` solves two issues: - `rules_rust` correctly re-splices crates when the workspace `Cargo.toml` manifest changes, but also when any of the projects' `Cargo.toml` change - `rules_rust` correctly re-bootstraps `cargo-bazel` when the source changes (if you're developing for `rules_rust` and using `local_path_override`) Closes #3216 Signed-off-by: Gabriel Féron <g@leirbag.net>
1 parent 13c596e commit a21f494

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

cargo/private/cargo_bootstrap.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,13 @@ def _detect_changes(repository_ctx):
173173
# 'consumed' which means changes to it will trigger rebuilds
174174

175175
for src in repository_ctx.attr.srcs:
176-
repository_ctx.path(src)
176+
repository_ctx.watch(src)
177177

178-
repository_ctx.path(repository_ctx.attr.cargo_lockfile)
179-
repository_ctx.path(repository_ctx.attr.cargo_toml)
178+
repository_ctx.watch(repository_ctx.attr.cargo_lockfile)
179+
repository_ctx.watch(repository_ctx.attr.cargo_toml)
180180

181181
if repository_ctx.attr.cargo_config:
182-
repository_ctx.path(repository_ctx.attr.cargo_config)
182+
repository_ctx.watch(repository_ctx.attr.cargo_config)
183183

184184
def _cargo_bootstrap_repository_impl(repository_ctx):
185185
# Pretend to Bazel that this rule's input files have been used, so that it will re-run the rule if they change.

crate_universe/extensions.bzl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -943,16 +943,17 @@ def _crate_impl(module_ctx):
943943
fail("Spec specified for repo {}, but the module defined repositories {}".format(repo, local_repos))
944944

945945
for cfg in mod.tags.from_cargo + mod.tags.from_specs:
946-
# Preload all external repositories. Calling `module_ctx.path` will cause restarts of the implementation
947-
# function of the module extension, so we want to trigger all restarts before we start the actual work.
948-
# Once https://github.com/bazelbuild/bazel/issues/22729 has been fixed, this code can be removed.
946+
# Preload all external repositories. Calling `module_ctx.watch` will cause restarts of the implementation
947+
# function of the module extension when the file has changed.
949948
if cfg.cargo_lockfile:
950-
module_ctx.path(cfg.cargo_lockfile)
949+
module_ctx.watch(cfg.cargo_lockfile)
951950
if cfg.lockfile:
952-
module_ctx.path(cfg.lockfile)
951+
module_ctx.watch(cfg.lockfile)
952+
if cfg.cargo_config:
953+
module_ctx.watch(cfg.cargo_config)
953954
if hasattr(cfg, "manifests"):
954955
for m in cfg.manifests:
955-
module_ctx.path(m)
956+
module_ctx.watch(m)
956957

957958
cargo_path, rustc_path = _get_host_cargo_rustc(module_ctx, host_triple, cfg.host_tools_repo)
958959
cargo_bazel_fn = new_cargo_bazel_fn(

0 commit comments

Comments
 (0)