Skip to content

Cannot bootstrap cargo-bazel #1204

@roman-kashitsyn

Description

@roman-kashitsyn

I'm trying to build a minimal project with a cargo-free setup as described in https://bazelbuild.github.io/rules_rust/crate_universe.html

Here is my WORKSPACE.bazel file:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")    
    
http_archive(                                                           
    name = "rules_rust",    
    sha256 = "7453856d239a004c9e29cde2e45903a068446e4a69501ee7393faf08e1a30403",    
    urls = [                                                                        
        "https://mirror.bazel.build/github.com/bazelbuild/rules_rust/releases/download/0.1.0/rules_rust-v0.1.0.tar.gz",    
        "https://github.com/bazelbuild/rules_rust/releases/download/0.1.0/rules_rust-v0.1.0.tar.gz",                       
    ],                                                                                                         
)

load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains")              
                                                                                                     
rules_rust_dependencies()                                                                            
rust_register_toolchains(version = "1.58.1")    
                                                
load("@rules_rust//crate_universe:defs.bzl", "crate", "crates_repository", "splicing_config")    
load("@rules_rust//crate_universe:deps_bootstrap.bzl", "cargo_bazel_bootstrap")                         
                                                                                                        
cargo_bazel_bootstrap(rust_version = "1.58.1")                                     
                                                                                                     
crates_repository(                                                                                   
    name = "crate_index",    
    generator = "@cargo_bazel_bootstrap//:cargo-bazel",    
    lockfile = "//:Cargo.Bazel.lock",                       
    packages = {
        "ic-cdk-macros": crate.spec(version = "0.3.0"),
        "ic-cdk": crate.spec(version = "0.3.0"),
    },
    splicing_config = splicing_config(
        resolver_version = "2",
    ),
)

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

However, when I try to use packages from the @crate_index in my targets, the cargo-bazel tool fails to bootstrap:

   Compiling crates-index v0.18.7
   Compiling cargo-bazel v0.1.0 (/home/roman/.cache/bazel/_bazel_roman/08ce8840fa16138f7ad6f5d2ab8b55af/external/rules_rust/crate_universe)
    Finished release [optimized] target(s) in 1m 37s
INFO: Repository cargo_bazel_bootstrap instantiated at:
  /home/roman/bazel-sample/WORKSPACE.bazel:26:22: in <toplevel>
  /home/roman/.cache/bazel/_bazel_roman/08ce8840fa16138f7ad6f5d2ab8b55af/external/rules_rust/crate_universe/deps_bootstrap.bzl:16:31: in cargo_bazel_bootstrap
Repository rule cargo_bootstrap_repository defined at:
  /home/roman/.cache/bazel/_bazel_roman/08ce8840fa16138f7ad6f5d2ab8b55af/external/rules_rust/cargo/cargo_bootstrap.bzl:227:45: in <toplevel>
ERROR: An error occurred during the fetch of repository 'cargo_bazel_bootstrap':
   Traceback (most recent call last):
        File "/home/roman/.cache/bazel/_bazel_roman/08ce8840fa16138f7ad6f5d2ab8b55af/external/rules_rust/cargo/cargo_bootstrap.bzl", line 208, column 35, in _cargo_bootstrap_repository_impl
                built_binary = cargo_bootstrap(
        File "/home/roman/.cache/bazel/_bazel_roman/08ce8840fa16138f7ad6f5d2ab8b55af/external/rules_rust/cargo/cargo_bootstrap.bzl", line 105, column 13, in cargo_bootstrap
                fail("Failed to produce binary at {}".format(binary_path))
Error in fail: Failed to produce binary at release/cargo-bazel
ERROR: /home/roman/bazel-sample/WORKSPACE.bazel:26:22: fetching cargo_bootstrap_repository rule //external:cargo_bazel_bootstrap: Traceback (most recent call last):
        File "/home/roman/.cache/bazel/_bazel_roman/08ce8840fa16138f7ad6f5d2ab8b55af/external/rules_rust/cargo/cargo_bootstrap.bzl", line 208, column 35, in _cargo_bootstrap_repository_impl
                built_binary = cargo_bootstrap(
        File "/home/roman/.cache/bazel/_bazel_roman/08ce8840fa16138f7ad6f5d2ab8b55af/external/rules_rust/cargo/cargo_bootstrap.bzl", line 105, column 13, in cargo_bootstrap
                fail("Failed to produce binary at {}".format(binary_path))
Error in fail: Failed to produce binary at release/cargo-bazel
ERROR: error loading package '': Encountered error while reading extension file 'defs.bzl': no such package '@crate_index//': no such package '@cargo_bazel_bootstrap//': Failed to produce binary at release/cargo-bazel
INFO: Elapsed time: 99.408s

It seems that the tool compiled successfully, but the cargo_bootstrap rule could not find the binary at the expected place. I believe cargo_bootstrap expects /target/release/cargo-bazel but the path that cargo uses is target/x86_64-unknown-linux-gnu/release/cargo-bazel.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions