@@ -43,14 +43,18 @@ load_arbitrary_tool = _load_arbitrary_tool
4343# Note: Code in `.github/workflows/crate_universe.yaml` looks for this line, if you remove it or change its format, you will also need to update that code.
4444DEFAULT_TOOLCHAIN_TRIPLES = {
4545 "aarch64-apple-darwin" : "rust_macos_aarch64" ,
46+ # "aarch64-pc-windows-gnu": "rust_windows_aarch64_gnu",
4647 "aarch64-pc-windows-msvc" : "rust_windows_aarch64" ,
4748 "aarch64-unknown-linux-gnu" : "rust_linux_aarch64" ,
49+ # "aarch64-unknown-linux-musl": "rust_linux_aarch64_gnu",
4850 "powerpc64le-unknown-linux-gnu" : "rust_linux_powerpc64le" ,
4951 "s390x-unknown-linux-gnu" : "rust_linux_s390x" ,
5052 "x86_64-apple-darwin" : "rust_macos_x86_64" ,
53+ # "x86_64-pc-windows-gnu": "rust_windows_x86_64_gnu",
5154 "x86_64-pc-windows-msvc" : "rust_windows_x86_64" ,
5255 "x86_64-unknown-freebsd" : "rust_freebsd_x86_64" ,
5356 "x86_64-unknown-linux-gnu" : "rust_linux_x86_64" ,
57+ # "x86_64-unknown-linux-musl": "rust_linux_x86_64_musl",
5458}
5559
5660_COMPACT_WINDOWS_NAMES = True
@@ -234,6 +238,7 @@ def rust_register_toolchains(
234238 toolchain_names = []
235239 toolchain_labels = {}
236240 toolchain_target_settings = {}
241+ toolchain_target_settings_select = {}
237242 toolchain_types = {}
238243 exec_compatible_with_by_toolchain = {}
239244 target_compatible_with_by_toolchain = {}
@@ -295,6 +300,7 @@ def rust_register_toolchains(
295300 target_compatible_with_by_toolchain [toolchain .name ] = toolchain .target_constraints
296301 toolchain_types [toolchain .name ] = "@rules_rust//rust:toolchain"
297302 toolchain_target_settings [toolchain .name ] = ["@rules_rust//rust/toolchain/channel:{}" .format (toolchain .channel .name )] + target_settings
303+ toolchain_target_settings_select [toolchain .name ] = _get_abi_target_settings_select (toolchain .target_triple )
298304
299305 for exec_triple , name in rustfmt_toolchain_triples .items ():
300306 rustfmt_repo_name = "rustfmt_{}__{}" .format (rustfmt_version .replace ("/" , "-" ), exec_triple )
@@ -319,6 +325,7 @@ def rust_register_toolchains(
319325 toolchain_labels [rustfmt_repo_name ] = "@{}_tools//:rustfmt_toolchain" .format (rustfmt_repo_name )
320326 exec_compatible_with_by_toolchain [rustfmt_repo_name ] = triple_to_constraint_set (exec_triple )
321327 target_compatible_with_by_toolchain [rustfmt_repo_name ] = []
328+ toolchain_target_settings_select [rustfmt_repo_name ] = {}
322329 toolchain_types [rustfmt_repo_name ] = "@rules_rust//rust/rustfmt:toolchain_type"
323330
324331 if aliases :
@@ -332,6 +339,7 @@ def rust_register_toolchains(
332339 exec_compatible_with_by_toolchain [name ] = info ["exec_compatible_with" ]
333340 target_compatible_with_by_toolchain [name ] = info ["target_compatible_with" ]
334341 toolchain_target_settings [name ] = info ["target_settings" ]
342+ toolchain_target_settings_select [name ] = info ["target_settings_select" ]
335343 toolchain_types [name ] = info ["toolchain_type" ]
336344
337345 toolchain_repository_hub (
@@ -340,6 +348,7 @@ def rust_register_toolchains(
340348 toolchain_labels = toolchain_labels ,
341349 toolchain_types = toolchain_types ,
342350 target_settings = toolchain_target_settings ,
351+ target_settings_select = json .encode (toolchain_target_settings_select ),
343352 exec_compatible_with = exec_compatible_with_by_toolchain ,
344353 target_compatible_with = target_compatible_with_by_toolchain ,
345354 )
@@ -590,6 +599,7 @@ def _toolchain_repository_proxy_impl(repository_ctx):
590599 name = "toolchain" ,
591600 toolchain = repository_ctx .attr .toolchain ,
592601 target_settings = repository_ctx .attr .target_settings ,
602+ target_settings_select = repository_ctx .attr .target_settings_select ,
593603 toolchain_type = repository_ctx .attr .toolchain_type ,
594604 target_compatible_with = repository_ctx .attr .target_compatible_with ,
595605 exec_compatible_with = repository_ctx .attr .exec_compatible_with ,
@@ -610,6 +620,9 @@ toolchain_repository_proxy = repository_rule(
610620 "target_settings" : attr .string_list (
611621 doc = "A list of config_settings that must be satisfied by the target configuration in order for this toolchain to be selected during toolchain resolution." ,
612622 ),
623+ "target_settings_select" : attr .string_list_dict (
624+ doc = "A dictionary mapping config_setting labels to lists of additional target_settings, used to generate a select() statement. If empty, no select() is generated." ,
625+ ),
613626 "toolchain" : attr .string (
614627 doc = "The name of the toolchain implementation target." ,
615628 mandatory = True ,
@@ -625,6 +638,42 @@ toolchain_repository_proxy = repository_rule(
625638# For legacy support
626639rust_toolchain_repository_proxy = toolchain_repository_proxy
627640
641+ def _get_abi_target_settings_select (target_triple ):
642+ """Returns the ABI-specific config_settings for use in a select() statement.
643+
644+ Args:
645+ target_triple (str): The target triple to check
646+
647+ Returns:
648+ dict: A dictionary mapping config_setting labels to lists of target_settings,
649+ for use in a select() statement. Empty dict if no ABI-specific settings apply.
650+ """
651+ triple_struct = triple (target_triple )
652+
653+ # Check for linux + musl combination
654+ if triple_struct .system == "linux" :
655+ return {
656+ "@rules_rust//rust/settings:experimental_use_platform_abi_settings_enabled" : [
657+ "@rules_rust//rust/settings:platform_linux_musl_{}" .format (
658+ "enabled" if triple_struct .abi == "musl" else "disabled" ,
659+ ),
660+ ],
661+ "//conditions:default" : [],
662+ }
663+
664+ # Check for windows + gnu combination
665+ if triple_struct .system == "windows" :
666+ return {
667+ "@rules_rust//rust/settings:experimental_use_platform_abi_settings_enabled" : [
668+ "@rules_rust//rust/settings:platform_windows_gnu_{}" .format (
669+ "enabled" if triple_struct .abi == "gnu" else "disabled" ,
670+ ),
671+ ],
672+ "//conditions:default" : [],
673+ }
674+
675+ return {}
676+
628677# N.B. A "proxy repository" is needed to allow for registering the toolchain (with constraints)
629678# without actually downloading the toolchain.
630679def rust_toolchain_repository (
@@ -718,6 +767,7 @@ def rust_toolchain_repository(
718767 )
719768
720769 channel_target_settings = ["@rules_rust//rust/toolchain/channel:{}" .format (channel )] if channel else []
770+ abi_target_settings_select = _get_abi_target_settings_select (target_triple )
721771
722772 tools_toolchain_label = "@{}//:rust_toolchain" .format (tools_repo_name )
723773
@@ -727,6 +777,7 @@ def rust_toolchain_repository(
727777 name = name ,
728778 toolchain = tools_toolchain_label ,
729779 target_settings = channel_target_settings + target_settings ,
780+ target_settings_select = abi_target_settings_select ,
730781 toolchain_type = toolchain_type ,
731782 exec_compatible_with = exec_compatible_with ,
732783 target_compatible_with = target_compatible_with ,
@@ -736,7 +787,8 @@ def rust_toolchain_repository(
736787 "exec_compatible_with" : exec_compatible_with ,
737788 "name" : name ,
738789 "target_compatible_with" : target_compatible_with ,
739- "target_settings" : target_settings ,
790+ "target_settings" : channel_target_settings + target_settings ,
791+ "target_settings_select" : abi_target_settings_select ,
740792 "toolchain_label" : "@{name}//:toolchain" .format (name = name ),
741793 "toolchain_type" : toolchain_type ,
742794 "tools_toolchain_label" : tools_toolchain_label ,
0 commit comments