Fetch each component of a Rust release on demand (#4397)

This change splits a toolchain's downloads by component so a build only
fetches what it uses, and extracts the compiler once per execution
platform instead of once per target triple.

`rust_toolchain_tools_repository` takes `components`, the archives to
download, and labels for the repositories holding the rest.
`rust_repository_set` creates, per channel:

* `<name>__<channel>__rustc`: the compiler, the tools beside it and the
standard library of the execution platform, shared by every target
triple.
* `<name>__<channel>__cargo` and `<name>__<channel>__clippy`: fetched
only when a `cargo_toolchain` or `clippy_toolchain` is analyzed.
* `<name>__<target_triple>__<channel>_tools`: the toolchain declarations
and, for a target other than the execution platform, its standard
library.

The hub and proxy repositories are unchanged. `rust_host_tools` stays in
one repository because crate_universe reads `bin/cargo` from it by path.

A rustc driver loads `librustc_driver` relative to its own real path, so
the Clippy repository links the compiler's `lib/` (and its DLLs on
Windows) beside `clippy-driver` when it is fetched. The generated
`rust_toolchain` drops the deprecated `cargo` attribute, which would
have fetched Cargo for every build; `$(CARGO)` comes from the
`cargo_toolchain`. The default tool templates of `crates_repository` and
`cargo_bootstrap_repository` follow the new names.

A `rust_library` build from an empty output base now fetches the
compiler repository, the declarations repository and the hub, nothing
else.
8 files changed
tree: 541fbb32ee8d7f7ec814ff559cd5d0718ea87f50
  1. .bazelci/
  2. .bcr/
  3. .github/
  4. cargo/
  5. crate_universe/
  6. docs/
  7. examples/
  8. extensions/
  9. ffi/
  10. nix/
  11. rust/
  12. test/
  13. tools/
  14. util/
  15. .bazelignore
  16. .bazelrc
  17. .clang-format
  18. .clippy.toml
  19. .envrc
  20. .gitattributes
  21. .gitignore
  22. .pre-commit-config.yaml
  23. .prettierrc.toml
  24. .rustfmt.toml
  25. .typos.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.

Starter repo

The fastest way to try this in an empty project is to click the green “Use this template” button on https://github.com/bazel-starters/rust.

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.