Skip to content

Commit 40648cd

Browse files
authored
Avoid direct references to volatile files (#3361)
closes #3297
1 parent da98390 commit 40648cd

File tree

3 files changed

+15673
-819
lines changed

3 files changed

+15673
-819
lines changed

crate_universe/extensions.bzl

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,11 @@ def _get_generator(module_ctx):
801801
generator_sha256 = module_ctx.os.environ.get(CARGO_BAZEL_GENERATOR_SHA256)
802802
generator_url = module_ctx.os.environ.get(CARGO_BAZEL_GENERATOR_URL)
803803
elif len(CARGO_BAZEL_URLS) == 0:
804-
return module_ctx.path(Label("@cargo_bazel_bootstrap//:cargo-bazel"))
804+
# For Bazel 7 and below, `module_ctx.path` will also watch files so to avoid
805+
# volatility in lock files caused by referencing host specific files, direct
806+
# references are avoided.
807+
return module_ctx.path(Label("@cargo_bazel_bootstrap//:BUILD.bazel")).dirname.get_child("cargo-bazel")
808+
805809
else:
806810
generator_sha256 = CARGO_BAZEL_SHA256S.get(host_triple.str)
807811
generator_url = CARGO_BAZEL_URLS.get(host_triple.str)
@@ -839,8 +843,17 @@ def _get_host_cargo_rustc(module_ctx, host_triple, host_tools_repo):
839843
"""
840844
binary_ext = system_to_binary_ext(host_triple.system)
841845

842-
cargo_path = str(module_ctx.path(Label("@{}//:bin/cargo{}".format(host_tools_repo, binary_ext))))
843-
rustc_path = str(module_ctx.path(Label("@{}//:bin/rustc{}".format(host_tools_repo, binary_ext))))
846+
# For Bazel 7 and below, `module_ctx.path` will also watch files so to avoid
847+
# volatility in lock files caused by referencing host specific files, direct
848+
# references are avoided. Note that `BUILD.bazel` is not used as it also
849+
# contains host specific data.
850+
root = module_ctx.path(Label("@{rust_host_tools}//:WORKSPACE.bazel".format(
851+
rust_host_tools = host_tools_repo,
852+
)))
853+
854+
cargo_path = root.dirname.get_child("bin/cargo{}".format(binary_ext))
855+
rustc_path = root.dirname.get_child("bin/rustc{}".format(binary_ext))
856+
844857
return cargo_path, rustc_path
845858

846859
def _crate_impl(module_ctx):

0 commit comments

Comments
 (0)