bazelbuild / bazelbuild/rules_rust
crate_universe: cannot define two variants of the same library
- Dominant language
- Starlark
- Stars
- 843
- Forks
- 651
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 15
Description
I need to use different variants of a library in the same workspace, depending on the target platform.
However, when I add the same package with different aliases to the `packages` section of `crates_repository` rule, the package disappears from the workspace. Minimal example:
`WORKSPACE.bazel`
```bazel
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "rules_rust",
sha256 = "e074f1e203607c5fcd549929d956170346f8807d2bbaeb98b2ed213c37e0870f",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_rust/releases/download/0.3.1/rules_rust-v0.3.1.tar.gz",
"https://github.com/bazelbuild/rules_rust/releases/download/0.3.1/rules_rust-v0.3.1.tar.gz",
],
)
load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains")
rules_rust_dependencies()
rust_register_toolchains(version = "1.60.0")
load("@rules_rust//crate_universe:defs.bzl", "crate", "crates_repository", "splicing_config")
crates_repository(
name = "crate_index",
lockfile = "//:Cargo.Bazel.lock",
packages = {
"getrandom": crate.spec(
package = "getrandom",
version = "0.2.6",
),
"getrandom_custom": crate.spec(
features = ["custom"],
package = "getrandom",
version = "0.2.6",
),
},
splicing_config = splicing_config(
resolver_version = "2",
),
)
load("@crate_index//:defs.bzl", "crate_repositories")
crate_repositories()
```
```
bazel query @crate_index//...
@crate_index//:srcs
```
The `Cargo.Bazel.lock` file is empty as well:
```json
{
"checksum": "9058ba895bb4665566607200bccedaa5623580eb7c8440bc9ea8dc2414703d73",
"crates": {
"direct-cargo-bazel-deps 0.0.1": {
"name": "direct-cargo-bazel-deps",
"version": "0.0.1",
"repository": null,
"targets": [
{
"Library": {
"crate_name": "direct_cargo_bazel_deps",
"crate_root": ".direct_cargo_bazel_deps.rs",
"srcs": {
"include": [
"**/*.rs"
],
"exclude": []
}
}
}
],
"library_target_name": "direct_cargo_bazel_deps",
"common_attrs": {
"compile_data_glob": [
"**"
],
"edition": "2018",
"version": "0.0.1"
},
"license": null
}
},
"binary_crates": [],
"workspace_members": {
"direct-cargo-bazel-deps 0.0.1": ""
},
"conditions": {}
}
```
If I remove either of the library variants, the build works as expected.
Contributor guide
Assessment
This issue has not been assessed yet.