From d94c5eeda2dae9a2b39fbbd1f11852a8723bc49b Mon Sep 17 00:00:00 2001 From: Nikola Radakovic Date: Wed, 19 Aug 2026 15:57:23 +0200 Subject: [PATCH] Revert "Extract common toolchain features (#85) (#113)" This reverts commit 75330be32473069cff3881a1f79ad8ee156e9c6f. --- extensions/gcc.bzl | 2 - rules/gcc.bzl | 9 - .../cc_toolchain_shared_features.bzl.template | 452 ------------------ .../linux/cc_toolchain_config.bzl.template | 440 +++++++++++++++-- .../qnx/cc_toolchain_config.bzl.template | 437 +++++++++++++++-- tests/MODULE.bazel.lock | 12 +- 6 files changed, 816 insertions(+), 536 deletions(-) delete mode 100644 templates/cc_toolchain_shared_features.bzl.template diff --git a/extensions/gcc.bzl b/extensions/gcc.bzl index d86ee8a..ae8b330 100644 --- a/extensions/gcc.bzl +++ b/extensions/gcc.bzl @@ -205,7 +205,6 @@ def _get_toolchains(tags): toolchain = { "cc_toolchain_config": "@score_bazel_cpp_toolchains//templates/{}:cc_toolchain_config.bzl.template".format(tag.target_os), "cc_toolchain_flags": "@score_bazel_cpp_toolchains//templates/{}:cc_toolchain_flags.bzl.template".format(tag.target_os), - "cc_toolchain_shared_features": "@score_bazel_cpp_toolchains//templates:cc_toolchain_shared_features.bzl.template", "gcc_version": tag.version, "name": tag.name, "use_base_constraints_only": tag.use_base_constraints_only, @@ -418,7 +417,6 @@ def _impl(mctx): gcc_version = toolchain_info["gcc_version"], cc_toolchain_config = toolchain_info["cc_toolchain_config"], cc_toolchain_flags = toolchain_info["cc_toolchain_flags"], - cc_toolchain_shared_features = toolchain_info["cc_toolchain_shared_features"], use_base_constraints_only = toolchain_info["use_base_constraints_only"], ) diff --git a/rules/gcc.bzl b/rules/gcc.bzl index f128e12..1a9504b 100644 --- a/rules/gcc.bzl +++ b/rules/gcc.bzl @@ -282,12 +282,6 @@ def _impl(rctx): {}, ) - rctx.template( - "shared_features.bzl", - rctx.attr.cc_toolchain_shared_features, - {}, - ) - if rctx.attr.tc_os == _OS_LINUX: # There is an issue with gcov and cc_toolchain config. # See: https://github.com/bazelbuild/rules_cc/issues/351 @@ -329,9 +323,6 @@ gcc_toolchain = repository_rule( "cc_toolchain_flags": attr.label( doc = "Path to the Bazel BUILD file template for the toolchain.", ), - "cc_toolchain_shared_features": attr.label( - doc = "Path to the shared features template.", - ), "extra_c_compile_flags": attr.string_list(doc = "Extra/Additional C-specific compile flags."), "extra_compile_flags": attr.string_list(doc = "Extra/Additional compile flags."), "extra_cxx_compile_flags": attr.string_list(doc = "Extra/Additional C++-specific compile flags."), diff --git a/templates/cc_toolchain_shared_features.bzl.template b/templates/cc_toolchain_shared_features.bzl.template deleted file mode 100644 index c07477f..0000000 --- a/templates/cc_toolchain_shared_features.bzl.template +++ /dev/null @@ -1,452 +0,0 @@ -# ******************************************************************************* -# Copyright (c) 2026 Contributors to the Eclipse Foundation -# -# See the NOTICE file(s) distributed with this work for additional -# information regarding copyright ownership. -# -# This program and the accompanying materials are made available under the -# terms of the Apache License Version 2.0 which is available at -# https://www.apache.org/licenses/LICENSE-2.0 -# -# SPDX-License-Identifier: Apache-2.0 -# ******************************************************************************* - -"""Shared feature definitions common to both Linux and QNX GCC toolchains (Group S).""" - -load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") -load( - "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", - "feature", - "flag_group", - "flag_set", - "variable_with_value", -) - -all_cpp_compile_actions = [ - ACTION_NAMES.cpp_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.clif_match, - ACTION_NAMES.lto_backend, -] - -all_c_compile_actions = [ - ACTION_NAMES.c_compile, -] - -all_assemble_actions = [ - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, -] - -all_compile_actions = all_c_compile_actions + all_cpp_compile_actions + all_assemble_actions - -all_link_actions = [ - ACTION_NAMES.cpp_link_executable, - ACTION_NAMES.cpp_link_dynamic_library, - ACTION_NAMES.cpp_link_nodeps_dynamic_library, -] - -all_actions = all_compile_actions + all_link_actions + [ - ACTION_NAMES.strip, - ACTION_NAMES.cpp_link_static_library, -] - -def make_shared_features(unfiltered_compile_flags): - """Construct the Group S features shared to both Linux and QNX toolchains. - - These features have identical names, flag definitions, action lists, and - enabled state on both platforms. Callers are responsible for inserting the - returned features into their platform-specific features list in the correct - order. - - Args: - unfiltered_compile_flags: flag_group list for the unfiltered compile - flags, loaded from the platform-specific flags.bzl. - - Returns: - struct with one named field per Group S feature. - """ - no_legacy_features_feature = feature(name = "no_legacy_features", enabled = True) - - dbg_feature = feature(name = "dbg") - - opt_feature = feature(name = "opt") - - supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True) - - supports_pic_feature = feature(name = "supports_pic", enabled = True) - - unfiltered_compile_flags_feature = feature( - name = "unfiltered_compile_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_c_compile_actions + all_cpp_compile_actions, - flag_groups = unfiltered_compile_flags, - ), - ], - ) - - random_seed_feature = feature( - name = "random_seed", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_codegen, - ], - flag_groups = [ - flag_group( - expand_if_available = "output_file", - flags = ["-frandom-seed=%{output_file}"], - ), - ], - ), - ], - ) - - include_paths_feature = feature( - name = "include_paths", - enabled = True, - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = [ - flag_group( - iterate_over = "quote_include_paths", - flags = ["-iquote", "%{quote_include_paths}"], - expand_if_available = "quote_include_paths", - ), - ], - ), - flag_set( - actions = all_compile_actions, - flag_groups = [ - flag_group( - iterate_over = "include_paths", - flags = ["-I%{include_paths}"], - expand_if_available = "include_paths", - ), - ], - ), - flag_set( - actions = all_compile_actions, - flag_groups = [ - flag_group( - iterate_over = "system_include_paths", - flags = ["-isystem", "%{system_include_paths}"], - expand_if_available = "system_include_paths", - ), - ], - ), - ], - ) - - preprocessor_defines_feature = feature( - name = "preprocessor_defines", - enabled = True, - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = [ - flag_group( - iterate_over = "preprocessor_defines", - flags = ["-D%{preprocessor_defines}"], - expand_if_available = "preprocessor_defines", - ), - ], - ), - ], - ) - - user_compile_flags_feature = feature( - name = "user_compile_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = [ - flag_group( - iterate_over = "user_compile_flags", - flags = ["%{user_compile_flags}"], - expand_if_available = "user_compile_flags", - ), - ], - ), - ], - ) - - compiler_input_flags_feature = feature( - name = "compiler_input_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = [ - flag_group( - flags = ["-c", "%{source_file}"], - expand_if_available = "source_file", - ), - ], - ), - ], - ) - - compiler_output_flags_feature = feature( - name = "compiler_output_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = [ - flag_group( - flags = ["-S"], - expand_if_available = "output_assembly_file", - ), - flag_group( - flags = ["-E"], - expand_if_available = "output_preprocess_file", - ), - flag_group( - flags = ["-o", "%{output_file}"], - expand_if_available = "output_file", - ), - ], - ), - ], - ) - - pic_feature = feature( - name = "pic", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.cpp_module_compile, - ], - flag_groups = [ - flag_group(flags = ["-fPIC"], expand_if_available = "pic"), - ], - ), - ], - ) - - archiver_flags_feature = feature( - name = "archiver_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = [ACTION_NAMES.cpp_link_static_library], - flag_groups = [ - flag_group(flags = ["rcsD", "%{output_execpath}"]), - flag_group( - iterate_over = "libraries_to_link", - flag_groups = [ - flag_group( - flags = ["%{libraries_to_link.name}"], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "object_file", - ), - ), - flag_group( - flags = ["%{libraries_to_link.object_files}"], - iterate_over = "libraries_to_link.object_files", - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "object_file_group", - ), - ), - ], - expand_if_available = "libraries_to_link", - ), - flag_group( - iterate_over = "user_archiver_flags", - flags = ["%{user_archiver_flags}"], - expand_if_available = "user_archiver_flags", - ), - ], - ), - ], - ) - - user_link_flags_feature = feature( - name = "user_link_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [ - flag_group( - iterate_over = "user_link_flags", - flags = ["%{user_link_flags}"], - expand_if_available = "user_link_flags", - ), - ], - ), - ], - ) - - linker_param_file_feature = feature( - name = "linker_param_file", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions + [ACTION_NAMES.cpp_link_static_library], - flag_groups = [ - flag_group( - flags = ["@%{linker_param_file}"], - expand_if_available = "linker_param_file", - ), - ], - ), - ], - ) - - library_search_directories_feature = feature( - name = "library_search_directories", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [ - flag_group( - iterate_over = "library_search_directories", - flag_groups = [ - flag_group( - flags = ["-L%{library_search_directories}"], - ), - ], - expand_if_available = "library_search_directories", - ), - ], - ), - ], - ) - - shared_flag_feature = feature( - name = "shared_flag", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.cpp_link_dynamic_library, - ACTION_NAMES.cpp_link_nodeps_dynamic_library, - ], - flag_groups = [flag_group(flags = ["-shared"])], - ), - ], - ) - - output_execpath_flags_feature = feature( - name = "output_execpath_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [ - flag_group( - flags = ["-o", "%{output_execpath}"], - expand_if_available = "output_execpath", - ), - ], - ), - ], - ) - - libraries_to_link_feature = feature( - name = "libraries_to_link", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [ - flag_group( - iterate_over = "libraries_to_link", - flag_groups = [ - flag_group( - flags = ["-Wl,--whole-archive", "%{libraries_to_link.name}", "-Wl,--no-whole-archive"], - expand_if_true = "libraries_to_link.is_whole_archive", - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "static_library", - ), - ), - flag_group( - flags = ["%{libraries_to_link.name}"], - expand_if_false = "libraries_to_link.is_whole_archive", - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "static_library", - ), - ), - flag_group( - flags = ["%{libraries_to_link.name}"], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "object_file", - ), - ), - flag_group( - flags = ["%{libraries_to_link.object_files}"], - iterate_over = "libraries_to_link.object_files", - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "object_file_group", - ), - ), - flag_group( - flags = ["-l%{libraries_to_link.name}"], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "dynamic_library", - ), - ), - flag_group( - flags = ["-l:%{libraries_to_link.name}"], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "versioned_dynamic_library", - ), - ), - ], - expand_if_available = "libraries_to_link", - ), - ], - ), - ], - ) - - return struct( - no_legacy_features_feature = no_legacy_features_feature, - dbg_feature = dbg_feature, - opt_feature = opt_feature, - supports_dynamic_linker_feature = supports_dynamic_linker_feature, - supports_pic_feature = supports_pic_feature, - unfiltered_compile_flags_feature = unfiltered_compile_flags_feature, - random_seed_feature = random_seed_feature, - include_paths_feature = include_paths_feature, - preprocessor_defines_feature = preprocessor_defines_feature, - user_compile_flags_feature = user_compile_flags_feature, - compiler_input_flags_feature = compiler_input_flags_feature, - compiler_output_flags_feature = compiler_output_flags_feature, - pic_feature = pic_feature, - archiver_flags_feature = archiver_flags_feature, - user_link_flags_feature = user_link_flags_feature, - linker_param_file_feature = linker_param_file_feature, - library_search_directories_feature = library_search_directories_feature, - shared_flag_feature = shared_flag_feature, - output_execpath_flags_feature = output_execpath_flags_feature, - libraries_to_link_feature = libraries_to_link_feature, - ) diff --git a/templates/linux/cc_toolchain_config.bzl.template b/templates/linux/cc_toolchain_config.bzl.template index 8d28e81..f85312f 100644 --- a/templates/linux/cc_toolchain_config.bzl.template +++ b/templates/linux/cc_toolchain_config.bzl.template @@ -51,21 +51,48 @@ load(":flags.bzl", "WARNINGS_AS_ERRORS", ) -load(":shared_features.bzl", - "all_actions", - "all_assemble_actions", - "all_c_compile_actions", - "all_compile_actions", - "all_cpp_compile_actions", - "all_link_actions", - "make_shared_features", -) +all_cpp_compile_actions = [ + ACTION_NAMES.cpp_compile, + ACTION_NAMES.linkstamp_compile, + ACTION_NAMES.cpp_header_parsing, + ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.clif_match, + ACTION_NAMES.lto_backend, +] + +all_c_compile_actions = [ + ACTION_NAMES.c_compile, +] + +all_assemble_actions = [ + ACTION_NAMES.assemble, + ACTION_NAMES.preprocess_assemble, +] + +all_compile_actions = all_c_compile_actions + all_cpp_compile_actions + all_assemble_actions + +all_link_actions = [ + ACTION_NAMES.cpp_link_executable, + ACTION_NAMES.cpp_link_dynamic_library, + ACTION_NAMES.cpp_link_nodeps_dynamic_library, +] + +all_actions = all_compile_actions + all_link_actions + [ + ACTION_NAMES.strip, + ACTION_NAMES.cpp_link_static_library, +] def _impl(ctx): + dbg_feature = feature(name = "dbg") + opt_feature = feature(name = "opt") + + no_legacy_features_feature = feature(name = "no_legacy_features", enabled = True) # Temp solution until we do not add feature injection gnu11_feature = feature(name = "gnu11") + supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True) supports_fission_feature = feature(name = "supports_fission", enabled = True) assemble_action = action_config( @@ -140,8 +167,6 @@ def _impl(ctx): strip_action, ] - shared = make_shared_features(UNFILTERED_COMPILE_FLAGS) - # Set LD_LIBRARY_PATH environment variable for all actions # This is needed by some toolchains since these libraries are not in `rpath` of compiler binary # which are needed to run it. @@ -157,6 +182,17 @@ def _impl(ctx): ], ) + unfiltered_compile_flags_feature = feature( + name = "unfiltered_compile_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = all_c_compile_actions + all_cpp_compile_actions, + flag_groups = UNFILTERED_COMPILE_FLAGS + ), + ], + ) + target_cpu_flags = [] if ctx.attr.target_cpu == "x86_64": target_cpu_flags = DEFAULT_x86_64_COMPILE_FLAGS @@ -390,6 +426,136 @@ def _impl(ctx): ], ) + supports_pic_feature = feature(name = "supports_pic", enabled = True) + + pic_feature = feature( + name = "pic", + enabled = True, + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.assemble, + ACTION_NAMES.preprocess_assemble, + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.cpp_module_compile, + ], + flag_groups = [ + flag_group(flags = ["-fPIC"], expand_if_available = "pic"), + ], + ), + ], + ) + + user_compile_flags_feature = feature( + name = "user_compile_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = all_compile_actions, + flag_groups = [ + flag_group( + iterate_over = "user_compile_flags", + flags = ["%{user_compile_flags}"], + expand_if_available = "user_compile_flags", + ), + ], + ), + ], + ) + + random_seed_feature = feature( + name = "random_seed", + enabled = True, + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.cpp_module_codegen, + ], + flag_groups = [ + flag_group( + expand_if_available = "output_file", + flags = ["-frandom-seed=%{output_file}"], + ), + ], + ), + ], + ) + + include_paths_feature = feature( + name = "include_paths", + enabled = True, + flag_sets = [ + flag_set( + actions = all_compile_actions, + flag_groups = [ + flag_group( + iterate_over = "quote_include_paths", + flags = ["-iquote", "%{quote_include_paths}"], + expand_if_available = "quote_include_paths", + ), + ], + ), + flag_set( + actions = all_compile_actions, + flag_groups = [ + flag_group( + iterate_over = "include_paths", + flags = ["-I%{include_paths}"], + expand_if_available = "include_paths", + ), + ], + ), + flag_set( + actions = all_compile_actions, + flag_groups = [ + flag_group( + iterate_over = "system_include_paths", + flags = ["-isystem", "%{system_include_paths}"], + expand_if_available = "system_include_paths", + ), + ], + ), + ], + ) + + preprocessor_defines_feature = feature( + name = "preprocessor_defines", + enabled = True, + flag_sets = [ + flag_set( + actions = all_compile_actions, + flag_groups = [ + flag_group( + iterate_over = "preprocessor_defines", + flags = ["-D%{preprocessor_defines}"], + expand_if_available = "preprocessor_defines", + ), + ], + ), + ], + ) + + compiler_input_flags_feature = feature( + name = "compiler_input_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = all_compile_actions, + flag_groups = [ + flag_group( + flags = ["-c", "%{source_file}"], + expand_if_available = "source_file", + ), + ], + ), + ], + ) + dependency_file_feature = feature( name = "dependency_file", enabled = True, @@ -416,6 +582,136 @@ def _impl(ctx): ], ) + compiler_output_flags_feature = feature( + name = "compiler_output_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = all_compile_actions, + flag_groups = [ + flag_group( + flags = ["-S"], + expand_if_available = "output_assembly_file", + ), + flag_group( + flags = ["-E"], + expand_if_available = "output_preprocess_file", + ), + flag_group( + flags = ["-o", "%{output_file}"], + expand_if_available = "output_file", + ), + ], + ), + ], + ) + + archiver_flags_feature = feature( + name = "archiver_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = [ACTION_NAMES.cpp_link_static_library], + flag_groups = [ + flag_group(flags = ["rcsD", "%{output_execpath}"]), + flag_group( + iterate_over = "libraries_to_link", + flag_groups = [ + flag_group( + flags = ["%{libraries_to_link.name}"], + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "object_file", + ), + ), + flag_group( + flags = ["%{libraries_to_link.object_files}"], + iterate_over = "libraries_to_link.object_files", + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "object_file_group", + ), + ), + ], + expand_if_available = "libraries_to_link", + ), + flag_group( + iterate_over = "user_archiver_flags", + flags = ["%{user_archiver_flags}"], + expand_if_available = "user_archiver_flags", + ), + ], + ), + ], + ) + + linker_param_file_feature = feature( + name = "linker_param_file", + enabled = True, + flag_sets = [ + flag_set( + actions = all_link_actions + [ACTION_NAMES.cpp_link_static_library], + flag_groups = [ + flag_group( + flags = ["@%{linker_param_file}"], + expand_if_available = "linker_param_file", + ), + ], + ), + ], + ) + + library_search_directories_feature = feature( + name = "library_search_directories", + enabled = True, + flag_sets = [ + flag_set( + actions = all_link_actions, + flag_groups = [ + flag_group( + iterate_over = "library_search_directories", + flag_groups = [ + flag_group( + flags = ["-L%{library_search_directories}"], + ), + ], + expand_if_available = "library_search_directories", + ), + ], + ), + ], + ) + + shared_flag_feature = feature( + name = "shared_flag", + enabled = True, + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.cpp_link_dynamic_library, + ACTION_NAMES.cpp_link_nodeps_dynamic_library, + ], + flag_groups = [flag_group(flags = ["-shared"])], + ), + ], + ) + + output_execpath_flags_feature = feature( + name = "output_execpath_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = all_link_actions, + flag_groups = [ + flag_group( + flags = ["-o", "%{output_execpath}"], + expand_if_available = "output_execpath", + ), + ], + ), + ], + ) + runtime_library_search_directories_feature = feature( name = "runtime_library_search_directories", enabled = True, @@ -442,6 +738,86 @@ def _impl(ctx): ], ) + libraries_to_link_feature = feature( + name = "libraries_to_link", + enabled = True, + flag_sets = [ + flag_set( + actions = all_link_actions, + flag_groups = [ + flag_group( + iterate_over = "libraries_to_link", + flag_groups = [ + flag_group( + flags = ["-Wl,--whole-archive", "%{libraries_to_link.name}", "-Wl,--no-whole-archive"], + expand_if_true = "libraries_to_link.is_whole_archive", + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "static_library", + ), + ), + flag_group( + flags = ["%{libraries_to_link.name}"], + expand_if_false = "libraries_to_link.is_whole_archive", + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "static_library", + ), + ), + flag_group( + flags = ["%{libraries_to_link.name}"], + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "object_file", + ), + ), + flag_group( + flags = ["%{libraries_to_link.object_files}"], + iterate_over = "libraries_to_link.object_files", + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "object_file_group", + ), + ), + flag_group( + flags = ["-l%{libraries_to_link.name}"], + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "dynamic_library", + ), + ), + flag_group( + flags = ["-l:%{libraries_to_link.name}"], + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "versioned_dynamic_library", + ), + ), + ], + expand_if_available = "libraries_to_link", + ), + ], + ), + ], + ) + + user_link_flags_feature = feature( + name = "user_link_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = all_link_actions, + flag_groups = [ + flag_group( + iterate_over = "user_link_flags", + flags = ["%{user_link_flags}"], + expand_if_available = "user_link_flags", + ), + ], + ), + ], + ) + # ------------------------------------------------------------------------ # Additional legacy features. # @@ -636,30 +1012,30 @@ def _impl(ctx): # after a command line parameter from a feature at the beginning of the list. features = [ - shared.no_legacy_features_feature, + no_legacy_features_feature, compiler_library_search_paths_feature, - shared.dbg_feature, - shared.unfiltered_compile_flags_feature, + dbg_feature, + unfiltered_compile_flags_feature, gnu11_feature, default_compile_flags_feature, - shared.random_seed_feature, - shared.include_paths_feature, - shared.preprocessor_defines_feature, - shared.user_compile_flags_feature, - shared.compiler_input_flags_feature, - shared.compiler_output_flags_feature, + random_seed_feature, + include_paths_feature, + preprocessor_defines_feature, + user_compile_flags_feature, + compiler_input_flags_feature, + compiler_output_flags_feature, dependency_file_feature, per_object_debug_info_feature, includes_feature, default_link_flags_feature, - shared.archiver_flags_feature, - shared.linker_param_file_feature, - shared.library_search_directories_feature, - shared.shared_flag_feature, - shared.output_execpath_flags_feature, + archiver_flags_feature, + linker_param_file_feature, + library_search_directories_feature, + shared_flag_feature, + output_execpath_flags_feature, runtime_library_search_directories_feature, - shared.libraries_to_link_feature, - shared.user_link_flags_feature, + libraries_to_link_feature, + user_link_flags_feature, linkstamps_feature, fission_support_feature, force_pic_flags_feature, @@ -676,10 +1052,10 @@ def _impl(ctx): extra_c_compile_flags_feature, extra_cxx_compile_flags_feature, extra_link_flags_feature, - shared.opt_feature, - shared.supports_dynamic_linker_feature, - shared.supports_pic_feature, - shared.pic_feature, + opt_feature, + supports_dynamic_linker_feature, + supports_pic_feature, + pic_feature, supports_header_path_normalization, supports_fission_feature, coverage_feature, @@ -700,7 +1076,7 @@ def _impl(ctx): sysroot = None if ctx.attr.sysroot != None: sysroot = ctx.attr.sysroot[DefaultInfo].files.to_list()[0].path - + return cc_common.create_cc_toolchain_config_info( ctx = ctx, abi_version = "%{tc_abi_version}", diff --git a/templates/qnx/cc_toolchain_config.bzl.template b/templates/qnx/cc_toolchain_config.bzl.template index c023bd2..39bb81a 100644 --- a/templates/qnx/cc_toolchain_config.bzl.template +++ b/templates/qnx/cc_toolchain_config.bzl.template @@ -49,20 +49,49 @@ load(":flags.bzl", "WARNINGS_AS_ERRORS", ) -load(":shared_features.bzl", - "all_actions", - "all_assemble_actions", - "all_c_compile_actions", - "all_compile_actions", - "all_cpp_compile_actions", - "all_link_actions", - "make_shared_features", -) +all_cpp_compile_actions = [ + ACTION_NAMES.cpp_compile, + ACTION_NAMES.linkstamp_compile, + ACTION_NAMES.cpp_header_parsing, + ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.clif_match, + ACTION_NAMES.lto_backend, +] + +all_c_compile_actions = [ + ACTION_NAMES.c_compile, +] + +all_assemble_actions = [ + ACTION_NAMES.assemble, + ACTION_NAMES.preprocess_assemble, +] + +all_compile_actions = all_c_compile_actions + all_cpp_compile_actions + all_assemble_actions + +all_link_actions = [ + ACTION_NAMES.cpp_link_executable, + ACTION_NAMES.cpp_link_dynamic_library, + ACTION_NAMES.cpp_link_nodeps_dynamic_library, +] + +all_actions = all_compile_actions + all_link_actions + [ + ACTION_NAMES.strip, + ACTION_NAMES.cpp_link_static_library, +] def _impl(ctx): """ Implementation function of GCC toolchains. """ + dbg_feature = feature(name = "dbg") + opt_feature = feature(name = "opt") + + no_legacy_features_feature = feature(name = "no_legacy_features", enabled = True) + + supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True) + assemble_action = action_config( action_name = ACTION_NAMES.assemble, tools = [tool(tool = ctx.executable.cc_binary)], @@ -135,9 +164,336 @@ def _impl(ctx): strip_action, ] - shared = make_shared_features(UNFILTERED_COMPILE_FLAGS) + # Core compilation features + random_seed_feature = feature( + name = "random_seed", + enabled = True, + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.cpp_module_codegen, + ], + flag_groups = [ + flag_group( + expand_if_available = "output_file", + flags = ["-frandom-seed=%{output_file}"], + ), + ], + ), + ], + ) + + include_paths_feature = feature( + name = "include_paths", + enabled = True, + flag_sets = [ + flag_set( + actions = all_compile_actions, + flag_groups = [ + flag_group( + iterate_over = "quote_include_paths", + flags = ["-iquote", "%{quote_include_paths}"], + expand_if_available = "quote_include_paths", + ), + ], + ), + flag_set( + actions = all_compile_actions, + flag_groups = [ + flag_group( + iterate_over = "include_paths", + flags = ["-I%{include_paths}"], + expand_if_available = "include_paths", + ), + ], + ), + flag_set( + actions = all_compile_actions, + flag_groups = [ + flag_group( + iterate_over = "system_include_paths", + flags = ["-isystem", "%{system_include_paths}"], + expand_if_available = "system_include_paths", + ), + ], + ), + ], + ) + + preprocessor_defines_feature = feature( + name = "preprocessor_defines", + enabled = True, + flag_sets = [ + flag_set( + actions = all_compile_actions, + flag_groups = [ + flag_group( + iterate_over = "preprocessor_defines", + flags = ["-D%{preprocessor_defines}"], + expand_if_available = "preprocessor_defines", + ), + ], + ), + ], + ) + + user_compile_flags_feature = feature( + name = "user_compile_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = all_compile_actions, + flag_groups = [ + flag_group( + iterate_over = "user_compile_flags", + flags = ["%{user_compile_flags}"], + expand_if_available = "user_compile_flags", + ), + ], + ), + ], + ) + + compiler_input_flags_feature = feature( + name = "compiler_input_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = all_compile_actions, + flag_groups = [ + flag_group( + flags = ["-c", "%{source_file}"], + expand_if_available = "source_file", + ), + ], + ), + ], + ) + + compiler_output_flags_feature = feature( + name = "compiler_output_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = all_compile_actions, + flag_groups = [ + flag_group( + flags = ["-S"], + expand_if_available = "output_assembly_file", + ), + flag_group( + flags = ["-E"], + expand_if_available = "output_preprocess_file", + ), + flag_group( + flags = ["-o", "%{output_file}"], + expand_if_available = "output_file", + ), + ], + ), + ], + ) + + archiver_flags_feature = feature( + name = "archiver_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = [ACTION_NAMES.cpp_link_static_library], + flag_groups = [ + flag_group(flags = ["rcsD", "%{output_execpath}"]), + flag_group( + iterate_over = "libraries_to_link", + flag_groups = [ + flag_group( + flags = ["%{libraries_to_link.name}"], + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "object_file", + ), + ), + flag_group( + flags = ["%{libraries_to_link.object_files}"], + iterate_over = "libraries_to_link.object_files", + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "object_file_group", + ), + ), + ], + expand_if_available = "libraries_to_link", + ), + flag_group( + iterate_over = "user_archiver_flags", + flags = ["%{user_archiver_flags}"], + expand_if_available = "user_archiver_flags", + ), + ], + ), + ], + ) # Core linking features + user_link_flags_feature = feature( + name = "user_link_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = all_link_actions, + flag_groups = [ + flag_group( + iterate_over = "user_link_flags", + flags = ["%{user_link_flags}"], + expand_if_available = "user_link_flags", + ), + ], + ), + ], + ) + + linker_param_file_feature = feature( + name = "linker_param_file", + enabled = True, + flag_sets = [ + flag_set( + actions = all_link_actions + [ACTION_NAMES.cpp_link_static_library], + flag_groups = [ + flag_group( + flags = ["@%{linker_param_file}"], + expand_if_available = "linker_param_file", + ), + ], + ), + ], + ) + + library_search_directories_feature = feature( + name = "library_search_directories", + enabled = True, + flag_sets = [ + flag_set( + actions = all_link_actions, + flag_groups = [ + flag_group( + iterate_over = "library_search_directories", + flag_groups = [ + flag_group( + flags = ["-L%{library_search_directories}"], + ), + ], + expand_if_available = "library_search_directories", + ), + ], + ), + ], + ) + + shared_flag_feature = feature( + name = "shared_flag", + enabled = True, + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.cpp_link_dynamic_library, + ACTION_NAMES.cpp_link_nodeps_dynamic_library, + ], + flag_groups = [flag_group(flags = ["-shared"])], + ), + ], + ) + + output_execpath_flags_feature = feature( + name = "output_execpath_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = all_link_actions, + flag_groups = [ + flag_group( + flags = ["-o", "%{output_execpath}"], + expand_if_available = "output_execpath", + ), + ], + ), + ], + ) + + libraries_to_link_feature = feature( + name = "libraries_to_link", + enabled = True, + flag_sets = [ + flag_set( + actions = all_link_actions, + flag_groups = [ + flag_group( + iterate_over = "libraries_to_link", + flag_groups = [ + flag_group( + flags = ["-Wl,--whole-archive", "%{libraries_to_link.name}", "-Wl,--no-whole-archive"], + expand_if_true = "libraries_to_link.is_whole_archive", + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "static_library", + ), + ), + flag_group( + flags = ["%{libraries_to_link.name}"], + expand_if_false = "libraries_to_link.is_whole_archive", + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "static_library", + ), + ), + flag_group( + flags = ["%{libraries_to_link.name}"], + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "object_file", + ), + ), + flag_group( + flags = ["%{libraries_to_link.object_files}"], + iterate_over = "libraries_to_link.object_files", + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "object_file_group", + ), + ), + flag_group( + flags = ["-l%{libraries_to_link.name}"], + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "dynamic_library", + ), + ), + flag_group( + flags = ["-l:%{libraries_to_link.name}"], + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "versioned_dynamic_library", + ), + ), + ], + expand_if_available = "libraries_to_link", + ), + ], + ), + ], + ) + + unfiltered_compile_flags_feature = feature( + name = "unfiltered_compile_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = all_c_compile_actions + all_cpp_compile_actions, + flag_groups = UNFILTERED_COMPILE_FLAGS, + ), + ], + ) default_compile_flags_feature = feature( name = "default_compile_flags", @@ -285,6 +641,27 @@ def _impl(ctx): ), ], ) + supports_pic_feature = feature(name = "supports_pic", enabled = True) + + pic_feature = feature( + name = "pic", + enabled = True, + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.assemble, + ACTION_NAMES.preprocess_assemble, + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.cpp_module_compile, + ], + flag_groups = [ + flag_group(flags = ["-fPIC"], expand_if_available = "pic"), + ], + ), + ], + ) dependency_file_named_implicitly_feature = feature( name = "dependency_file_named_implicitly", @@ -422,38 +799,38 @@ def _impl(ctx): # after a command line parameter from a feature at the beginning of the list. features = [ - shared.dbg_feature, - shared.no_legacy_features_feature, - shared.unfiltered_compile_flags_feature, + dbg_feature, + no_legacy_features_feature, + unfiltered_compile_flags_feature, default_compile_flags_feature, - shared.random_seed_feature, - shared.include_paths_feature, - shared.preprocessor_defines_feature, - shared.user_compile_flags_feature, - shared.compiler_input_flags_feature, - shared.compiler_output_flags_feature, + random_seed_feature, + include_paths_feature, + preprocessor_defines_feature, + user_compile_flags_feature, + compiler_input_flags_feature, + compiler_output_flags_feature, dependency_file_named_implicitly_feature, dependency_file_feature, default_link_flags_feature, - shared.archiver_flags_feature, - shared.user_link_flags_feature, - shared.linker_param_file_feature, - shared.library_search_directories_feature, - shared.shared_flag_feature, - shared.output_execpath_flags_feature, - shared.libraries_to_link_feature, + archiver_flags_feature, + user_link_flags_feature, + linker_param_file_feature, + library_search_directories_feature, + shared_flag_feature, + output_execpath_flags_feature, + libraries_to_link_feature, minimal_warnings_feature, strict_warnings_feature, all_wall_warnings_feature, warnings_as_errors_feature, extra_compile_flags_feature, extra_link_flags_feature, - shared.opt_feature, + opt_feature, use_license_env_info_feautre, sdp_env_feature, - shared.supports_dynamic_linker_feature, - shared.supports_pic_feature, - shared.pic_feature, + supports_dynamic_linker_feature, + supports_pic_feature, + pic_feature, runtime_library_search_directories_feature, coverage_feature, gcc_coverage_map_format_feature, diff --git a/tests/MODULE.bazel.lock b/tests/MODULE.bazel.lock index 6fe2457..15a6923 100644 --- a/tests/MODULE.bazel.lock +++ b/tests/MODULE.bazel.lock @@ -1369,7 +1369,7 @@ }, "@@score_bazel_cpp_toolchains+//extensions:gcc.bzl%gcc": { "general": { - "bzlTransitiveDigest": "k0Poh7g76vVDdUlgMYBtFBF1aGJ46pOj0iy05dby95c=", + "bzlTransitiveDigest": "uUsNFSfSSybb9eE3vhujRJ3STO1XYw/Su0MpWT8DZJI=", "usagesDigest": "dWr2zFjJ8fBvweFk2KWoZzQqJ+aKnb9A8QACQhKlUfw=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, @@ -1509,7 +1509,6 @@ "gcc_version": "12.2.0", "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_config.bzl.template", "cc_toolchain_flags": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_flags.bzl.template", - "cc_toolchain_shared_features": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_shared_features.bzl.template", "use_base_constraints_only": true } }, @@ -1537,7 +1536,6 @@ "gcc_version": "12.2.0", "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_config.bzl.template", "cc_toolchain_flags": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_flags.bzl.template", - "cc_toolchain_shared_features": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_shared_features.bzl.template", "use_base_constraints_only": false } }, @@ -1565,7 +1563,6 @@ "gcc_version": "15.3.0", "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_config.bzl.template", "cc_toolchain_flags": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_flags.bzl.template", - "cc_toolchain_shared_features": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_shared_features.bzl.template", "use_base_constraints_only": false } }, @@ -1593,7 +1590,6 @@ "gcc_version": "12.2.0", "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_config.bzl.template", "cc_toolchain_flags": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_flags.bzl.template", - "cc_toolchain_shared_features": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_shared_features.bzl.template", "use_base_constraints_only": false } }, @@ -1621,7 +1617,6 @@ "gcc_version": "15.3.0", "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_config.bzl.template", "cc_toolchain_flags": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_flags.bzl.template", - "cc_toolchain_shared_features": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_shared_features.bzl.template", "use_base_constraints_only": false } }, @@ -1651,7 +1646,6 @@ "gcc_version": "12.2.0", "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_config.bzl.template", "cc_toolchain_flags": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_flags.bzl.template", - "cc_toolchain_shared_features": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_shared_features.bzl.template", "use_base_constraints_only": false } }, @@ -1679,7 +1673,6 @@ "gcc_version": "12.2.0", "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates/qnx:cc_toolchain_config.bzl.template", "cc_toolchain_flags": "@@score_bazel_cpp_toolchains+//templates/qnx:cc_toolchain_flags.bzl.template", - "cc_toolchain_shared_features": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_shared_features.bzl.template", "use_base_constraints_only": false } }, @@ -1707,7 +1700,6 @@ "gcc_version": "12.2.0", "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates/qnx:cc_toolchain_config.bzl.template", "cc_toolchain_flags": "@@score_bazel_cpp_toolchains+//templates/qnx:cc_toolchain_flags.bzl.template", - "cc_toolchain_shared_features": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_shared_features.bzl.template", "use_base_constraints_only": false } }, @@ -1771,7 +1763,6 @@ "gcc_version": "", "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_config.bzl.template", "cc_toolchain_flags": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_flags.bzl.template", - "cc_toolchain_shared_features": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_shared_features.bzl.template", "use_base_constraints_only": false } }, @@ -1851,7 +1842,6 @@ "gcc_version": "", "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_config.bzl.template", "cc_toolchain_flags": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_flags.bzl.template", - "cc_toolchain_shared_features": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_shared_features.bzl.template", "use_base_constraints_only": false } }