bazelbuild / bazelbuild/rules_rust

crate_universe: `crate.spec` does not support git tags

Open
#1,262 3 comments 0 reactions 0 assignees View on GitHub
crate-universe enhancement needs-triage
Dominant language
Starlark
Stars
843
Forks
651
Avg merge
2d 18h
Merged PRs (30d)
15

Description

rules_rust: 0.2.1

Given

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

rules_rust_dependencies()

rust_register_toolchains()

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

crate_universe_dependencies()

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

crates_repository(
name = "crate_index",
lockfile = "//:Cargo.Bazel.lock",
packages = {
"regex": crate.spec(
git = "https://github.com/rust-lang/regex",
rev = "1.5.5",
)
},
)

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

crate_repositories()
```

The crate will fail to build.

```sh
❯ bazel build @crate_index//:regex
(18:01:03) INFO: Current date is 2022-04-14
(18:01:05) INFO: Repository crate_index__regex-1.5.5 instantiated at:
/Users/thomas/code//WORKSPACE:166:19: in
/private/var/tmp/_bazel_thomas/796dd52d4d981101108548a9446ddca6/external/crate_index/defs.bzl:392:10: in crate_repositories
/private/var/tmp/_bazel_thomas/796dd52d4d981101108548a9446ddca6/external/bazel_tools/tools/build_defs/repo/utils.bzl:233:18: in maybe
Repository rule new_git_repository defined at:
/private/var/tmp/_bazel_thomas/796dd52d4d981101108548a9446ddca6/external/bazel_tools/tools/build_defs/repo/git.bzl:186:37: in
(18:01:05) ERROR: An error occurred during the fetch of repository 'crate_index__regex-1.5.5':
Traceback (most recent call last):
File "/private/var/tmp/_bazel_thomas/796dd52d4d981101108548a9446ddca6/external/bazel_tools/tools/build_defs/repo/git.bzl", line 174, column 30, in _new_git_repository_implementation
update = _clone_or_update(ctx)
File "/private/var/tmp/_bazel_thomas/796dd52d4d981101108548a9446ddca6/external/bazel_tools/tools/build_defs/repo/git.bzl", line 36, column 20, in _clone_or_update
git_ = git_repo(ctx, directory)
File "/private/var/tmp/_bazel_thomas/796dd52d4d981101108548a9446ddca6/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 91, column 12, in git_repo
_update(ctx, git_repo)
File "/private/var/tmp/_bazel_thomas/796dd52d4d981101108548a9446ddca6/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 104, column 10, in _update
reset(ctx, git_repo)
File "/private/var/tmp/_bazel_thomas/796dd52d4d981101108548a9446ddca6/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 148, column 9, in reset
_git(ctx, git_repo, "reset", "--hard", git_repo.reset_ref)
File "/private/var/tmp/_bazel_thomas/796dd52d4d981101108548a9446ddca6/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 169, column 15, in _git
_error(ctx.name, start + list(args), st.stderr)
File "/private/var/tmp/_bazel_thomas/796dd52d4d981101108548a9446ddca6/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 190, column 9, in _error
fail("error running '%s' while working with @%s:\n%s" % (command_text, name, stderr))
Error in fail: error running 'git reset --hard 1.5.5' while working with @crate_index__regex-1.5.5:
fatal: ambiguous argument '1.5.5': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git [...] -- [...]'
(18:01:05) ERROR: /Users/thomas/code//WORKSPACE:166:19: fetching new_git_repository rule //external:crate_index__regex-1.5.5: Traceback (most recent call last):
File "/private/var/tmp/_bazel_thomas/796dd52d4d981101108548a9446ddca6/external/bazel_tools/tools/build_defs/repo/git.bzl", line 174, column 30, in _new_git_repository_implementation
update = _clone_or_update(ctx)
File "/private/var/tmp/_bazel_thomas/796dd52d4d981101108548a9446ddca6/external/bazel_tools/tools/build_defs/repo/git.bzl", line 36, column 20, in _clone_or_update
git_ = git_repo(ctx, directory)
File "/private/var/tmp/_bazel_thomas/796dd52d4d981101108548a9446ddca6/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 91, column 12, in git_repo
_update(ctx, git_repo)
File "/private/var/tmp/_bazel_thomas/796dd52d4d981101108548a9446ddca6/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 104, column 10, in _update
reset(ctx, git_repo)
File "/private/var/tmp/_bazel_thomas/796dd52d4d981101108548a9446ddca6/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 148, column 9, in reset
_git(ctx, git_repo, "reset", "--hard", git_repo.reset_ref)
File "/private/var/tmp/_bazel_thomas/796dd52d4d981101108548a9446ddca6/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 169, column 15, in _git
_error(ctx.name, start + list(args), st.stderr)
File "/private/var/tmp/_bazel_thomas/796dd52d4d981101108548a9446ddca6/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 190, column 9, in _error
fail("error running '%s' while working with @%s:\n%s" % (command_text, name, stderr))
Error in fail: error running 'git reset --hard 1.5.5' while working with @crate_index__regex-1.5.5:
fatal: ambiguous argument '1.5.5': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git [...] -- [...]'
(18:01:05) ERROR: /private/var/tmp/_bazel_thomas/796dd52d4d981101108548a9446ddca6/external/crate_index/BUILD.bazel:28:6: @crate_index//:regex depends on @crate_index__regex-1.5.5//:regex in repository @crate_index__regex-1.5.5 which failed to fetch. no such package '@crate_index__regex-1.5.5//': error running 'git reset --hard 1.5.5' while working with @crate_index__regex-1.5.5:
fatal: ambiguous argument '1.5.5': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git [...] -- [...]'
(18:01:05) ERROR: Analysis of target '@crate_index//:regex' failed; build aborted: Analysis failed
(18:01:05) INFO: Elapsed time: 2.836s
(18:01:05) INFO: 0 processes.
(18:01:05) FAILED: Build did NOT complete successfully (1 packages loaded, 0 targets configured\
)
```

This is available on crates.io, and works. I'm building from source as we need to use [`regex-capi`](https://github.com/rust-lang/regex/tree/1.5.5/regex-capi).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.