bazelbuild / bazelbuild/rules_rust
Bug: `crates_vendor` is generating a broken `defs.bzl`
- Dominant language
- Starlark
- Stars
- 843
- Forks
- 651
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 15
Description
While upgrading to 0.57.1 (or 0.57.0) we encountered a problem where `crates_vendor` is generating a `defs.bzl` where the labels are broken. For example instead of generating
```starlark
"anyhow": Label("@vendor__anyhow-1.0.44//:anyhow"),
```
we are getting instead
```starlark
"anyhow": Label("@vendor//:anyhow-1.0.44")
```
This then results in an error like
```
ERROR: no such package '@@[unknown repo 'vendor' requested from @@]//'
```
Initially I thought something was off with the default label template that can be provided via `render_config`, but I quickly found out that changing the `crate_label_template` there has no effect.
A reproducer can be found [here](https://github.com/github/codeql/blob/5f171b67ec7ff2704b8b4f9e4089e9e4801d417b/misc/bazel/3rdparty/BUILD.bazel) (malformed content [here](https://github.com/github/codeql/blob/5f171b67ec7ff2704b8b4f9e4089e9e4801d417b/misc/bazel/3rdparty/py_deps/defs.bzl#L297) and [here](https://github.com/github/codeql/blob/5f171b67ec7ff2704b8b4f9e4089e9e4801d417b/misc/bazel/3rdparty/tree_sitter_extractors_deps/defs.bzl#L298)). We're running bazel 8.0.0.
For the time being I'm about to work around this via this python script
```python
import sys
import re
import pathlib
label_re = re.compile(r'"@vendor//:(.+)-([\d.]+)"')
file = pathlib.Path(sys.argv[1])
temp = file.with_suffix(f'{file.suffix}.tmp')
with open(file) as input, open(temp, "w") as output:
for line in input:
line = label_re.sub(lambda m: f'"@vendor__{m[1]}-{m[2]}//:{m[1].replace("-", "_")}"', line)
output.write(line)
temp.rename(file)
```
Contributor guide
Assessment
This issue has not been assessed yet.