From e4b87f3c910be43f9322dd7cda3d359a1012f6c9 Mon Sep 17 00:00:00 2001 From: Daniel Wagner-Hall Date: Sun, 15 Dec 2024 22:15:21 +0000 Subject: [PATCH] Fill in TODOs --- rust/repositories.bzl | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/rust/repositories.bzl b/rust/repositories.bzl index bd5a99ea29..c917e18102 100644 --- a/rust/repositories.bzl +++ b/rust/repositories.bzl @@ -314,7 +314,7 @@ def rust_register_toolchains( if extra_toolchain_infos: for name, info in extra_toolchain_infos.items(): toolchain_names.append(name) - toolchain_labels[name] = info["label"] + toolchain_labels[name] = info["tools_toolchain_label"] exec_compatible_with_by_toolchain[name] = info["exec_compatible_with"] target_compatible_with_by_toolchain[name] = info["target_compatible_with"] toolchain_target_settings[name] = info["target_settings"] @@ -641,7 +641,7 @@ def rust_toolchain_repository( auth_patterns (list, optional): A list of patterns to match against urls for which the auth object should be used. Returns: - str: The name of the registerable toolchain created by this rule. + dict[str, str]: Information about the name of the registerable toolchain created by this rule. """ if exec_compatible_with == None: exec_compatible_with = triple_to_constraint_set(exec_triple) @@ -673,18 +673,28 @@ def rust_toolchain_repository( channel_target_settings = ["@rules_rust//rust/toolchain/channel:{}".format(channel)] if channel else [] + tools_toolchain_label = "@{}//:rust_toolchain".format(tools_repo_name) + + toolchain_type = "@rules_rust//rust:toolchain" + toolchain_repository_proxy( name = name, - toolchain = "@{}//:rust_toolchain".format(tools_repo_name), + toolchain = tools_toolchain_label, target_settings = channel_target_settings + target_settings, - toolchain_type = "@rules_rust//rust:toolchain", + toolchain_type = toolchain_type, exec_compatible_with = exec_compatible_with, target_compatible_with = target_compatible_with, ) - return "@{name}//:toolchain".format( - name = name, - ) + return { + "exec_compatible_with": exec_compatible_with, + "name": name, + "target_compatible_with": target_compatible_with, + "target_settings": target_settings, + "toolchain_label": "@{name}//:toolchain".format(name = name), + "tools_toolchain_label": tools_toolchain_label, + "toolchain_type": toolchain_type, + } _RUST_ANALYZER_TOOLCHAIN_TOOLS_REPOSITORY_ATTRS = { "auth": attr.string_dict( @@ -1170,7 +1180,7 @@ def rust_repository_set( else: fail("extra_rustc_flags should be a list or a dict") - toolchain_label = rust_toolchain_repository( + toolchain_info = rust_toolchain_repository( name = toolchain.name, allocator_library = allocator_library, global_allocator_library = global_allocator_library, @@ -1193,20 +1203,8 @@ def rust_repository_set( exec_compatible_with = exec_compatible_with, target_compatible_with = toolchain.target_constraints, ) - toolchain_labels.append(toolchain_label) - all_toolchain_details[toolchain.name] = { - # TODO: Don't duplicate the defaulting here - "exec_compatible_with": exec_compatible_with or triple_to_constraint_set(exec_triple), - # "label": toolchain_label, - # TODO: Don't duplicate - "label": "@{}_tools//:rust_toolchain".format(toolchain.name), - "name": toolchain.name, - # TODO: Don't duplicate the defaulting here - "target_compatible_with": toolchain.target_constraints or triple_to_constraint_set(toolchain.target_triple), - "target_settings": target_settings, - # TODO: Don't duplicate - "toolchain_type": "@rules_rust//rust:toolchain", - } + toolchain_labels.append(toolchain_info["toolchain_label"]) + all_toolchain_details[toolchain.name] = toolchain_info # This repository exists to allow `rust_repository_set` to work with the `maybe` wrapper. rust_toolchain_set_repository(