load_arbitrary_tool uses tool_suburl to look up sha256 (#1695)

* load_arbitrary_tool uses tool_suburl to look up sha256

In load_arbitrary_tool, use the suburl (which contains the a
subdirectory containing the date, if the version is beta or nightly) to
look up the sha256 to to download a specific archive. This allows Bazel
to cache the downloaded archive by hash, and supports the correct
behavior for dated nightly builds, as provided in the FILE_KEY_TO_SHA
dict in //rust:known_shas.bzl.

The most recent nightly entry is given in FILE_KEY_TO_SHA as:

```
    "2022-11-02/cargo-nightly-x86_64-unknown-linux-gnu.tar.gz": "d32e0a9f78ece567627b9b572912b000c53099c0dd9c9f5cea54848de02c6486",
```

This change fixes downloaded archive caching when using the nightly
toolchains, including the default nightly toolchain.

* Refactor load_arbitrary_tool()

Move the sha256 code out of load_arbitrary_tool() into a new function,
lookup_tool_sha256().

Implement a new unit test to confirm that the sha256 lookup code behaves
as expected, and returns the expected sha256 hash from the static list
of known tool hashes.
2 files changed
tree: 86d4e9677a87eb2c3eadd1a6bb26073c2b81076a
  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. .clang-format
  17. .gitignore
  18. ARCHITECTURE.md
  19. AUTHORS
  20. BUILD.bazel
  21. CODEOWNERS
  22. COMPATIBILITY.md
  23. CONTRIBUTING.md
  24. CONTRIBUTORS
  25. LICENSE.txt
  26. README.md
  27. version.bzl
  28. 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.