diff options
-rw-r--r-- | docs/flatten.md | 2 | ||||
-rw-r--r-- | docs/rust_repositories.md | 2 | ||||
-rw-r--r-- | rust/repositories.bzl | 10 |
3 files changed, 10 insertions, 4 deletions
diff --git a/docs/flatten.md b/docs/flatten.md index 3d3210a4..5a27be78 100644 --- a/docs/flatten.md +++ b/docs/flatten.md @@ -1963,7 +1963,7 @@ See `load_arbitrary_tool` in `@rules_rust//rust:repositories.bzl` for more detai | <a id="rust_register_toolchains-global_allocator_library"></a>global_allocator_library | Target that provides allocator functions when global allocator is used with cc_common.link. | `None` | | <a id="rust_register_toolchains-iso_date"></a>iso_date | **Deprecated**: Use <code>versions</code> instead. | `None` | | <a id="rust_register_toolchains-register_toolchains"></a>register_toolchains | If true, repositories will be generated to produce and register <code>rust_toolchain</code> targets. | `True` | -| <a id="rust_register_toolchains-rustfmt_version"></a>rustfmt_version | The version of rustfmt. | `"nightly/2024-05-02"` | +| <a id="rust_register_toolchains-rustfmt_version"></a>rustfmt_version | The version of rustfmt. If none is supplied and only a single version in <code>versions</code> is given, then this defaults to that version, otherwise will default to the default nightly version. | `None` | | <a id="rust_register_toolchains-rust_analyzer_version"></a>rust_analyzer_version | The version of Rustc to pair with rust-analyzer. | `None` | | <a id="rust_register_toolchains-sha256s"></a>sha256s | A dict associating tool subdirectories to sha256 hashes. | `None` | | <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"]` | diff --git a/docs/rust_repositories.md b/docs/rust_repositories.md index 252d4b24..bc59cdb1 100644 --- a/docs/rust_repositories.md +++ b/docs/rust_repositories.md @@ -275,7 +275,7 @@ See `load_arbitrary_tool` in `@rules_rust//rust:repositories.bzl` for more detai | <a id="rust_register_toolchains-global_allocator_library"></a>global_allocator_library | Target that provides allocator functions when global allocator is used with cc_common.link. | `None` | | <a id="rust_register_toolchains-iso_date"></a>iso_date | **Deprecated**: Use <code>versions</code> instead. | `None` | | <a id="rust_register_toolchains-register_toolchains"></a>register_toolchains | If true, repositories will be generated to produce and register <code>rust_toolchain</code> targets. | `True` | -| <a id="rust_register_toolchains-rustfmt_version"></a>rustfmt_version | The version of rustfmt. | `"nightly/2024-05-02"` | +| <a id="rust_register_toolchains-rustfmt_version"></a>rustfmt_version | The version of rustfmt. If none is supplied and only a single version in <code>versions</code> is given, then this defaults to that version, otherwise will default to the default nightly version. | `None` | | <a id="rust_register_toolchains-rust_analyzer_version"></a>rust_analyzer_version | The version of Rustc to pair with rust-analyzer. | `None` | | <a id="rust_register_toolchains-sha256s"></a>sha256s | A dict associating tool subdirectories to sha256 hashes. | `None` | | <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"]` | diff --git a/rust/repositories.bzl b/rust/repositories.bzl index 59c8a8c8..9552e816 100644 --- a/rust/repositories.bzl +++ b/rust/repositories.bzl @@ -112,7 +112,7 @@ def rust_register_toolchains( global_allocator_library = None, iso_date = None, register_toolchains = True, - rustfmt_version = DEFAULT_NIGHTLY_VERSION, + rustfmt_version = None, rust_analyzer_version = None, sha256s = None, extra_target_triples = DEFAULT_EXTRA_TARGET_TRIPLES, @@ -146,7 +146,7 @@ def rust_register_toolchains( global_allocator_library (str, optional): Target that provides allocator functions when global allocator is used with cc_common.link. iso_date (str, optional): **Deprecated**: Use `versions` instead. register_toolchains (bool): If true, repositories will be generated to produce and register `rust_toolchain` targets. - rustfmt_version (str, optional): The version of rustfmt. + rustfmt_version (str, optional): The version of rustfmt. If none is supplied and only a single version in `versions` is given, then this defaults to that version, otherwise will default to the default nightly version. rust_analyzer_version (str, optional): The version of Rustc to pair with rust-analyzer. sha256s (str, optional): A dict associating tool subdirectories to sha256 hashes. extra_target_triples (list, optional): Additional rust-style targets that rust toolchains should support. @@ -176,6 +176,12 @@ def rust_register_toolchains( else: versions = _RUST_TOOLCHAIN_VERSIONS + if not rustfmt_version: + if len(versions) == 1: + rustfmt_version = versions[0] + else: + rustfmt_version = DEFAULT_NIGHTLY_VERSION + if dev_components: has_nightly = False for ver in versions: |