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

NameDescriptionTypeMandatoryDefault
nameName of the repository_set - if you're looking to replace default toolchains you must use the exact name you're replacing.Nameoptional""
allocator_libraryTarget that provides allocator functions when rust_library targets are embedded in a cc_binary.Stringoptional"@rules_rust//ffi/cc/allocator_library"
dev_componentsWhether to download the rustc-dev components (defaults to False). Requires version to be "nightly".BooleanoptionalFalse
editionThe rust edition to be used by default (2015, 2018, or 2021). If absent, every rule is required to specify its edition attribute.Stringoptional""
exec_tripleExec triple for this repository_set.Stringoptional""
rustfmt_versionThe version of the tool among "nightly", "beta", or an exact version.Stringoptional"nightly/2025-03-18"
sha256sA dict associating tool subdirectories to sha256 hashes. See rust_repositories for more details.Dictionary: String -> Stringoptional{}
target_compatible_withList of platform constraints this toolchain produces, for the particular target_triple this call is for.List of labelsoptional[]
target_tripletarget_triple to configure.Stringoptional""
urlsA 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 stringsoptional["https://static.rust-lang.org/dist/{}.tar.xz"]
versionsA 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 stringsoptional[]

toolchain

Tags for defining rust toolchains (where toolchain tools are fetched).

Attributes

NameDescriptionTypeMandatoryDefault
aliasesMap 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 -> Stringoptional{}
allocator_libraryTarget that provides allocator functions when rust_library targets are embedded in a cc_binary.Stringoptional"@rules_rust//ffi/cc/allocator_library"
dev_componentsWhether to download the rustc-dev components (defaults to False). Requires version to be "nightly".BooleanoptionalFalse
editionThe rust edition to be used by default (2015, 2018, or 2021). If absent, every rule is required to specify its edition attribute.Stringoptional""
extra_exec_rustc_flagsExtra flags to pass to rustc in exec configurationList of stringsoptional[]
extra_rustc_flagsExtra flags to pass to rustc in non-exec configurationList of stringsoptional[]
extra_rustc_flags_triplesExtra flags to pass to rustc in non-exec configuration. Key is the triple, value is the flag.Dictionary: String -> List of stringsoptional{}
extra_target_triples-List of stringsoptional["wasm32-unknown-unknown", "wasm32-wasip1"]
rust_analyzer_versionThe version of Rustc to pair with rust-analyzer.Stringoptional""
rustfmt_versionThe version of the tool among "nightly", "beta", or an exact version.Stringoptional"nightly/2025-03-18"
sha256sA dict associating tool subdirectories to sha256 hashes. See rust_repositories for more details.Dictionary: String -> Stringoptional{}
urlsA 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 stringsoptional["https://static.rust-lang.org/dist/{}.tar.xz"]
versionsA 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 stringsoptional["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

NameDescriptionTypeMandatoryDefault
nameThe name of the module to createNameoptional"rust_host_tools"
allocator_libraryTarget that provides allocator functions when rust_library targets are embedded in a cc_binary.Stringoptional"@rules_rust//ffi/cc/allocator_library"
dev_componentsWhether to download the rustc-dev components (defaults to False). Requires version to be "nightly".BooleanoptionalFalse
editionThe rust edition to be used by default (2015, 2018, or 2021). If absent, every rule is required to specify its edition attribute.Stringoptional""
rustfmt_versionThe version of the tool among "nightly", "beta", or an exact version.Stringoptional"nightly/2025-03-18"
sha256sA dict associating tool subdirectories to sha256 hashes. See rust_repositories for more details.Dictionary: String -> Stringoptional{}
urlsA 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 stringsoptional["https://static.rust-lang.org/dist/{}.tar.xz"]
versionThe version of Rust to use for tools executed on the Bazel host.Stringoptional"1.85.1"