Refactor rustc_compile_action to construct CrateInfo internally (#2188)

In #2161, I anticipated to make
[create_crate_info_dict](https://github.com/bazelbuild/rules_rust/pull/2161/files#diff-b75adb75969318e09670c45b8eea5aaf147fdc1d2cf229a72a17bd39edf49163R853)
reusable across all rules and aspects.

The logic to construct `crate_info` is significantly different among the
rules and aspects. As I tried to to expand the arguments to make
`create_crate_info_dict` universally reusable, the arguments grow which
make it not worth anymore. This PR changes the refactoring approach.

Before (result from #2161)
```
def _rust_library_common()
    return rustc_compile_action(
        # the callback allows us to slowly refactor one rule or aspect at a time.
        create_crate_info_callback = create_crate_info_dict,
    )

def rustc_compile_action(create_crate_info_callback)
  if create_crate_info_callback:
    crate_info_dict = create_crate_info_callback()
```

After (result from this PR)
```
def _rust_library_common()
    # create crate_info_dict
    return rustc_compile_action(
        crate_info_dict = crate_info_dict,
    )

def rustc_compile_action(crate_info_dict)
  # crate_info_dict always exists
```

Instead of creating `crate_info_dict` at the beginning of
`rustc_compile_action`, this PR lifted the creation logic to the rules
and aspects completely so that they can add any custom logic without
caring about the `rustc_compile_action`'s implementation.

---------

Co-authored-by: scentini <rosica@google.com>
8 files changed
tree: d4093f37c78e12ea367c90a85a6e4a59193efcb5
  1. .bazelci/
  2. .github/
  3. bindgen/
  4. cargo/
  5. crate_universe/
  6. docs/
  7. examples/
  8. ffi/
  9. proto/
  10. rust/
  11. test/
  12. tools/
  13. util/
  14. wasm_bindgen/
  15. .bazelignore
  16. .bazelrc
  17. .clang-format
  18. .gitattributes
  19. .gitignore
  20. .rustfmt.toml
  21. ARCHITECTURE.md
  22. AUTHORS
  23. BUILD.bazel
  24. CODEOWNERS
  25. COMPATIBILITY.md
  26. CONTRIBUTING.md
  27. CONTRIBUTORS
  28. LICENSE.txt
  29. MODULE.bazel
  30. README.md
  31. version.bzl
  32. 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.