mix in label in crate hash computation (#1083)

Consider the situation where we have two variants of the same crate:
```
rust_library(
    name = "foo",
    srcs = ["foo.rs"],
)

rust_library(
    name = "foo2",
    crate_name = "foo",
    srcs = ["foo.rs"],
)
```

A use case for this is for example when we want to define different variants
of a crate using different feature sets, e.g., define a rustc_private non-std
variant of a vendored crate of the standard library together with a more
standard version of the vendored crate that requires the standard library.

Currently, this is a fragile definition since the output rlib filename of both
of these is the same, e.g., `libfoo-$HASH.rlib`, where `$HASH` is
derived from the crate root source filename, in this case `foo.rs`. So whenever
we have a Bazel query that includes both of these, the build may fail with
errors like:
```
ERROR: file 'test/unit/crate_variants/libfoo-717083168.rlib' is generated by these conflicting actions:
Label: //test/unit/crate_variants:foo2, //test/unit/crate_variants:foo
```

This patch reduces the risk of such output filename collisions by mixing in
the rule label in the output hash calculation.
10 files changed
tree: 9041ecd14939454891ab16f5a894008fe52e8959
  1. .bazelci/
  2. .github/
  3. bindgen/
  4. cargo/
  5. crate_universe/
  6. docs/
  7. examples/
  8. proto/
  9. rust/
  10. test/
  11. tools/
  12. util/
  13. wasm_bindgen/
  14. .bazelignore
  15. .bazelrc
  16. .gitignore
  17. ARCHITECTURE.md
  18. AUTHORS
  19. BUILD.bazel
  20. CODEOWNERS
  21. COMPATIBILITY.md
  22. CONTRIBUTING.md
  23. CONTRIBUTORS
  24. LICENSE.txt
  25. README.md
  26. WORKSPACE.bazel
  27. workspace.bzl
README.md

Rust Rules

  • Postsubmit Build status

Overview

This repository provides rules for building Rust projects with Bazel.

Community

General discussions and announcements take place in the GitHub Discussions, but there are additional places where community members gather to discuss rules_rust.

Documentation

Please refer to the full documentation.