fix: Duplicate aliases generated in rendering when two crates of the same version (#3386)
Original cause:
https://github.com/bazelbuild/rules_rust/commit/5e904830eee39b37775855c6ff7e7e1079eb59e0#diff-52bdc04b030a02035a19a3c805288b7720191185a18f6b8f16f61a59baa42d3fR224
Related to: https://github.com/bazelbuild/rules_rust/pull/3215
This PR updates rendering in `cargo-bazel` to handle the case when there
are multiple dependencies on a crate at the same version, but they're
aliased. For example, when a `Cargo.toml` has the following:
```
itertools = "0.11.24"
itertools_other = { version = "0.11.24", package = "itertools" }
```
Previously this would generate two aliases both with the name
`itertools-0.11.24` but now we only create a single alias of that name.
Encountering this case is odd but not uncommon, especially if you also
use a tool like
[`cargo-hakari`](https://github.com/guppy-rs/guppy/tree/main/tools/cargo-hakari)
in your workspace.diff --git a/examples/crate_universe/vendor_external/crates/BUILD.indexmap-1.8.0.bazel b/examples/crate_universe/vendor_external/crates/BUILD.indexmap-1.8.0.bazel
index 92533b0..26dff13 100644
--- a/examples/crate_universe/vendor_external/crates/BUILD.indexmap-1.8.0.bazel
+++ b/examples/crate_universe/vendor_external/crates/BUILD.indexmap-1.8.0.bazel
@@ -140,6 +140,9 @@
),
edition = "2018",
pkg_name = "indexmap",
+ rustc_env_files = [
+ ":cargo_toml_env_vars",
+ ],
rustc_flags = [
"--cap-lints=allow",
],
diff --git a/examples/crate_universe/vendor_external/crates/BUILD.libc-0.2.119.bazel b/examples/crate_universe/vendor_external/crates/BUILD.libc-0.2.119.bazel
index d46f204..a74894f 100644
--- a/examples/crate_universe/vendor_external/crates/BUILD.libc-0.2.119.bazel
+++ b/examples/crate_universe/vendor_external/crates/BUILD.libc-0.2.119.bazel
@@ -133,6 +133,9 @@
),
edition = "2015",
pkg_name = "libc",
+ rustc_env_files = [
+ ":cargo_toml_env_vars",
+ ],
rustc_flags = [
"--cap-lints=allow",
],
diff --git a/examples/crate_universe/vendor_external/crates/BUILD.memchr-2.4.1.bazel b/examples/crate_universe/vendor_external/crates/BUILD.memchr-2.4.1.bazel
index df5c7fe..93aec00 100644
--- a/examples/crate_universe/vendor_external/crates/BUILD.memchr-2.4.1.bazel
+++ b/examples/crate_universe/vendor_external/crates/BUILD.memchr-2.4.1.bazel
@@ -141,6 +141,9 @@
),
edition = "2018",
pkg_name = "memchr",
+ rustc_env_files = [
+ ":cargo_toml_env_vars",
+ ],
rustc_flags = [
"--cap-lints=allow",
],
diff --git a/examples/crate_universe/vendor_external/crates/BUILD.proc-macro-error-1.0.4.bazel b/examples/crate_universe/vendor_external/crates/BUILD.proc-macro-error-1.0.4.bazel
index c5e01d6..0d835fa 100644
--- a/examples/crate_universe/vendor_external/crates/BUILD.proc-macro-error-1.0.4.bazel
+++ b/examples/crate_universe/vendor_external/crates/BUILD.proc-macro-error-1.0.4.bazel
@@ -149,6 +149,9 @@
),
edition = "2018",
pkg_name = "proc-macro-error",
+ rustc_env_files = [
+ ":cargo_toml_env_vars",
+ ],
rustc_flags = [
"--cap-lints=allow",
],
diff --git a/examples/crate_universe/vendor_external/crates/BUILD.proc-macro-error-attr-1.0.4.bazel b/examples/crate_universe/vendor_external/crates/BUILD.proc-macro-error-attr-1.0.4.bazel
index 3519e5b..8814a05 100644
--- a/examples/crate_universe/vendor_external/crates/BUILD.proc-macro-error-attr-1.0.4.bazel
+++ b/examples/crate_universe/vendor_external/crates/BUILD.proc-macro-error-attr-1.0.4.bazel
@@ -135,6 +135,9 @@
),
edition = "2018",
pkg_name = "proc-macro-error-attr",
+ rustc_env_files = [
+ ":cargo_toml_env_vars",
+ ],
rustc_flags = [
"--cap-lints=allow",
],
diff --git a/examples/crate_universe/vendor_external/crates/BUILD.proc-macro2-1.0.36.bazel b/examples/crate_universe/vendor_external/crates/BUILD.proc-macro2-1.0.36.bazel
index a07f6f3..5aa502f 100644
--- a/examples/crate_universe/vendor_external/crates/BUILD.proc-macro2-1.0.36.bazel
+++ b/examples/crate_universe/vendor_external/crates/BUILD.proc-macro2-1.0.36.bazel
@@ -256,6 +256,9 @@
),
edition = "2018",
pkg_name = "proc-macro2",
+ rustc_env_files = [
+ ":cargo_toml_env_vars",
+ ],
rustc_flags = [
"--cap-lints=allow",
],
diff --git a/examples/crate_universe/vendor_external/crates/BUILD.pulldown-cmark-0.8.0.bazel b/examples/crate_universe/vendor_external/crates/BUILD.pulldown-cmark-0.8.0.bazel
index 3530f9a..daed3ad 100644
--- a/examples/crate_universe/vendor_external/crates/BUILD.pulldown-cmark-0.8.0.bazel
+++ b/examples/crate_universe/vendor_external/crates/BUILD.pulldown-cmark-0.8.0.bazel
@@ -136,6 +136,9 @@
),
edition = "2018",
pkg_name = "pulldown-cmark",
+ rustc_env_files = [
+ ":cargo_toml_env_vars",
+ ],
rustc_flags = [
"--cap-lints=allow",
],
diff --git a/examples/crate_universe/vendor_external/crates/BUILD.semver-1.0.6.bazel b/examples/crate_universe/vendor_external/crates/BUILD.semver-1.0.6.bazel
index 5b5ca15..98fe73f 100644
--- a/examples/crate_universe/vendor_external/crates/BUILD.semver-1.0.6.bazel
+++ b/examples/crate_universe/vendor_external/crates/BUILD.semver-1.0.6.bazel
@@ -141,6 +141,9 @@
),
edition = "2018",
pkg_name = "semver",
+ rustc_env_files = [
+ ":cargo_toml_env_vars",
+ ],
rustc_flags = [
"--cap-lints=allow",
],
diff --git a/examples/crate_universe/vendor_external/crates/BUILD.serde-1.0.136.bazel b/examples/crate_universe/vendor_external/crates/BUILD.serde-1.0.136.bazel
index 12c3c25..8c02597 100644
--- a/examples/crate_universe/vendor_external/crates/BUILD.serde-1.0.136.bazel
+++ b/examples/crate_universe/vendor_external/crates/BUILD.serde-1.0.136.bazel
@@ -141,6 +141,9 @@
),
edition = "2015",
pkg_name = "serde",
+ rustc_env_files = [
+ ":cargo_toml_env_vars",
+ ],
rustc_flags = [
"--cap-lints=allow",
],
diff --git a/examples/crate_universe/vendor_external/crates/BUILD.syn-1.0.86.bazel b/examples/crate_universe/vendor_external/crates/BUILD.syn-1.0.86.bazel
index a6e9ce4..13cc642 100644
--- a/examples/crate_universe/vendor_external/crates/BUILD.syn-1.0.86.bazel
+++ b/examples/crate_universe/vendor_external/crates/BUILD.syn-1.0.86.bazel
@@ -320,6 +320,9 @@
),
edition = "2018",
pkg_name = "syn",
+ rustc_env_files = [
+ ":cargo_toml_env_vars",
+ ],
rustc_flags = [
"--cap-lints=allow",
],
diff --git a/examples/crate_universe/vendor_external/crates/BUILD.unicase-2.6.0.bazel b/examples/crate_universe/vendor_external/crates/BUILD.unicase-2.6.0.bazel
index 81dbc0d..c1322c4 100644
--- a/examples/crate_universe/vendor_external/crates/BUILD.unicase-2.6.0.bazel
+++ b/examples/crate_universe/vendor_external/crates/BUILD.unicase-2.6.0.bazel
@@ -133,6 +133,9 @@
),
edition = "2015",
pkg_name = "unicase",
+ rustc_env_files = [
+ ":cargo_toml_env_vars",
+ ],
rustc_flags = [
"--cap-lints=allow",
],
diff --git a/examples/crate_universe/vendor_external/crates/BUILD.winapi-0.3.9.bazel b/examples/crate_universe/vendor_external/crates/BUILD.winapi-0.3.9.bazel
index 76ab3ba..ac54a2d 100644
--- a/examples/crate_universe/vendor_external/crates/BUILD.winapi-0.3.9.bazel
+++ b/examples/crate_universe/vendor_external/crates/BUILD.winapi-0.3.9.bazel
@@ -159,6 +159,9 @@
),
edition = "2015",
pkg_name = "winapi",
+ rustc_env_files = [
+ ":cargo_toml_env_vars",
+ ],
rustc_flags = [
"--cap-lints=allow",
],
diff --git a/examples/crate_universe/vendor_external/crates/BUILD.winapi-i686-pc-windows-gnu-0.4.0.bazel b/examples/crate_universe/vendor_external/crates/BUILD.winapi-i686-pc-windows-gnu-0.4.0.bazel
index b56c4e6..d10a1a2 100644
--- a/examples/crate_universe/vendor_external/crates/BUILD.winapi-i686-pc-windows-gnu-0.4.0.bazel
+++ b/examples/crate_universe/vendor_external/crates/BUILD.winapi-i686-pc-windows-gnu-0.4.0.bazel
@@ -133,6 +133,9 @@
),
edition = "2015",
pkg_name = "winapi-i686-pc-windows-gnu",
+ rustc_env_files = [
+ ":cargo_toml_env_vars",
+ ],
rustc_flags = [
"--cap-lints=allow",
],
diff --git a/examples/crate_universe/vendor_external/crates/BUILD.winapi-x86_64-pc-windows-gnu-0.4.0.bazel b/examples/crate_universe/vendor_external/crates/BUILD.winapi-x86_64-pc-windows-gnu-0.4.0.bazel
index 3e27bb2..a3640c3 100644
--- a/examples/crate_universe/vendor_external/crates/BUILD.winapi-x86_64-pc-windows-gnu-0.4.0.bazel
+++ b/examples/crate_universe/vendor_external/crates/BUILD.winapi-x86_64-pc-windows-gnu-0.4.0.bazel
@@ -133,6 +133,9 @@
),
edition = "2015",
pkg_name = "winapi-x86_64-pc-windows-gnu",
+ rustc_env_files = [
+ ":cargo_toml_env_vars",
+ ],
rustc_flags = [
"--cap-lints=allow",
],