diff --git a/cc/toolchains/impl/toolchain_config.bzl b/cc/toolchains/impl/toolchain_config.bzl index 1f6efefe5..1a7c916bc 100644 --- a/cc/toolchains/impl/toolchain_config.bzl +++ b/cc/toolchains/impl/toolchain_config.bzl @@ -84,8 +84,8 @@ def _cc_toolchain_config_impl(ctx): # compiler compiler = ctx.attr.compiler, target_cpu = ctx.attr.cpu, + target_system_name = ctx.expand_make_variables("target_system_name", ctx.attr.target_system_name, {}), # These fields are only relevant for legacy toolchain resolution. - target_system_name = "", target_libc = "", abi_version = "", abi_libc_version = "", @@ -105,6 +105,7 @@ cc_toolchain_config = rule( # Attributes new to this rule. "compiler": attr.string(default = ""), "cpu": attr.string(default = ""), + "target_system_name": attr.string(default = ""), "tool_map": attr.label(providers = [ToolConfigInfo], mandatory = True), "args": attr.label_list(providers = [ArgsListInfo]), "known_features": attr.label_list(providers = [FeatureSetInfo]), diff --git a/cc/toolchains/toolchain.bzl b/cc/toolchains/toolchain.bzl index fa41163ab..b804b7e33 100644 --- a/cc/toolchains/toolchain.bzl +++ b/cc/toolchains/toolchain.bzl @@ -70,6 +70,7 @@ def cc_toolchain( supports_header_parsing = False, supports_param_files = False, compiler = "", + target_system_name = None, **kwargs): """A C/C++ toolchain configuration. @@ -158,6 +159,10 @@ def cc_toolchain( compiler: (str) The type of compiler used by this toolchain (e.g. "gcc", "clang"). The current toolchain's compiler is exposed to `@rules_cc//cc/private/toolchain:compiler (compiler_flag)` as a flag value. + target_system_name: (str) The target system name for this toolchain. This is exposed through the + toolchain info providers. This string is commonly the target triple you would pass to + `clang -target` (e.g. "x86_64-unknown-linux-gnu", "aarch64-apple-darwin"). If not + provided, a default is selected based on the target platform.. **kwargs: [common attributes](https://bazel.build/reference/be/common-definitions#common-attributes) that should be applied to all rules created by this macro. """ @@ -177,6 +182,15 @@ def cc_toolchain( known_features = known_features, enabled_features = enabled_features, compiler = compiler, + target_system_name = target_system_name or select({ + Label("//cc/toolchains/impl:darwin_aarch64"): "aarch64-apple-darwin", + Label("//cc/toolchains/impl:darwin_x86_64"): "x86_64-apple-darwin", + Label("//cc/toolchains/impl:linux_aarch64"): "aarch64-unknown-linux-gnu", + Label("//cc/toolchains/impl:linux_x86_64"): "x86_64-unknown-linux-gnu", + Label("//cc/toolchains/impl:windows_x86_32"): "i686-pc-windows-msvc", + Label("//cc/toolchains/impl:windows_x86_64"): "x86_64-pc-windows-msvc", + "//conditions:default": "", + }), cpu = select({ Label("//cc/toolchains/impl:darwin_aarch64"): "darwin_arm64", Label("//cc/toolchains/impl:darwin_x86_64"): "darwin_x86_64",