Skip to content

Commit df73e91

Browse files
authored
Change default Rust distribution downloads from .tar.gz to .tar.xz (#2399)
Rust infra folks requested that I send this change. According to Rust's logs, currently 30% of bytes served by static.rust-lang.org are .gz tarballs, and primarily that is attributed to Bazel according to user-agent. The .gz tarballs are needlessly large and consume more bandwidth for Rust than we want to serve. This PR changes rules_rust to default to .xz tarballs instead. Rustup has been using xz downloads for the past 6.5 years. The default set of tars downloaded by rules_rust (rustc, rust-std, cargo, clippy, rustfmt, llvm-tools) is 215M in gz and 127M in xz, which is 41% smaller. If adopted, this PR would save static.rust-lang.org more than 12% of its bandwidth. As a tradeoff, decompressing that set of 6 files with xz is slower: 3.6 seconds for gz and 8.4 seconds for xz. (Single-threaded. If Bazel extracts different files in parallel than the magnitude of the difference would be smaller but the ratio is similar.) In rust-lang/infra-team#89 we intend to sunset gz downloads, or do something to push users away from them (such as throttling), so gz will be the wrong choice no matter what. To make up for decompression speed we are investigating providing zstd tarballs in rust-lang/infra-team#97 which decompress significantly faster than gz while being not much larger than xz.
1 parent 6b35cfd commit df73e91

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
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-rustfmt_version"></a>rustfmt_version | The version of the tool among "nightly", "beta", or an exact version. | String | optional | <code>""</code> |
13221322
| <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> |
13231323
| <a id="rust_toolchain_tools_repository-target_triple"></a>target_triple | The Rust-style target that this compiler builds for. | String | required | |
1324-
| <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.gz"]</code> |
1324+
| <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> |
13251325
| <a id="rust_toolchain_tools_repository-version"></a>version | The version of the tool among "nightly", "beta", or an exact version. | String | required | |
13261326

13271327

@@ -1737,7 +1737,7 @@ Assemble a remote rust_analyzer_toolchain target based on the given params.
17371737
| <a id="rust_analyzer_toolchain_repository-target_compatible_with"></a>target_compatible_with | A list of constraints for the target platform for this toolchain. | `[]` |
17381738
| <a id="rust_analyzer_toolchain_repository-iso_date"></a>iso_date | The date of the tool. | `None` |
17391739
| <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` |
1740-
| <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.gz'] | `None` |
1740+
| <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` |
17411741
| <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` |
17421742

17431743
**RETURNS**
@@ -1954,7 +1954,7 @@ See `load_arbitrary_tool` in `@rules_rust//rust:repositories.bzl` for more detai
19541954
| <a id="rust_register_toolchains-extra_target_triples"></a>extra_target_triples | Additional rust-style targets that rust toolchains should support. | `["wasm32-unknown-unknown", "wasm32-wasi"]` |
19551955
| <a id="rust_register_toolchains-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` |
19561956
| <a id="rust_register_toolchains-extra_exec_rustc_flags"></a>extra_exec_rustc_flags | Extra flags to pass to rustc in exec configuration. | `None` |
1957-
| <a id="rust_register_toolchains-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.gz"]` |
1957+
| <a id="rust_register_toolchains-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"]` |
19581958
| <a id="rust_register_toolchains-version"></a>version | **Deprecated**: Use <code>versions</code> instead. | `None` |
19591959
| <a id="rust_register_toolchains-versions"></a>versions | A list of toolchain versions to download. This paramter only accepts one versions per channel. E.g. <code>["1.65.0", "nightly/2022-11-02", "beta/2020-12-30"]</code>. | `[]` |
19601960

@@ -2012,7 +2012,7 @@ Assembles a remote repository for the given toolchain params, produces a proxy r
20122012
| <a id="rust_repository_set-extra_exec_rustc_flags"></a>extra_exec_rustc_flags | Extra flags to pass to rustc in exec configuration. | `None` |
20132013
| <a id="rust_repository_set-opt_level"></a>opt_level | Dictionary of target triples to optimiztion config. | `None` |
20142014
| <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` |
2015-
| <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.gz"]` |
2015+
| <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"]` |
20162016
| <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` |
20172017
| <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` |
20182018
| <a id="rust_repository_set-exec_compatible_with"></a>exec_compatible_with | A list of constraints for the execution platform for this toolchain. | `None` |
@@ -2120,7 +2120,7 @@ Assembles a remote repository for the given toolchain params, produces a proxy r
21202120
| <a id="rust_toolchain_repository-extra_exec_rustc_flags"></a>extra_exec_rustc_flags | Extra flags to pass to rustc in exec configuration. | `None` |
21212121
| <a id="rust_toolchain_repository-opt_level"></a>opt_level | Optimization level config for this toolchain. | `None` |
21222122
| <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` |
2123-
| <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.gz'] | `["https://static.rust-lang.org/dist/{}.tar.gz"]` |
2123+
| <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"]` |
21242124
| <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` |
21252125

21262126
**RETURNS**

docs/rust_repositories.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ A given instance of this rule should be accompanied by a toolchain_repository_pr
182182
| <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> |
183183
| <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> |
184184
| <a id="rust_toolchain_tools_repository-target_triple"></a>target_triple | The Rust-style target that this compiler builds for. | String | required | |
185-
| <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.gz"]</code> |
185+
| <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> |
186186
| <a id="rust_toolchain_tools_repository-version"></a>version | The version of the tool among "nightly", "beta", or an exact version. | String | required | |
187187

188188

@@ -220,7 +220,7 @@ Assemble a remote rust_analyzer_toolchain target based on the given params.
220220
| <a id="rust_analyzer_toolchain_repository-target_compatible_with"></a>target_compatible_with | A list of constraints for the target platform for this toolchain. | `[]` |
221221
| <a id="rust_analyzer_toolchain_repository-iso_date"></a>iso_date | The date of the tool. | `None` |
222222
| <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` |
223-
| <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.gz'] | `None` |
223+
| <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` |
224224
| <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` |
225225

