Skip to content

Commit f9626f9

Browse files
authored
Updated repository rules to notify users about non-reproducible repos. (#2593)
This change updates rules_rust repository rules to report when the rules are not guaranteed to be reproducible due to missing sha256 values when fetching Rust artifacts. A common case for this is when users request newer versions of Rust than the ones referenced in [@rules_rust//rust:known_shas.bzl](https://github.com/bazelbuild/rules_rust/blob/0.41.0/rust/known_shas.bzl), thus leading to unnecessary downloads or potential security issues. After this PR, users will see warnings similar to when `integrity` is omitted from `http_archive` definitions ``` DEBUG: Rule 'rust_analyzer_1.77.1_tools' indicated that a canonical reproducible form can be obtained by modifying arguments sha256s = {"rust-src-1.77.1.tar.xz": "ad2064aa4a444ae35d55b8b57bec837b90c4f10fe6d721f8fce86d7a1992f607", "rustc-1.77.1-aarch64-apple-darwin.tar.xz": "8da1814eb8358236e88ceb155e32f0f34bbe71cb19cd9700c7eb40e675738d77"} DEBUG: Repository rust_analyzer_1.77.1_tools instantiated at: /Users/user/rules_rust/WORKSPACE.bazel:7:25: in <toplevel> /Users/user/rules_rust/rust/repositories.bzl:202:10: in rust_register_toolchains /private/var/tmp/_bazel_user/76282c66b0dfe3c5cb9a230bdc913a52/external/bazel_tools/tools/build_defs/repo/utils.bzl:240:18: in maybe /Users/user/rules_rust/rust/repositories.bzl:737:45: in rust_analyzer_toolchain_repository Repository rule rust_analyzer_toolchain_tools_repository defined at: /Users/user/rules_rust/rust/repositories.bzl:705:59: in <toplevel> DEBUG: Rule 'rust_darwin_aarch64__aarch64-apple-darwin__stable_tools' indicated that a canonical reproducible form can be obtained by modifying arguments sha256s = {"rustc-1.77.1-aarch64-apple-darwin.tar.xz": "8da1814eb8358236e88ceb155e32f0f34bbe71cb19cd9700c7eb40e675738d77", "clippy-1.77.1-aarch64-apple-darwin.tar.xz": "343f125b0c05dd756e71992c04fb5a4a29ce705c50a739d76eb7f38b088103ac", "cargo-1.77.1-aarch64-apple-darwin.tar.xz": "c0249b6c247953cbe3b01e276988b6ca600aeba4e91332cd2ddaa0b7eee4dfb7", "llvm-tools-1.77.1-aarch64-apple-darwin.tar.xz": "dfee0aaed6b24d34362f229f2926e6b1805f2a8ec4a090c7c28837b82a9bdfd1", "rust-std-1.77.1-aarch64-apple-darwin.tar.xz": "3b5b71e40d934de25dcb553b9df28289d38640e6fa2654b42410f4cc8d9bed2a"} DEBUG: Repository rust_darwin_aarch64__aarch64-apple-darwin__stable_tools instantiated at: /Users/user/rules_rust/WORKSPACE.bazel:7:25: in <toplevel> /Users/user/rules_rust/rust/repositories.bzl:230:14: in rust_register_toolchains /private/var/tmp/_bazel_user/76282c66b0dfe3c5cb9a230bdc913a52/external/bazel_tools/tools/build_defs/repo/utils.bzl:240:18: in maybe /Users/user/rules_rust/rust/repositories.bzl:1043:61: in rust_repository_set /Users/user/rules_rust/rust/repositories.bzl:601:36: in rust_toolchain_repository Repository rule rust_toolchain_tools_repository defined at: /Users/user/rules_rust/rust/repositories.bzl:475:50: in <toplevel> ``` The above was produced by running `bazel test //...` after applying the following diff: ```diff diff --git a/rust/private/common.bzl b/rust/private/common.bzl index 52728fe..c035ad5 100644 --- a/rust/private/common.bzl +++ b/rust/private/common.bzl @@ -31,7 +31,7 @@ load(":providers.bzl", "CrateGroupInfo", "CrateInfo", "DepInfo", "DepVariantInfo # # Note: Code in `.github/workflows/crate_universe.yaml` looks for this line, if # you remove it or change its format, you will also need to update that code. -DEFAULT_RUST_VERSION = "1.77.0" +DEFAULT_RUST_VERSION = "1.77.1" DEFAULT_NIGHTLY_ISO_DATE = "2024-03-21" ``` closes #1825
1 parent d3a227d commit f9626f9

File tree

6 files changed

+343
-220
lines changed

6 files changed

+343
-220
lines changed

docs/flatten.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,7 +1321,7 @@ A given instance of this rule should be accompanied by a toolchain_repository_pr
13211321
| <a id="rust_toolchain_tools_repository-opt_level"></a>opt_level | Rustc optimization levels. For more details see the documentation for <code>rust_toolchain.opt_level</code>. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | <code>{}</code> |
13221322
| <a id="rust_toolchain_tools_repository-repo_mapping"></a>repo_mapping | A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.&lt;p&gt;For example, an entry <code>"@foo": "@bar"</code> declares that, for any time this repository depends on <code>@foo</code> (such as a dependency on <code>@foo//some:target</code>, it should actually resolve that dependency within globally-declared <code>@bar</code> (<code>@bar//some:target</code>). | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | required | |
13231323
| <a id="rust_toolchain_tools_repository-rustfmt_version"></a>rustfmt_version | The version of the tool among "nightly", "beta", or an exact version. | String | optional | <code>""</code> |
1324-
| <a id="rust_toolchain_tools_repository-sha256s"></a>sha256s | A dict associating tool subdirectories to sha256 hashes. See [rust_repositories](#rust_repositories) for more details. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | <code>{}</code> |
1324+
| <a id="rust_toolchain_tools_repository-sha256s"></a>sha256s | A dict associating tool subdirectories to sha256 hashes. See [rust_register_toolchains](#rust_register_toolchains) for more details. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | <code>{}</code> |
13251325
| <a id="rust_toolchain_tools_repository-target_triple"></a>target_triple | The Rust-style target that this compiler builds for. | String | required | |
13261326
| <a id="rust_toolchain_tools_repository-urls"></a>urls | A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). | List of strings | optional | <code>["https://static.rust-lang.org/dist/{}.tar.xz"]</code> |
13271327
| <a id="rust_toolchain_tools_repository-version"></a>version | The version of the tool among "nightly", "beta", or an exact version. | String | required | |
@@ -1740,7 +1740,7 @@ Assemble a remote rust_analyzer_toolchain target based on the given params.
17401740
| <a id="rust_analyzer_toolchain_repository-exec_compatible_with"></a>exec_compatible_with | A list of constraints for the execution platform for this toolchain. | `[]` |
17411741
| <a id="rust_analyzer_toolchain_repository-target_compatible_with"></a>target_compatible_with | A list of constraints for the target platform for this toolchain. | `[]` |
17421742
| <a id="rust_analyzer_toolchain_repository-iso_date"></a>iso_date | The date of the tool. | `None` |
1743-
| <a id="rust_analyzer_toolchain_repository-sha256s"></a>sha256s | A dict associating tool subdirectories to sha256 hashes. See [rust_repositories](#rust_repositories) for more details. | `None` |
1743+
| <a id="rust_analyzer_toolchain_repository-sha256s"></a>sha256s | A dict associating tool subdirectories to sha256 hashes. See [rust_register_toolchains](#rust_register_toolchains) for more details. | `None` |
17441744
| <a id="rust_analyzer_toolchain_repository-urls"></a>urls | A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). Defaults to ['https://static.rust-lang.org/dist/{}.tar.xz'] | `None` |
17451745
| <a id="rust_analyzer_toolchain_repository-auth"></a>auth | Auth object compatible with repository_ctx.download to use when downloading files. See [repository_ctx.download](https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download) for more details. | `None` |
17461746

@@ -1929,7 +1929,7 @@ Emits a default set of toolchains for Linux, MacOS, and Freebsd
19291929

19301930
Skip this macro and call the `rust_repository_set` macros directly if you need a compiler for other hosts or for additional target triples.
19311931

1932-
The `sha256` attribute represents a dict associating tool subdirectories to sha256 hashes. As an example:
1932+
The `sha256s` attribute represents a dict associating tool subdirectories to sha256 hashes. As an example:
19331933
```python
19341934
{
19351935
"rust-1.46.0-x86_64-unknown-linux-gnu": "e3b98bc3440fe92817881933f9564389eccb396f5f431f33d48b979fa2fbdcf5",
@@ -2016,7 +2016,7 @@ Assembles a remote repository for the given toolchain params, produces a proxy r
20162016
| <a id="rust_repository_set-extra_rustc_flags"></a>extra_rustc_flags | Dictionary of target triples to list of extra flags to pass to rustc in non-exec configuration. | `None` |
20172017
| <a id="rust_repository_set-extra_exec_rustc_flags"></a>extra_exec_rustc_flags | Extra flags to pass to rustc in exec configuration. | `None` |
20182018
| <a id="rust_repository_set-opt_level"></a>opt_level | Dictionary of target triples to optimiztion config. | `None` |
2019-
| <a id="rust_repository_set-sha256s"></a>sha256s | A dict associating tool subdirectories to sha256 hashes. See [rust_repositories](#rust_repositories) for more details. | `None` |
2019+
| <a id="rust_repository_set-sha256s"></a>sha256s | A dict associating tool subdirectories to sha256 hashes. See [rust_register_toolchains](#rust_register_toolchains) for more details. | `None` |
20202020
| <a id="rust_repository_set-urls"></a>urls | A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). | `["https://static.rust-lang.org/dist/{}.tar.xz"]` |
20212021
| <a id="rust_repository_set-auth"></a>auth | Auth object compatible with repository_ctx.download to use when downloading files. See [repository_ctx.download](https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download) for more details. | `None` |
20222022
| <a id="rust_repository_set-register_toolchain"></a>register_toolchain | If True, the generated <code>rust_toolchain</code> target will become a registered toolchain. | `True` |
@@ -2124,7 +2124,7 @@ Assembles a remote repository for the given toolchain params, produces a proxy r
21242124
| <a id="rust_toolchain_repository-extra_rustc_flags"></a>extra_rustc_flags | Extra flags to pass to rustc in non-exec configuration. | `None` |
21252125
| <a id="rust_toolchain_repository-extra_exec_rustc_flags"></a>extra_exec_rustc_flags | Extra flags to pass to rustc in exec configuration. | `None` |
21262126
| <a id="rust_toolchain_repository-opt_level"></a>opt_level | Optimization level config for this toolchain. | `None` |
2127-
| <a id="rust_toolchain_repository-sha256s"></a>sha256s | A dict associating tool subdirectories to sha256 hashes. See [rust_repositories](#rust_repositories) for more details. | `None` |
2127+
| <a id="rust_toolchain_repository-sha256s"></a>sha256s | A dict associating tool subdirectories to sha256 hashes. See [rust_register_toolchains](#rust_register_toolchains) for more details. | `None` |
21282128
| <a id="rust_toolchain_repository-urls"></a>urls | A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). Defaults to ['https://static.rust-lang.org/dist/{}.tar.xz'] | `["https://static.rust-lang.org/dist/{}.tar.xz"]` |
21292129
| <a id="rust_toolchain_repository-auth"></a>auth | Auth object compatible with repository_ctx.download to use when downloading files. See [repository_ctx.download](https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download) for more details. | `None` |
21302130

docs/rust_repositories.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ A given instance of this rule should be accompanied by a toolchain_repository_pr
183183
| <a id="rust_toolchain_tools_repository-opt_level"></a>opt_level | Rustc optimization levels. For more details see the documentation for <code>rust_toolchain.opt_level</code>. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | <code>{}</code> |
184184
| <a id="rust_toolchain_tools_repository-repo_mapping"></a>repo_mapping | A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.&lt;p&gt;For example, an entry <code>"@foo": "@bar"</code> declares that, for any time this repository depends on <code>@foo</code> (such as a dependency on <code>@foo//some:target</code>, it should actually resolve that dependency within globally-declared <code>@bar</code> (<code>@bar//some:target</code>). | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | required | |
185185
| <a id="rust_toolchain_tools_repository-rustfmt_version"></a>rustfmt_version | The version of the tool among "nightly", "beta", or an exact version. | String | optional | <code>""</code> |
186-
| <a id="rust_toolchain_tools_repository-sha256s"></a>sha256s | A dict associating tool subdirectories to sha256 hashes. See [rust_repositories](#rust_repositories) for more details. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | <code>{}</code> |
186+
| <a id="rust_toolchain_tools_repository-sha256s"></a>sha256s | A dict associating tool subdirectories to sha256 hashes. See [rust_register_toolchains](#rust_register_toolchains) for more details. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | <code>{}</code> |
187187
| <a id="rust_toolchain_tools_repository-target_triple"></a>target_triple | The Rust-style target that this compiler builds for. | String | required | |
188188
| <a id="rust_toolchain_tools_repository-urls"></a>urls | A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). | List of strings | optional | <code>["https://static.rust-lang.org/dist/{}.tar.xz"]</code> |
189189
| <a id="rust_toolchain_tools_repository-version"></a>version | The version of the tool among "nightly", "beta", or an exact version. | String | required | |
@@ -222,7 +222,7 @@ Assemble a remote rust_analyzer_toolchain target based on the given params.
222222
| <a id="rust_analyzer_toolchain_repository-exec_compatible_with"></a>exec_compatible_with | A list of constraints for the execution platform for this toolchain. | `[]` |
223223
| <a id="rust_analyzer_toolchain_repository-target_compatible_with"></a>target_compatible_with | A list of constraints for the target platform for this toolchain. | `[]` |
224224
| <a id="rust_analyzer_toolchain_repository-iso_date"></a>iso_date | The date of the tool. | `None` |
225-
| <a id="rust_analyzer_toolchain_repository-sha256s"></a>sha256s | A dict associating tool subdirectories to sha256 hashes. See [rust_repositories](#rust_repositories) for more details. | `None` |
225+
| <a id="rust_analyzer_toolchain_repository-sha256s"></a>sha256s | A dict associating tool subdirectories to sha256 hashes. See [rust_register_toolchains](#rust_register_toolchains) for more details. | `None` |
226226
| <a id="rust_analyzer_toolchain_repository-urls"></a>urls | A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). Defaults to ['https://static.rust-lang.org/dist/{}.tar.xz'] | `None` |
227227
| <a id="rust_analyzer_toolchain_repository-auth"></a>auth | Auth object compatible with repository_ctx.download to use when downloading files. See [repository_ctx.download](https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download) for more details. | `None` |
228228

@@ -246,7 +246,7 @@ Emits a default set of toolchains for Linux, MacOS, and Freebsd
246246

247247
Skip this macro and call the `rust_repository_set` macros directly if you need a compiler for other hosts or for additional target triples.
248248

249-
The `sha256` attribute represents a dict associating tool subdirectories to sha256 hashes. As an example:
249+
The `sha256s` attribute represents a dict associating tool subdirectories to sha256 hashes. As an example:
250250
```python
251251
{
252252
"rust-1.46.0-x86_64-unknown-linux-gnu": "e3b98bc3440fe92817881933f9564389eccb396f5f431f33d48b979fa2fbdcf5",
@@ -333,7 +333,7 @@ Assembles a remote repository for the given toolchain params, produces a proxy r
333333
| <a id="rust_repository_set-extra_rustc_flags"></a>extra_rustc_flags | Dictionary of target triples to list of extra flags to pass to rustc in non-exec configuration. | `None` |
334334
| <a id="rust_repository_set-extra_exec_rustc_flags"></a>extra_exec_rustc_flags | Extra flags to pass to rustc in exec configuration. | `None` |
335335
| <a id="rust_repository_set-opt_level"></a>opt_level | Dictionary of target triples to optimiztion config. | `None` |
336-
| <a id="rust_repository_set-sha256s"></a>sha256s | A dict associating tool subdirectories to sha256 hashes. See [rust_repositories](#rust_repositories) for more details. | `None` |
336+
| <a id="rust_repository_set-sha256s"></a>sha256s | A dict associating tool subdirectories to sha256 hashes. See [rust_register_toolchains](#rust_register_toolchains) for more details. | `None` |
337337
| <a id="rust_repository_set-urls"></a>urls | A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). | `["https://static.rust-lang.org/dist/{}.tar.xz"]` |
338338
| <a id="rust_repository_set-auth"></a>auth | Auth object compatible with repository_ctx.download to use when downloading files. See [repository_ctx.download](https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download) for more details. | `None` |
339339
| <a id="rust_repository_set-register_toolchain"></a>register_toolchain | If True, the generated <code>rust_toolchain</code> target will become a registered toolchain. | `True` |
@@ -377,7 +377,7 @@ Assembles a remote repository for the given toolchain params, produces a proxy r
377377
| <a id="rust_toolchain_repository-extra_rustc_flags"></a>extra_rustc_flags | Extra flags to pass to rustc in non-exec configuration. | `None` |
378378
| <a id="rust_toolchain_repository-extra_exec_rustc_flags"></a>extra_exec_rustc_flags | Extra flags to pass to rustc in exec configuration. | `None` |
379379
| <a id="rust_toolchain_repository-opt_level"></a>opt_level | Optimization level config for this toolchain. | `None` |
380-
| <a id="rust_toolchain_repository-sha256s"></a>sha256s | A dict associating tool subdirectories to sha256 hashes. See [rust_repositories](#rust_repositories) for more details. | `None` |
380+
| <a id="rust_toolchain_repository-sha256s"></a>sha256s | A dict associating tool subdirectories to sha256 hashes. See [rust_register_toolchains](#rust_register_toolchains) for more details. | `None` |
381381
| <a id="rust_toolchain_repository-urls"></a>urls | A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). Defaults to ['https://static.rust-lang.org/dist/{}.tar.xz'] | `["https://static.rust-lang.org/dist/{}.tar.xz"]` |
382382
| <a id="rust_toolchain_repository-auth"></a>auth | Auth object compatible with repository_ctx.download to use when downloading files. See [repository_ctx.download](https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download) for more details. | `None` |
383383

0 commit comments

Comments
 (0)