From a52041fb56c6dcdd37142c81e90d083e860b8213 Mon Sep 17 00:00:00 2001 From: Matt Date: Fri, 13 Jan 2023 14:33:04 -0600 Subject: [PATCH] Support `target_settings` in `rust_repository_set` and `rust_toolchain_repository` (#1758) * support target_settings in rust_repository_set and rust_toolchain_repository * Regenerate documentation Co-authored-by: UebelAndre --- docs/flatten.md | 13 ++++++++----- docs/rust_repositories.md | 13 ++++++++----- rust/repositories.bzl | 9 ++++++++- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/docs/flatten.md b/docs/flatten.md index e67f867c7c..bd9568a3bf 100644 --- a/docs/flatten.md +++ b/docs/flatten.md @@ -1826,9 +1826,9 @@ rust_repositories(kwargs) ## rust_repository_set
-rust_repository_set(name, exec_triple, version, versions, include_rustc_srcs, allocator_library,
-                    extra_target_triples, iso_date, rustfmt_version, edition, dev_components, sha256s,
-                    urls, auth, register_toolchain)
+rust_repository_set(name, exec_triple, target_settings, version, versions, include_rustc_srcs,
+                    allocator_library, extra_target_triples, iso_date, rustfmt_version, edition,
+                    dev_components, sha256s, urls, auth, register_toolchain)
 
Assembles a remote repository for the given toolchain params, produces a proxy repository to contain the toolchain declaration, and registers the toolchains. @@ -1840,6 +1840,7 @@ Assembles a remote repository for the given toolchain params, produces a proxy r | :------------- | :------------- | :------------- | | name | The name of the generated repository | none | | exec_triple | The Rust-style target that this compiler runs on | none | +| target_settings | A list of config_settings that must be satisfied by the target configuration in order for this set of toolchains to be selected during toolchain resolution. | `[]` | | version | The version of the tool among "nightly", "beta', or an exact version. | `None` | | versions | A list of toolchain versions to download. This paramter only accepts one versions per channel. E.g. ["1.65.0", "nightly/2022-11-02", "beta/2020-12-30"]. | `[]` | | include_rustc_srcs | **Deprecated** - instead see [rust_analyzer_toolchain_repository](#rust_analyzer_toolchain_repository). | `False` | @@ -1925,8 +1926,9 @@ rust_test_suite(
 rust_toolchain_repository(name, version, exec_triple, target_triple, exec_compatible_with,
-                          target_compatible_with, channel, include_rustc_srcs, allocator_library,
-                          iso_date, rustfmt_version, edition, dev_components, sha256s, urls, auth)
+                          target_compatible_with, target_settings, channel, include_rustc_srcs,
+                          allocator_library, iso_date, rustfmt_version, edition, dev_components,
+                          sha256s, urls, auth)
 
Assembles a remote repository for the given toolchain params, produces a proxy repository to contain the toolchain declaration, and registers the toolchains. @@ -1942,6 +1944,7 @@ Assembles a remote repository for the given toolchain params, produces a proxy r | target_triple | The Rust-style target to build for. | none | | exec_compatible_with | A list of constraints for the execution platform for this toolchain. | `None` | | target_compatible_with | A list of constraints for the target platform for this toolchain. | `None` | +| target_settings | A list of config_settings that must be satisfied by the target configuration in order for this toolchain to be selected during toolchain resolution. | `[]` | | channel | The channel of the Rust toolchain. | `None` | | include_rustc_srcs | Whether to download rustc's src code. This is required in order to use rust-analyzer support. | `False` | | allocator_library | Target that provides allocator functions when rust_library targets are embedded in a cc_binary. | `None` | diff --git a/docs/rust_repositories.md b/docs/rust_repositories.md index 3ba4136ce5..24bc5dc7f7 100644 --- a/docs/rust_repositories.md +++ b/docs/rust_repositories.md @@ -291,9 +291,9 @@ rust_repositories(kwargs) ## rust_repository_set
-rust_repository_set(name, exec_triple, version, versions, include_rustc_srcs, allocator_library,
-                    extra_target_triples, iso_date, rustfmt_version, edition, dev_components, sha256s,
-                    urls, auth, register_toolchain)
+rust_repository_set(name, exec_triple, target_settings, version, versions, include_rustc_srcs,
+                    allocator_library, extra_target_triples, iso_date, rustfmt_version, edition,
+                    dev_components, sha256s, urls, auth, register_toolchain)
 
