From b315eb39ed91ae0921c91ccd9a034dc7a90f541c Mon Sep 17 00:00:00 2001 From: Derek Cormier Date: Sat, 20 Jun 2026 21:19:07 -0700 Subject: [PATCH] feat: split toolchain type into execution and target types --- mylang/private/resolved_toolchain.bzl | 4 ++-- mylang/private/toolchains_repo.bzl | 9 ++++++++- mylang/toolchain/BUILD.bazel | 20 +++++++++++++------- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/mylang/private/resolved_toolchain.bzl b/mylang/private/resolved_toolchain.bzl index 5030e17..b037987 100644 --- a/mylang/private/resolved_toolchain.bzl +++ b/mylang/private/resolved_toolchain.bzl @@ -9,7 +9,7 @@ Workaround for https://github.com/bazelbuild/bazel/issues/14009 # Forward all the providers def _resolved_toolchain_impl(ctx): - toolchain_info = ctx.toolchains["//mylang:/toolchain/toolchain_type"] + toolchain_info = ctx.toolchains["//mylang/toolchain:execution_type"] return [ toolchain_info, toolchain_info.default, @@ -21,6 +21,6 @@ def _resolved_toolchain_impl(ctx): # https://cs.opensource.google/bazel/bazel/+/master:tools/jdk/java_toolchain_alias.bzl resolved_toolchain = rule( implementation = _resolved_toolchain_impl, - toolchains = ["//mylang/toolchain:toolchain_type"], + toolchains = ["//mylang/toolchain:execution_type"], doc = DOC, ) diff --git a/mylang/private/toolchains_repo.bzl b/mylang/private/toolchains_repo.bzl index ca6f9cd..2311b12 100644 --- a/mylang/private/toolchains_repo.bzl +++ b/mylang/private/toolchains_repo.bzl @@ -63,7 +63,14 @@ toolchain( name = "{platform}_toolchain", exec_compatible_with = {compatible_with}, toolchain = "@{user_repository_name}_{platform}//:mylang_toolchain", - toolchain_type = "@com_myorg_rules_mylang//mylang/toolchain:toolchain_type", + toolchain_type = "@com_myorg_rules_mylang//mylang/toolchain:execution_type", +) + +toolchain( + name = "{platform}_target_toolchain", + target_compatible_with = {compatible_with}, + toolchain = "@{user_repository_name}_{platform}//:mylang_toolchain", + toolchain_type = "@com_myorg_rules_mylang//mylang/toolchain:target_type", ) """.format( platform = platform, diff --git a/mylang/toolchain/BUILD.bazel b/mylang/toolchain/BUILD.bazel index badc414..d5e4fbc 100644 --- a/mylang/toolchain/BUILD.bazel +++ b/mylang/toolchain/BUILD.bazel @@ -1,7 +1,13 @@ -# This is the target rule authors should put in their "toolchains" -# attribute in order to get a runtime for the correct platform. -# See https://docs.bazel.build/versions/main/toolchains.html#writing-rules-that-use-toolchains -toolchain_type( - name = "toolchain_type", - visibility = ["//visibility:public"], -) +""" +These are the targets rule authors should put in their "toolchains" +attribute in order to get a runtime for the correct platform. +See https://docs.bazel.build/versions/main/toolchains.html +""" + +package(default_visibility = ["//visibility:public"]) + +# Resolve the mylang tool for the execution platform. +toolchain_type(name = "execution_type") + +# Less frequently needed: give a diff tool for the target platform. +toolchain_type(name = "target_type")