From 78bc3cd0364f432b08d49c047c823f302f80aa24 Mon Sep 17 00:00:00 2001 From: Thulio Ferraz Assis <3149049+f0rmiga@users.noreply.github.com> Date: Mon, 29 Apr 2024 11:36:45 -0700 Subject: [PATCH] feat: add target_settings so we can do config transitions (#173) --- docs/defs.md | 3 ++- toolchain/defs.bzl | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/docs/defs.md b/docs/defs.md index 36c3d6e..98eb30f 100644 --- a/docs/defs.md +++ b/docs/defs.md @@ -10,7 +10,7 @@ This module provides the definitions for registering a GCC toolchain for C and C
 gcc_toolchain(name, binary_prefix, extra_cflags, extra_cxxflags, extra_fflags, extra_ldflags,
               gcc_toolchain_workspace_name, includes, repo_mapping, sysroot, target_arch,
-              target_compatible_with, toolchain_files_repository_name)
+              target_compatible_with, target_settings, toolchain_files_repository_name)
 
@@ -32,6 +32,7 @@ gcc_toolchain(name, sysroot | A sysroot to be used as the logical build root. | String | required | | | target_arch | The target architecture this toolchain produces. E.g. x86_64. | String | required | | | target_compatible_with | contraint_values passed to target_compatible_with of the toolchain. {target_arch} is rendered to the target_arch attribute value. | List of strings | optional | ["@platforms//os:linux", "@platforms//cpu:{target_arch}"] | +| target_settings | config_settings passed to target_compatible_with of the toolchain. {target_arch} is rendered to the target_arch attribute value. | List of strings | optional | [] | | toolchain_files_repository_name | The name of the repository containing the toolchain files. | String | required | | diff --git a/toolchain/defs.bzl b/toolchain/defs.bzl index 46d1fb0..9df306b 100644 --- a/toolchain/defs.bzl +++ b/toolchain/defs.bzl @@ -55,9 +55,15 @@ def _gcc_toolchain_impl(rctx): for v in rctx.attr.target_compatible_with ] + target_settings = [ + v.format(target_arch = target_arch) + for v in rctx.attr.target_settings + ] + rctx.file("BUILD.bazel", _TOOLCHAIN_BUILD_FILE_CONTENT.format( gcc_toolchain_workspace_name = rctx.attr.gcc_toolchain_workspace_name, target_compatible_with = str(target_compatible_with), + target_settings = str(target_settings), toolchain_files_repository_name = rctx.attr.toolchain_files_repository_name, # Sysroot @@ -135,6 +141,11 @@ _FEATURE_ATTRS = { doc = "contraint_values passed to target_compatible_with of the toolchain. {target_arch} is rendered to the target_arch attribute value.", mandatory = False, ), + "target_settings": attr.string_list( + default = [], + doc = "config_settings passed to target_compatible_with of the toolchain. {target_arch} is rendered to the target_arch attribute value.", + mandatory = False, + ), "toolchain_files_repository_name": attr.string( doc = "The name of the repository containing the toolchain files.", mandatory = True, @@ -570,6 +581,7 @@ toolchain( "@platforms//cpu:x86_64", ], target_compatible_with = {target_compatible_with}, + target_settings = {target_settings}, toolchain = ":_cc_toolchain", toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", )