226226
**RETURNS**
@@ -273,7 +273,7 @@ See `load_arbitrary_tool` in `@rules_rust//rust:repositories.bzl` for more detai
273273
| <a id="rust_register_toolchains-extra_target_triples"></a>extra_target_triples | Additional rust-style targets that rust toolchains should support. | `["wasm32-unknown-unknown", "wasm32-wasi"]` |
274274
| <a id="rust_register_toolchains-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` |
275275
| <a id="rust_register_toolchains-extra_exec_rustc_flags"></a>extra_exec_rustc_flags | Extra flags to pass to rustc in exec configuration. | `None` |
276-
| <a id="rust_register_toolchains-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.gz"]` |
276+
| <a id="rust_register_toolchains-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"]` |
277277
| <a id="rust_register_toolchains-version"></a>version | **Deprecated**: Use <code>versions</code> instead. | `None` |
278278
| <a id="rust_register_toolchains-versions"></a>versions | A list of toolchain versions to download. This paramter only accepts one versions per channel. E.g. <code>["1.65.0", "nightly/2022-11-02", "beta/2020-12-30"]</code>. | `[]` |
279279

@@ -331,7 +331,7 @@ Assembles a remote repository for the given toolchain params, produces a proxy r
331331
| <a id="rust_repository_set-extra_exec_rustc_flags"></a>extra_exec_rustc_flags | Extra flags to pass to rustc in exec configuration. | `None` |
332332
| <a id="rust_repository_set-opt_level"></a>opt_level | Dictionary of target triples to optimiztion config. | `None` |
333333
| <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` |
334-
| <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.gz"]` |
334+
| <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"]` |
335335
| <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` |
336336
| <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` |
337337
| <a id="rust_repository_set-exec_compatible_with"></a>exec_compatible_with | A list of constraints for the execution platform for this toolchain. | `None` |
@@ -375,7 +375,7 @@ Assembles a remote repository for the given toolchain params, produces a proxy r
375375
| <a id="rust_toolchain_repository-extra_exec_rustc_flags"></a>extra_exec_rustc_flags | Extra flags to pass to rustc in exec configuration. | `None` |
376376
| <a id="rust_toolchain_repository-opt_level"></a>opt_level | Optimization level config for this toolchain. | `None` |
377377
| <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` |
378-
| <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.gz'] | `["https://static.rust-lang.org/dist/{}.tar.gz"]` |
378+
| <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"]` |
379379
| <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` |
380380

381381
**RETURNS**

rust/private/repository_utils.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ load(
1111
load("//rust/private:common.bzl", "DEFAULT_NIGHTLY_ISO_DATE")
1212

1313
DEFAULT_TOOLCHAIN_NAME_PREFIX = "toolchain_for"
14-
DEFAULT_STATIC_RUST_URL_TEMPLATES = ["https://static.rust-lang.org/dist/{}.tar.gz"]
14+
DEFAULT_STATIC_RUST_URL_TEMPLATES = ["https://static.rust-lang.org/dist/{}.tar.xz"]
1515
DEFAULT_NIGHTLY_VERSION = "nightly/{}".format(DEFAULT_NIGHTLY_ISO_DATE)
1616
DEFAULT_EXTRA_TARGET_TRIPLES = ["wasm32-unknown-unknown", "wasm32-wasi"]
1717

rust/repositories.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ def rust_toolchain_repository(
534534
opt_level (dict, optional): Optimization level config for this toolchain.
535535
sha256s (str, optional): A dict associating tool subdirectories to sha256 hashes. See
536536
[rust_repositories](#rust_repositories) for more details.
537-
urls (list, optional): 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.gz']
537+
urls (list, optional): 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']
538538
auth (dict): Auth object compatible with repository_ctx.download to use when downloading files.
539539
See [repository_ctx.download](https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download) for more details.
540540
@@ -673,7 +673,7 @@ def rust_analyzer_toolchain_repository(
673673
iso_date (str, optional): The date of the tool.
674674
sha256s (str, optional): A dict associating tool subdirectories to sha256 hashes. See
675675
[rust_repositories](#rust_repositories) for more details.
676-
urls (list, optional): 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.gz']
676+
urls (list, optional): 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']
677677
auth (dict): Auth object compatible with repository_ctx.download to use when downloading files.
678678
See [repository_ctx.download](https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download) for more details.
679679
@@ -792,7 +792,7 @@ def rustfmt_toolchain_repository(
792792
channel (str, optional): The channel value to with which to constrain the toolchain.
793793
sha256s (str, optional): A dict associating tool subdirectories to sha256 hashes. See
794794
[rust_repositories](#rust_repositories) for more details.
795-
urls (list, optional): 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.gz']
795+
urls (list, optional): 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']
796796
auth (dict): Auth object compatible with repository_ctx.download to use when downloading files.
797797
See [repository_ctx.download](https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download) for more details.
798798

0 commit comments

Comments
 (0)