Skip to content

Commit

Permalink
Change default Rust distribution downloads from .tar.gz to .tar.xz (#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
dtolnay authored Jan 5, 2024
1 parent 6b35cfd commit df73e91
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
10 changes: 5 additions & 5 deletions docs/flatten.md
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@ A given instance of this rule should be accompanied by a toolchain_repository_pr
| <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> |
| <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> |
| <a id="rust_toolchain_tools_repository-target_triple"></a>target_triple | The Rust-style target that this compiler builds for. | String | required | |
| <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> |
| <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> |
| <a id="rust_toolchain_tools_repository-version"></a>version | The version of the tool among "nightly", "beta", or an exact version. | String | required | |


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

**RETURNS**
Expand Down Expand Up @@ -1954,7 +1954,7 @@ See `load_arbitrary_tool` in `@rules_rust//rust:repositories.bzl` for more detai
| <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"]` |
| <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` |
| <a id="rust_register_toolchains-extra_exec_rustc_flags"></a>extra_exec_rustc_flags | Extra flags to pass to rustc in exec configuration. | `None` |
| <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"]` |
| <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"]` |
| <a id="rust_register_toolchains-version"></a>version | **Deprecated**: Use <code>versions</code> instead. | `None` |
| <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>. | `[]` |

Expand Down Expand Up @@ -2012,7 +2012,7 @@ Assembles a remote repository for the given toolchain params, produces a proxy r
| <a id="rust_repository_set-extra_exec_rustc_flags"></a>extra_exec_rustc_flags | Extra flags to pass to rustc in exec configuration. | `None` |
| <a id="rust_repository_set-opt_level"></a>opt_level | Dictionary of target triples to optimiztion config. | `None` |
| <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` |
| <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"]` |
| <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"]` |
| <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` |
| <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` |
| <a id="rust_repository_set-exec_compatible_with"></a>exec_compatible_with | A list of constraints for the execution platform for this toolchain. | `None` |
Expand Down Expand Up @@ -2120,7 +2120,7 @@ Assembles a remote repository for the given toolchain params, produces a proxy r
| <a id="rust_toolchain_repository-extra_exec_rustc_flags"></a>extra_exec_rustc_flags | Extra flags to pass to rustc in exec configuration. | `None` |
| <a id="rust_toolchain_repository-opt_level"></a>opt_level | Optimization level config for this toolchain. | `None` |
| <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` |
| <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"]` |
| <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"]` |
| <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` |

**RETURNS**
Expand Down
10 changes: 5 additions & 5 deletions docs/rust_repositories.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ A given instance of this rule should be accompanied by a toolchain_repository_pr
| <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> |
| <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> |
| <a id="rust_toolchain_tools_repository-target_triple"></a>target_triple | The Rust-style target that this compiler builds for. | String | required | |
| <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> |
| <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> |
| <a id="rust_toolchain_tools_repository-version"></a>version | The version of the tool among "nightly", "beta", or an exact version. | String | required | |


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

**RETURNS**
Expand Down Expand Up @@ -273,7 +273,7 @@ See `load_arbitrary_tool` in `@rules_rust//rust:repositories.bzl` for more detai
| <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"]` |
| <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` |
| <a id="rust_register_toolchains-extra_exec_rustc_flags"></a>extra_exec_rustc_flags | Extra flags to pass to rustc in exec configuration. | `None` |
| <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"]` |
| <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"]` |
| <a id="rust_register_toolchains-version"></a>version | **Deprecated**: Use <code>versions</code> instead. | `None` |
| <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>. | `[]` |

Expand Down Expand Up @@ -331,7 +331,7 @@ Assembles a remote repository for the given toolchain params, produces a proxy r
| <a id="rust_repository_set-extra_exec_rustc_flags"></a>extra_exec_rustc_flags | Extra flags to pass to rustc in exec configuration. | `None` |
| <a id="rust_repository_set-opt_level"></a>opt_level | Dictionary of target triples to optimiztion config. | `None` |
| <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` |
| <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"]` |
| <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"]` |
| <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` |
| <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` |
| <a id="rust_repository_set-exec_compatible_with"></a>exec_compatible_with | A list of constraints for the execution platform for this toolchain. | `None` |
Expand Down Expand Up @@ -375,7 +375,7 @@ Assembles a remote repository for the given toolchain params, produces a proxy r
| <a id="rust_toolchain_repository-extra_exec_rustc_flags"></a>extra_exec_rustc_flags | Extra flags to pass to rustc in exec configuration. | `None` |
| <a id="rust_toolchain_repository-opt_level"></a>opt_level | Optimization level config for this toolchain. | `None` |
| <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` |
| <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"]` |
| <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"]` |
| <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` |

**RETURNS**
Expand Down
2 changes: 1 addition & 1 deletion rust/private/repository_utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ load(
load("//rust/private:common.bzl", "DEFAULT_NIGHTLY_ISO_DATE")

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

Expand Down
6 changes: 3 additions & 3 deletions rust/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ def rust_toolchain_repository(
opt_level (dict, optional): Optimization level config for this toolchain.
sha256s (str, optional): A dict associating tool subdirectories to sha256 hashes. See
[rust_repositories](#rust_repositories) for more details.
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']
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']
auth (dict): 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.
Expand Down Expand Up @@ -673,7 +673,7 @@ def rust_analyzer_toolchain_repository(
iso_date (str, optional): The date of the tool.
sha256s (str, optional): A dict associating tool subdirectories to sha256 hashes. See
[rust_repositories](#rust_repositories) for more details.
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']
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']
auth (dict): 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.
Expand Down Expand Up @@ -792,7 +792,7 @@ def rustfmt_toolchain_repository(
channel (str, optional): The channel value to with which to constrain the toolchain.
sha256s (str, optional): A dict associating tool subdirectories to sha256 hashes. See
[rust_repositories](#rust_repositories) for more details.
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']
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']
auth (dict): 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.
Expand Down
Loading

0 comments on commit df73e91

Please sign in to comment.