crate_universe: local_crate_mirror does not accept relative paths despite docs implying it might
维护者通常 3 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 68/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 冷清
- 技术栈
- rust
- 领域
- build-system
调研方向
从 crate_universe/private/local_crate_mirror.bzl 开始,将其路径处理方式与 crate_universe/src/metadata/metadata_annotation.rs:284–310 发出的工作区相对路径进行比较。使用 Cargo patch 和 bazel run //third_party/rust:update-repos 重现该失败;当生成的 local_crate_mirror 能够使用相对路径且不再出现外部仓库的 readdir 错误时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
Summary
crate_universe's update-repos (cargo-bazel renderer) emits local_crate_mirror(path = "<workspace-relative path>") calls when consumers use a standard Cargo [patch.crates-io] entry with a relative path. But the local_crate_mirror repository rule cannot consume the path it was given: repository_ctx.path(string) resolves relative paths against the external repo's own directory, not the workspace root, so the readdir() call inside the rule fails immediately.
So the bug is entirely internal to rules_rust — the generator produces a value the consumer can't use.
Reproducer
In a Bazel workspace, vendor a crate hand-tweak it, then patch it into Cargo:
# Cargo.toml
[patch.crates-io]
mycrate = { path = "third_party/rust/vendor/mycrate-1.0.0" }
bazel run //third_party/rust:update-repos
cargo-bazel renders this into third_party/rust/crates/defs.bzl:
local_crate_mirror(
name = "crate_index__mycrate-1.0.0",
options_json = "{...,\"local_path\":\"third_party/rust/vendor/mycrate-1.0.0\",...}",
path = "third_party/rust/vendor/mycrate-1.0.0",
)
crate_universe/src/metadata/metadata_annotation.rs:284–310 explicitly produces this workspace-relative form, and the in-code comment says:
// This replacement allows in-repo patches sections to work as intended using local_crate_mirror.
So upstream's intent is clearly to support relative [patch.crates-io] paths. But crate_universe/private/local_crate_mirror.bzl:9:
def _local_crate_mirror_impl(repository_ctx):
path = repository_ctx.path(repository_ctx.attr.path)
...
for child in repository_ctx.path(path).readdir():
...
repository_ctx.path(relative_str) resolves under the external repo's own directory. The external repo @@_main~rust_crates_extension~crate_index__mycrate-1.0.0 doesn't contain third_party/rust/vendor/mycrate-1.0.0, so:
Error in readdir: can't readdir(), not a directory:
.../external/_main~rust_crates_extension~crate_index__mycrate-1.0.0/third_party/rust/vendor/mycrate-1.0.0
The path attribute docstring even has a TODO flagging this:
"path": attr.string(
# TODO: Verify what happens if this is not an absolute path.
doc = "Absolute path to the BUILD.bazel file to generate.",
),
The docstring says "absolute" but the generator emits relative — that contradiction is the bug.
Proposed fix
Make local_crate_mirror resolve path relative to the workspace root when relative:
def _local_crate_mirror_impl(repository_ctx):
path = repository_ctx.workspace_root.get_child(repository_ctx.attr.path)
...
repository_ctx.workspace_root is well-defined and always points at the main workspace root from inside an external repo's fetch.
Either that, or update the renderer in metadata/metadata_annotation.rs to emit an absolute path (and update the path attr docs/checks accordingly). The first option seems cleaner because Cargo [patch.crates-io] paths are always relative-to-the-manifest by Cargo's design.
We carry the first option as a local patch against 0.70.0. Happy to send a PR if maintainers prefer.
Versions
- rules_rust: 0.70.0
- bazel: 7.7.1
- 主要语言
- Starlark
- 星标
- 857
- 派生
- 701
- 平均合并
- 4 天 7 小时
- 30 天内合并 PR
- 46
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
bazelbuild/rules_rust 的其他 Issue
-
`rust_test(crate = ...)` does not stage the crate's transitive dynamic libraries into runfiles可能已有人在做 @Wito-1 于 65 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 88/100
bazelbuild/rules_rust#4309 ·
维护者通常 3 天内回复
-
Windows (no-symlink path): drain_runfiles_dir_windows deletes retained runfiles — inverted filename_suffixes_to_retain condition可能已有人在做 @Mattbusel 于 17 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
bazelbuild/rules_rust#4266 ·
维护者通常 3 天内回复
-
rust.toolchain(strip_level = ...) is silently ignored可能已有人在做 @Mattbusel 于 17 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
bazelbuild/rules_rust#4223 ·
维护者通常 3 天内回复
-
难度 1/5 1-3 小时 新手友好度 90/100
bazelbuild/rules_rust#4152 · 1 个 reaction ·
维护者通常 3 天内回复
-
awaiting-response
难度 2/5 1-3 小时 新手友好度 76/100
bazelbuild/rules_rust#3599 · 1 条评论 ·
维护者通常 3 天内回复
查看 bazelbuild/rules_rust 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 65/100
bazelbuild/apple_support#707 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 92/100
-
out-of-date
难度 2/5 1-3 小时 新手友好度 68/100
CachyOS/CachyOS-PKGBUILDS#2232 ·
维护者通常 1 天内回复
-
blast/large refactor risk/low spend-dem
难度 2/5 1-3 小时 新手友好度 68/100
chriskelly/MusicWall#87 · 2 条评论 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
neilotoole/sq#1503 ·
维护者通常 1 天内回复