Assembles a remote repository for the given toolchain params, produces a proxy repository to contain the toolchain declaration, and registers the toolchains. @@ -305,6 +305,7 @@ Assembles a remote repository for the given toolchain params, produces a proxy r | :------------- | :------------- | :------------- | | name | The name of the generated repository | none | | exec_triple | The Rust-style target that this compiler runs on | none | +| target_settings | A list of config_settings that must be satisfied by the target configuration in order for this set of toolchains to be selected during toolchain resolution. | `[]` | | version | The version of the tool among "nightly", "beta', or an exact version. | `None` | | versions | A list of toolchain versions to download. This paramter only accepts one versions per channel. E.g. ["1.65.0", "nightly/2022-11-02", "beta/2020-12-30"]. | `[]` | | include_rustc_srcs | **Deprecated** - instead see [rust_analyzer_toolchain_repository](#rust_analyzer_toolchain_repository). | `False` | @@ -326,8 +327,9 @@ Assembles a remote repository for the given toolchain params, produces a proxy r
 rust_toolchain_repository(name, version, exec_triple, target_triple, exec_compatible_with,
-                          target_compatible_with, channel, include_rustc_srcs, allocator_library,
-                          iso_date, rustfmt_version, edition, dev_components, sha256s, urls, auth)
+                          target_compatible_with, target_settings, channel, include_rustc_srcs,
+                          allocator_library, iso_date, rustfmt_version, edition, dev_components,
+                          sha256s, urls, auth)
 
Assembles a remote repository for the given toolchain params, produces a proxy repository to contain the toolchain declaration, and registers the toolchains. @@ -343,6 +345,7 @@ Assembles a remote repository for the given toolchain params, produces a proxy r | target_triple | The Rust-style target to build for. | none | | exec_compatible_with | A list of constraints for the execution platform for this toolchain. | `None` | | target_compatible_with | A list of constraints for the target platform for this toolchain. | `None` | +| target_settings | A list of config_settings that must be satisfied by the target configuration in order for this toolchain to be selected during toolchain resolution. | `[]` | | channel | The channel of the Rust toolchain. | `None` | | include_rustc_srcs | Whether to download rustc's src code. This is required in order to use rust-analyzer support. | `False` | | allocator_library | Target that provides allocator functions when rust_library targets are embedded in a cc_binary. | `None` | diff --git a/rust/repositories.bzl b/rust/repositories.bzl index 73006c6374..72b2edc312 100644 --- a/rust/repositories.bzl +++ b/rust/repositories.bzl @@ -446,6 +446,7 @@ def rust_toolchain_repository( target_triple, exec_compatible_with = None, target_compatible_with = None, + target_settings = [], channel = None, include_rustc_srcs = False, allocator_library = None, @@ -467,6 +468,7 @@ def rust_toolchain_repository( channel (str, optional): The channel of the Rust toolchain. exec_compatible_with (list, optional): A list of constraints for the execution platform for this toolchain. target_compatible_with (list, optional): A list of constraints for the target platform for this toolchain. + target_settings (list, optional): A list of config_settings that must be satisfied by the target configuration in order for this toolchain to be selected during toolchain resolution. include_rustc_srcs (bool, optional): Whether to download rustc's src code. This is required in order to use rust-analyzer support. allocator_library (str, optional): Target that provides allocator functions when rust_library targets are embedded in a cc_binary. iso_date (str, optional): The date of the tool. @@ -514,10 +516,12 @@ def rust_toolchain_repository( auth = auth, ) + channel_target_settings = ["@rules_rust//rust/toolchain/channel:{}".format(channel)] if channel else [] + toolchain_repository_proxy( name = name, toolchain = "@{}//:rust_toolchain".format(tools_repo_name), - target_settings = ["@rules_rust//rust/toolchain/channel:{}".format(channel)] if channel else None, + target_settings = channel_target_settings + target_settings, toolchain_type = "@rules_rust//rust:toolchain", exec_compatible_with = exec_compatible_with, target_compatible_with = target_compatible_with, @@ -774,6 +778,7 @@ rust_toolchain_set_repository = repository_rule( def rust_repository_set( name, exec_triple, + target_settings = [], version = None, versions = [], include_rustc_srcs = False, @@ -793,6 +798,7 @@ def rust_repository_set( Args: name (str): The name of the generated repository exec_triple (str): The Rust-style target that this compiler runs on + target_settings (list, optional): A list of config_settings that must be satisfied by the target configuration in order for this set of toolchains to be selected during toolchain resolution. version (str): The version of the tool among "nightly", "beta', or an exact version. versions (list, optional): A list of toolchain versions to download. This paramter only accepts one versions per channel. E.g. `["1.65.0", "nightly/2022-11-02", "beta/2020-12-30"]`. @@ -871,6 +877,7 @@ def rust_repository_set( dev_components = dev_components, edition = edition, exec_triple = exec_triple, + target_settings = target_settings, include_rustc_srcs = include_rustc_srcs, iso_date = info.iso_date, rustfmt_version = rustfmt_version,