rules_rust icon indicating copy to clipboard operation
rules_rust copied to clipboard

crate_universe examples warn about canonical reproducible form

Open dtolnay opened this issue 2 years ago • 1 comments

When running bazel sync under examples/crate_universe, it produces the following output:

DEBUG: Rule 'crate_index_cargo_bindeps' indicated that a canonical reproducible form can be obtained by modifying arguments lockfile = Label("//cargo_bindeps:cargo-bazel-lock.json")
DEBUG: Repository crate_index_cargo_bindeps instantiated at:
  /git/rules_rust/examples/crate_universe/WORKSPACE.bazel:53:18: in <toplevel>
Repository rule crates_repository defined at:
  /home/david/.cache/bazel/_bazel_david/358f37b40955d4e8442564cc1d3c42fc/external/rules_rust/crate_universe/private/crates_repository.bzl:107:36: in <toplevel>
DEBUG: Rule 'crate_index_cargo_local' indicated that a canonical reproducible form can be obtained by modifying arguments lockfile = Label("//cargo_local:cargo-bazel-lock.json")
DEBUG: Repository crate_index_cargo_local instantiated at:
  /git/rules_rust/examples/crate_universe/WORKSPACE.bazel:75:18: in <toplevel>
Repository rule crates_repository defined at:
  /home/david/.cache/bazel/_bazel_david/358f37b40955d4e8442564cc1d3c42fc/external/rules_rust/crate_universe/private/crates_repository.bzl:107:36: in <toplevel>
DEBUG: Rule 'crate_index_cargo_remote' indicated that a canonical reproducible form can be obtained by modifying arguments lockfile = Label("@names//:cargo-bazel-lock.json")
DEBUG: Repository crate_index_cargo_remote instantiated at:
  /git/rules_rust/examples/crate_universe/WORKSPACE.bazel:105:18: in <toplevel>
Repository rule crates_repository defined at:
  /home/david/.cache/bazel/_bazel_david/358f37b40955d4e8442564cc1d3c42fc/external/rules_rust/crate_universe/private/crates_repository.bzl:107:36: in <toplevel>

I tried following what it said (https://github.com/bazelbuild/rules_rust/commit/3b9acf34d99834fe24e0d2054235180964879aab) but then sync fails.

@@ -57,6 +57,7 @@ crates_repository(
     # `generator` is not necessary in official releases.
     # See load satement for `cargo_bazel_bootstrap`.
     generator = "@cargo_bazel_bootstrap//:cargo-bazel",
+    lockfile = "//cargo_bindeps:cargo-bazel-lock.json",
     manifests = ["//cargo_bindeps:Cargo.toml"],
     rust_version = "nightly",
 )

@@ -78,6 +79,7 @@ crates_repository(
     # `generator` is not necessary in official releases.
     # See load satement for `cargo_bazel_bootstrap`.
     generator = "@cargo_bazel_bootstrap//:cargo-bazel",
+    lockfile = "//cargo_local:cargo-bazel-lock.json",
     manifests = ["//cargo_local:Cargo.toml"],
 )

@@ -108,6 +110,7 @@ crates_repository(
     # `generator` is not necessary in official releases.
     # See load satement for `cargo_bazel_bootstrap`.
     generator = "@cargo_bazel_bootstrap//:cargo-bazel",
+    lockfile = "@names//:cargo-bazel-lock.json",
     manifests = ["@names//:Cargo.toml"],
 )
INFO: Repository crate_index_cargo_bindeps instantiated at:
  /git/rules_rust/examples/crate_universe/WORKSPACE.bazel:53:18: in <toplevel>
Repository rule crates_repository defined at:
  /home/david/.cache/bazel/_bazel_david/358f37b40955d4e8442564cc1d3c42fc/external/rules_rust/crate_universe/private/crates_repository.bzl:107:36: in <toplevel>
ERROR: An error occurred during the fetch of repository 'crate_index_cargo_bindeps':
   Traceback (most recent call last):
        File "/home/david/.cache/bazel/_bazel_david/358f37b40955d4e8442564cc1d3c42fc/external/rules_rust/crate_universe/private/crates_repository.bzl", line 34, column 30, in _crates_repository_impl
                lockfiles = get_lockfiles(repository_ctx)
        File "/home/david/.cache/bazel/_bazel_david/358f37b40955d4e8442564cc1d3c42fc/external/rules_rust/crate_universe/private/generate_utils.bzl", line 317, column 36, in get_lockfiles
                bazel = repository_ctx.path(repository_ctx.attr.lockfile) if repository_ctx.attr.lockfile else None,
Error in path: Not a regular file: /git/rules_rust/examples/crate_universe/cargo_bindeps/cargo-bazel-lock.json
ERROR: /git/rules_rust/examples/crate_universe/WORKSPACE.bazel:53:18: fetching crates_repository rule //external:crate_index_cargo_bindeps: Traceback (most recent call last):
        File "/home/david/.cache/bazel/_bazel_david/358f37b40955d4e8442564cc1d3c42fc/external/rules_rust/crate_universe/private/crates_repository.bzl", line 34, column 30, in _crates_repository_impl
                lockfiles = get_lockfiles(repository_ctx)
        File "/home/david/.cache/bazel/_bazel_david/358f37b40955d4e8442564cc1d3c42fc/external/rules_rust/crate_universe/private/generate_utils.bzl", line 317, column 36, in get_lockfiles
                bazel = repository_ctx.path(repository_ctx.attr.lockfile) if repository_ctx.attr.lockfile else None,
Error in path: Not a regular file: /git/rules_rust/examples/crate_universe/cargo_bindeps/cargo-bazel-lock.json
ERROR: no such package '@crate_index_cargo_bindeps//': Not a regular file: /git/rules_rust/examples/crate_universe/cargo_bindeps/cargo-bazel-lock.json

I also attempted lockfile = Label("...") as appears in the warning, but that did not seem promising.

ERROR: /git/rules_rust/examples/crate_universe/WORKSPACE.bazel:60:16: name 'Label' is not defined
ERROR: error loading package '': Encountered error while reading extension file 'defs.bzl': no such package '@crate_index_cargo_bindeps//': error loading package 'external': Could not load //external package

Is there any other way that the "a canonical reproducible form can be obtained by modifying arguments" in examples/crate_universe is actionable? If not, is there any way to suppress this output?

dtolnay avatar Oct 31 '23 16:10 dtolnay

Did you create an empty file at these locations first? Repository rules can't create referenced files, only update existing ones.

cameron-martin avatar Jan 31 '24 22:01 cameron-martin