Platform transition added to Rust binary rules. (#2310)

Without much insight into core Bazel's plans for supporting "flagless"
builds across platforms, this seems like the most direct way to select
the platform for a given Rust binary target (all the terminal rules)
that doesn't need additional work to forward providers.

Currently I'm using `platform_transition_binary`
(https://github.com/aspect-build/bazel-lib/blob/main/docs/transitions.md),
but it doesn't work with Rust Analyzer/Clippy/etc. presumably due to not
forwarding the providers. In the case of this particular rule, it also
doesn't work for something like `rust_shared_library()` which is
explicitly not an `executable = True` target.

@illicitonion brought to my attention `with_cfg`
(https://github.com/fmeum/with_cfg.bzl) which could be used as an
alternative by consumers of `rules_rust` instead of this PR. That feels
reasonable, though certainly more work for individual users and appears
to rely on a lot of Bazel black magic.

Along the same lines, this could wait on rule inheritance as presumably
a more formally supported `with_cfg` approach, which would also be up to
individual users and not `rules_rust`.
7 files changed
tree: 8713e83951f81c9ff1d3c9b1d8dd2d641dfe3eb0
  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. .bazelversion
  20. .clang-format
  21. .envrc
  22. .gitattributes
  23. .gitignore
  24. .prettierrc.toml
  25. .rustfmt.toml
  26. ARCHITECTURE.md
  27. AUTHORS
  28. BUILD.bazel
  29. CODEOWNERS
  30. COMPATIBILITY.md
  31. CONTRIBUTING.md
  32. CONTRIBUTORS
  33. LICENSE.txt
  34. MODULE.bazel
  35. README.md
  36. version.bzl
  37. 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.