Module extensions for using rules_rust with bzlmod
Module Extensions
rust
rust = use_extension("@rules_rust//rust:extensions.bzl", "rust") rust.repository_set(name, allocator_library, dev_components, edition, exec_triple, rustfmt_version, sha256s, target_compatible_with, target_triple, urls, versions) rust.toolchain(aliases, allocator_library, dev_components, edition, extra_exec_rustc_flags, extra_rustc_flags, extra_rustc_flags_triples, extra_target_triples, rust_analyzer_version, rustfmt_version, sha256s, urls, versions)
Rust toolchain extension.
TAG CLASSES
repository_set
Tags for defining rust repository sets (where toolchains are defined).
Attributes
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | Name of the repository_set - if you're looking to replace default toolchains you must use the exact name you're replacing. | Name | optional | "" |
allocator_library | Target that provides allocator functions when rust_library targets are embedded in a cc_binary. | String | optional | "@rules_rust//ffi/cc/allocator_library" |
dev_components | Whether to download the rustc-dev components (defaults to False). Requires version to be "nightly". | Boolean | optional | False |
edition | The rust edition to be used by default (2015, 2018, or 2021). If absent, every rule is required to specify its edition attribute. | String | optional | "" |
exec_triple | Exec triple for this repository_set. | String | optional | "" |
rustfmt_version | The version of the tool among "nightly", "beta", or an exact version. | String | optional | "nightly/2025-03-18" |
sha256s | A dict associating tool subdirectories to sha256 hashes. See rust_repositories for more details. | Dictionary: String -> String | optional | {} |
target_compatible_with | List of platform constraints this toolchain produces, for the particular target_triple this call is for. | List of labels | optional | [] |
target_triple | target_triple to configure. | String | optional | "" |
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 | ["https://static.rust-lang.org/dist/{}.tar.xz"] |
versions | A list of toolchain versions to download. This parameter only accepts one version per channel. E.g. ["1.65.0", "nightly/2022-11-02", "beta/2020-12-30"] . May be set to an empty list ([] ) to inhibit rules_rust from registering toolchains. | List of strings | optional | [] |
toolchain
Tags for defining rust toolchains (where toolchain tools are fetched).
Attributes
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
aliases | Map of full toolchain repository name to an alias. If any repository is created by this extension matches a key in this dictionary, the name of the created repository will be remapped to the value instead. This may be required to work around path length limits on Windows. | Dictionary: String -> String | optional | {} |
allocator_library | Target that provides allocator functions when rust_library targets are embedded in a cc_binary. | String | optional | "@rules_rust//ffi/cc/allocator_library" |
dev_components | Whether to download the rustc-dev components (defaults to False). Requires version to be "nightly". | Boolean | optional | False |
edition | The rust edition to be used by default (2015, 2018, or 2021). If absent, every rule is required to specify its edition attribute. | String | optional | "" |
extra_exec_rustc_flags | Extra flags to pass to rustc in exec configuration | List of strings | optional | [] |
extra_rustc_flags | Extra flags to pass to rustc in non-exec configuration | List of strings | optional | [] |
extra_rustc_flags_triples | Extra flags to pass to rustc in non-exec configuration. Key is the triple, value is the flag. | Dictionary: String -> List of strings | optional | {} |
extra_target_triples | - | List of strings | optional | ["wasm32-unknown-unknown", "wasm32-wasip1"] |
rust_analyzer_version | The version of Rustc to pair with rust-analyzer. | String | optional | "" |
rustfmt_version | The version of the tool among "nightly", "beta", or an exact version. | String | optional | "nightly/2025-03-18" |
sha256s | A dict associating tool subdirectories to sha256 hashes. See rust_repositories for more details. | Dictionary: String -> String | optional | {} |
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 | ["https://static.rust-lang.org/dist/{}.tar.xz"] |
versions | A list of toolchain versions to download. This parameter only accepts one version per channel. E.g. ["1.65.0", "nightly/2022-11-02", "beta/2020-12-30"] . May be set to an empty list ([] ) to inhibit rules_rust from registering toolchains. | List of strings | optional | ["1.85.1", "nightly/2025-03-18"] |
rust_host_tools
rust_host_tools = use_extension("@rules_rust//rust:extensions.bzl", "rust_host_tools") rust_host_tools.host_tools(name, allocator_library, dev_components, edition, rustfmt_version, sha256s, urls, version)
An extension which exposes Rust tools compatible with the current host platform.
TAG CLASSES
host_tools
Attributes
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | The name of the module to create | Name | optional | "rust_host_tools" |
allocator_library | Target that provides allocator functions when rust_library targets are embedded in a cc_binary. | String | optional | "@rules_rust//ffi/cc/allocator_library" |
dev_components | Whether to download the rustc-dev components (defaults to False). Requires version to be "nightly". | Boolean | optional | False |
edition | The rust edition to be used by default (2015, 2018, or 2021). If absent, every rule is required to specify its edition attribute. | String | optional | "" |
rustfmt_version | The version of the tool among "nightly", "beta", or an exact version. | String | optional | "nightly/2025-03-18" |
sha256s | A dict associating tool subdirectories to sha256 hashes. See rust_repositories for more details. | Dictionary: String -> String | optional | {} |
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 | ["https://static.rust-lang.org/dist/{}.tar.xz"] |
version | The version of Rust to use for tools executed on the Bazel host. | String | optional | "1.85.1" |