rules_rust icon indicating copy to clipboard operation
rules_rust copied to clipboard

Unable to generate initial Cargo.Bazel.lock

Open spemmons opened this issue 1 year ago • 1 comments

i have a working cargo workspace and am trying to add it to an existing bazel WORKSPACE file with the following standard definitions per the docs

load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains")

rules_rust_dependencies()

rust_register_toolchains(
    edition = "2021",
)

load("@rules_rust//crate_universe:repositories.bzl", "crate_universe_dependencies")

crate_universe_dependencies()

load("@rules_rust//crate_universe:defs.bzl", "crates_repository")

crates_repository(
    name = "crate_index",
    cargo_lockfile = "//:Cargo.lock",
    lockfile = "//:Cargo.Bazel.lock",
    manifests = ["//system/bash-test:Cargo.toml"],
)

load("@crate_index//:defs.bzl", "crate_repositories")

crate_repositories()

cargo build works fine and generates the root-level Cargo.lock file

the Cargo.toml looks like this

[workspace]
resolver = "2"
members = [
...
]

i have an empty Cargo.Bazel.lock file via touch and call CARGO_BAZEL_REPIN=true bazel build and get the following error

Loading: 
ERROR: An error occurred during the fetch of repository 'crate_index':
   Traceback (most recent call last):
        File "/home/ubuntu/.cache/bazel/_docker_bazel_ubuntu/cbf41e95e355e36f4faad74de7a872da/external/rules_rust/crate_universe/private/crates_repository.bzl", line 59, column 50, in _crates_repository_impl
                metadata_path = splice_workspace_manifest(
        File "/home/ubuntu/.cache/bazel/_docker_bazel_ubuntu/cbf41e95e355e36f4faad74de7a872da/external/rules_rust/crate_universe/private/splicing_utils.bzl", line 175, column 12, in splice_workspace_manifest
                execute(
        File "/home/ubuntu/.cache/bazel/_docker_bazel_ubuntu/cbf41e95e355e36f4faad74de7a872da/external/rules_rust/crate_universe/private/common_utils.bzl", line 54, column 13, in execute
                fail(_EXECUTE_ERROR_MESSAGE.format(
Error in fail: Command [/home/ubuntu/.cache/bazel/_docker_bazel_ubuntu/cbf41e95e355e36f4faad74de7a872da/external/crate_index/cargo-bazel, "splice", "--output-dir", /home/ubuntu/.cache/bazel/_docker_bazel_ubuntu/cbf41e95e355e36f4faad74de7a872da/external/crate_index/splicing-output, "--splicing-manifest", /home/ubuntu/.cache/bazel/_docker_bazel_ubuntu/cbf41e95e355e36f4faad74de7a872da/external/crate_index/splicing_manifest.json, "--config", /home/ubuntu/.cache/bazel/_docker_bazel_ubuntu/cbf41e95e355e36f4faad74de7a872da/external/crate_index/cargo-bazel.json, "--cargo", /home/ubuntu/.cache/bazel/_docker_bazel_ubuntu/cbf41e95e355e36f4faad74de7a872da/external/rust_linux_x86_64__x86_64-unknown-linux-gnu__stable_tools/bin/cargo, "--rustc", /home/ubuntu/.cache/bazel/_docker_bazel_ubuntu/cbf41e95e355e36f4faad74de7a872da/external/rust_linux_x86_64__x86_64-unknown-linux-gnu__stable_tools/bin/rustc, "--cargo-lockfile", /home/ubuntu/repositories/pennybot/Cargo.lock] failed with exit code 1.
STDOUT ------------------------------------------------------------------------

STDERR ------------------------------------------------------------------------
Error: Failed to query cargo version

Loading: 
ERROR: /home/ubuntu/repositories/pennybot/WORKSPACE:627:18: fetching crates_repository rule //external:crate_index: Traceback (most recent call last):
        File "/home/ubuntu/.cache/bazel/_docker_bazel_ubuntu/cbf41e95e355e36f4faad74de7a872da/external/rules_rust/crate_universe/private/crates_repository.bzl", line 59, column 50, in _crates_repository_impl
                metadata_path = splice_workspace_manifest(
        File "/home/ubuntu/.cache/bazel/_docker_bazel_ubuntu/cbf41e95e355e36f4faad74de7a872da/external/rules_rust/crate_universe/private/splicing_utils.bzl", line 175, column 12, in splice_workspace_manifest
                execute(
        File "/home/ubuntu/.cache/bazel/_docker_bazel_ubuntu/cbf41e95e355e36f4faad74de7a872da/external/rules_rust/crate_universe/private/common_utils.bzl", line 54, column 13, in execute
                fail(_EXECUTE_ERROR_MESSAGE.format(
Error in fail: Command [/home/ubuntu/.cache/bazel/_docker_bazel_ubuntu/cbf41e95e355e36f4faad74de7a872da/external/crate_index/cargo-bazel, "splice", "--output-dir", /home/ubuntu/.cache/bazel/_docker_bazel_ubuntu/cbf41e95e355e36f4faad74de7a872da/external/crate_index/splicing-output, "--splicing-manifest", /home/ubuntu/.cache/bazel/_docker_bazel_ubuntu/cbf41e95e355e36f4faad74de7a872da/external/crate_index/splicing_manifest.json, "--config", /home/ubuntu/.cache/bazel/_docker_bazel_ubuntu/cbf41e95e355e36f4faad74de7a872da/external/crate_index/cargo-bazel.json, "--cargo", /home/ubuntu/.cache/bazel/_docker_bazel_ubuntu/cbf41e95e355e36f4faad74de7a872da/external/rust_linux_x86_64__x86_64-unknown-linux-gnu__stable_tools/bin/cargo, "--rustc", /home/ubuntu/.cache/bazel/_docker_bazel_ubuntu/cbf41e95e355e36f4faad74de7a872da/external/rust_linux_x86_64__x86_64-unknown-linux-gnu__stable_tools/bin/rustc, "--cargo-lockfile", /home/ubuntu/repositories/pennybot/Cargo.lock] failed with exit code 1.
STDOUT ------------------------------------------------------------------------

STDERR ------------------------------------------------------------------------
Error: Failed to query cargo version

Loading: 
ERROR: Error computing the main repository mapping: no such package '@crate_index//': Command [/home/ubuntu/.cache/bazel/_docker_bazel_ubuntu/cbf41e95e355e36f4faad74de7a872da/external/crate_index/cargo-bazel, "splice", "--output-dir", /home/ubuntu/.cache/bazel/_docker_bazel_ubuntu/cbf41e95e355e36f4faad74de7a872da/external/crate_index/splicing-output, "--splicing-manifest", /home/ubuntu/.cache/bazel/_docker_bazel_ubuntu/cbf41e95e355e36f4faad74de7a872da/external/crate_index/splicing_manifest.json, "--config", /home/ubuntu/.cache/bazel/_docker_bazel_ubuntu/cbf41e95e355e36f4faad74de7a872da/external/crate_index/cargo-bazel.json, "--cargo", /home/ubuntu/.cache/bazel/_docker_bazel_ubuntu/cbf41e95e355e36f4faad74de7a872da/external/rust_linux_x86_64__x86_64-unknown-linux-gnu__stable_tools/bin/cargo, "--rustc", /home/ubuntu/.cache/bazel/_docker_bazel_ubuntu/cbf41e95e355e36f4faad74de7a872da/external/rust_linux_x86_64__x86_64-unknown-linux-gnu__stable_tools/bin/rustc, "--cargo-lockfile", /home/ubuntu/repositories/pennybot/Cargo.lock] failed with exit code 1.
STDOUT ------------------------------------------------------------------------

STDERR ------------------------------------------------------------------------
Error: Failed to query cargo version

Loading: 

i've searched the docs and google for hints about "cargo version" in this context and can't seem to find anything that helps

ideas? thanks

spemmons avatar Apr 28 '24 13:04 spemmons

Unfortunately there's not enough data here to answer your question, but I've added logging here in https://github.com/bazelbuild/rules_rust/pull/2629 which should help explain what's going on.

UebelAndre avatar Apr 28 '24 17:04 UebelAndre