@@ -801,7 +801,11 @@ def _get_generator(module_ctx):
801
801
generator_sha256 = module_ctx .os .environ .get (CARGO_BAZEL_GENERATOR_SHA256 )
802
802
generator_url = module_ctx .os .environ .get (CARGO_BAZEL_GENERATOR_URL )
803
803
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
+
805
809
else :
806
810
generator_sha256 = CARGO_BAZEL_SHA256S .get (host_triple .str )
807
811
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):
839
843
"""
840
844
binary_ext = system_to_binary_ext (host_triple .system )
841
845
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
+
844
857
return cargo_path , rustc_path
845
858
846
859
def _crate_impl (module_ctx ):
0 commit comments