Use `crate_name` to also match `crate_root`. (#2824)

This allows targets to have special names that do not match their
sources while still ensuring a root is found. I've encountered this when
creating macros where I have a Rust target that is a side-effect and not
the named target itself. E.g.
```starlark
load("@rules_rust//rust:defs.bzl", "rust_binary")
load("//control/private:control.bzl", _control_binary = "control_binary")

def control_binary(
    name, 
    # ...
    **kwargs):

    rust_binary(
        name = name + "_bin",
        # ...
        **kwargs
    )

    _control_binary(
        name = name,
        bin = name + "_bin",
        # ...
        **kwargs
    )
```

Being able to specify `crate_name` will both ensure the binary is
compiled with a cleaner name for the runtime and be able to do the
nominal `crate_root` matching. The diff after this PR achieves the
desired behavior.

```diff
--- before/defs.bzl	2024-08-31 12:41:24
+++ after/defs.bzl	2024-08-31 12:42:09
@@ -8,6 +8,7 @@

     rust_binary(
         name = name + "_bin",
+        crate_name = name,
         # ...
         **kwargs
     )
```
6 files changed
tree: 51cda27db643ecf706842073bff43aa0ae451f12
  1. .bazelci/
  2. .bcr/
  3. .github/
  4. bindgen/
  5. cargo/
  6. crate_universe/
  7. docs/
  8. examples/
  9. ffi/
  10. nix/
  11. proto/
  12. rust/
  13. test/
  14. tools/
  15. util/
  16. wasm_bindgen/
  17. .bazelignore
  18. .bazelrc
  19. .clang-format
  20. .envrc
  21. .gitattributes
  22. .gitignore
  23. .prettierrc.toml
  24. .rustfmt.toml
  25. ARCHITECTURE.md
  26. AUTHORS
  27. BUILD.bazel
  28. CODEOWNERS
  29. COMPATIBILITY.md
  30. CONTRIBUTING.md
  31. CONTRIBUTORS
  32. LICENSE.txt
  33. MODULE.bazel
  34. README.md
  35. version.bzl
  36. WORKSPACE.bazel
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.