diff --git a/extensions/gcc.bzl b/extensions/gcc.bzl index d86ee8a..7daf650 100644 --- a/extensions/gcc.bzl +++ b/extensions/gcc.bzl @@ -203,9 +203,9 @@ def _get_toolchains(tags): toolchains = [] for tag in 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", + "cc_toolchain_config": "@score_bazel_cpp_toolchains//templates:cc_toolchain_config.bzl.template", + "cc_toolchain_flags": "@score_bazel_cpp_toolchains//templates:cc_toolchain_flags.bzl.template", + "cc_toolchain_shared_features": "@score_bazel_cpp_toolchains//templates/shared:cc_toolchain_shared_features.bzl.template", "gcc_version": tag.version, "name": tag.name, "use_base_constraints_only": tag.use_base_constraints_only, diff --git a/rules/gcc.bzl b/rules/gcc.bzl index f128e12..e353b65 100644 --- a/rules/gcc.bzl +++ b/rules/gcc.bzl @@ -241,40 +241,71 @@ def _impl(rctx): extra_link_flags = get_flag_groups(replace_placeholder(rctx.attr.extra_link_flags)) compiler_library_search_paths = replace_placeholder(rctx.attr.tc_compiler_library_search_paths) - template_dict = { - "%{compiler_library_search_paths_switch}": "True" if len(rctx.attr.tc_compiler_library_search_paths) else "False", - "%{compiler_library_search_paths}": ":".join(["/proc/self/cwd/" + entry for entry in compiler_library_search_paths]), - "%{extra_c_compile_flags_switch}": "True" if len(rctx.attr.extra_c_compile_flags) else "False", - "%{extra_c_compile_flags}": extra_c_compile_flags, - "%{extra_compile_flags_switch}": "True" if len(rctx.attr.extra_compile_flags) else "False", - "%{extra_compile_flags}": extra_compile_flags, - "%{extra_cxx_compile_flags_switch}": "True" if len(rctx.attr.extra_cxx_compile_flags) else "False", - "%{extra_cxx_compile_flags}": extra_cxx_compile_flags, - "%{extra_link_flags_switch}": "True" if len(rctx.attr.extra_link_flags) else "False", - "%{extra_link_flags}": extra_link_flags, + # Compute once so it is available for both config and qnx feature template dicts. + mapped_sdp_version = _apply_sdp_version_mapping(rctx.attr.sdp_version) + mapped_sdp_version_for_config = mapped_sdp_version if rctx.attr.tc_os == _OS_QNX else "" + + config_template_dict = { + "%{sdp_version}": mapped_sdp_version_for_config, + "%{tc_abi_version}": "{}-linux-gnu".format(_normalize_cpu(rctx.attr.tc_cpu)) if rctx.attr.tc_os == _OS_LINUX else "", "%{tc_cpu}": _normalize_cpu(rctx.attr.tc_cpu), - "%{tc_identifier}": "gcc", - "%{tc_runtime_es}": rctx.attr.tc_runtime_ecosystem, - "%{tc_version}": rctx.attr.gcc_version, + "%{tc_identifier}": rctx.attr.tc_identifier if rctx.attr.tc_identifier else "gcc", + "%{tc_os}": rctx.attr.tc_os, } - if rctx.attr.tc_os == _OS_QNX: - mapped_sdp_version = _apply_sdp_version_mapping(rctx.attr.sdp_version) - extra_template_dict = { + rctx.template( + "cc_toolchain_config.bzl", + rctx.attr.cc_toolchain_config, + config_template_dict, + ) + + if rctx.attr.tc_os == _OS_LINUX: + linux_features_template_dict = { + "%{compiler_library_search_paths_switch}": "True" if len(rctx.attr.tc_compiler_library_search_paths) else "False", + "%{compiler_library_search_paths}": ":".join(["/proc/self/cwd/" + entry for entry in compiler_library_search_paths]), + "%{extra_c_compile_flags_switch}": "True" if len(rctx.attr.extra_c_compile_flags) else "False", + "%{extra_c_compile_flags}": extra_c_compile_flags, + "%{extra_compile_flags_switch}": "True" if len(rctx.attr.extra_compile_flags) else "False", + "%{extra_compile_flags}": extra_compile_flags, + "%{extra_cxx_compile_flags_switch}": "True" if len(rctx.attr.extra_cxx_compile_flags) else "False", + "%{extra_cxx_compile_flags}": extra_cxx_compile_flags, + "%{extra_link_flags_switch}": "True" if len(rctx.attr.extra_link_flags) else "False", + "%{extra_link_flags}": extra_link_flags, + } + rctx.template( + "cc_toolchain_linux_config.bzl", + rctx.attr._cc_toolchain_linux_config, + linux_features_template_dict, + ) + rctx.template( + "linux_flags.bzl", + rctx.attr._cc_toolchain_linux_flags, + {}, + ) + elif rctx.attr.tc_os == _OS_QNX: + qnx_features_template_dict = { + "%{extra_compile_flags_switch}": "True" if len(rctx.attr.extra_compile_flags) else "False", + "%{extra_compile_flags}": extra_compile_flags, + "%{extra_link_flags_switch}": "True" if len(rctx.attr.extra_link_flags) else "False", + "%{extra_link_flags}": extra_link_flags, "%{license_info_value}": rctx.attr.license_info_value, "%{license_info_variable}": rctx.attr.license_info_variable, "%{license_path}": rctx.attr.license_path, - "%{sdp_version}": mapped_sdp_version, - "%{tc_cpu_cxx}": _normalize_cpu(rctx.attr.tc_cpu), + "%{sdp_version}": mapped_sdp_version_for_config, + "%{tc_cpu}": _normalize_cpu(rctx.attr.tc_cpu), + "%{tc_version}": rctx.attr.gcc_version, "%{use_license_info}": "False" if rctx.attr.license_info_value == "" else "True", } - template_dict = dict_union(template_dict, extra_template_dict) - - rctx.template( - "cc_toolchain_config.bzl", - rctx.attr.cc_toolchain_config, - template_dict, - ) + rctx.template( + "cc_toolchain_qnx_config.bzl", + rctx.attr._cc_toolchain_qnx_config, + qnx_features_template_dict, + ) + rctx.template( + "qnx_flags.bzl", + rctx.attr._cc_toolchain_qnx_flags, + {}, + ) rctx.template( "flags.bzl", @@ -304,7 +335,6 @@ def _impl(rctx): elif rctx.attr.tc_os == _OS_QNX: # Generate gcov wrapper for QNX toolchains to enable `bazel coverage`. # See: https://github.com/bazelbuild/rules_cc/issues/351 - mapped_sdp_version = _apply_sdp_version_mapping(rctx.attr.sdp_version) if rctx.attr.tc_cpu == _CPU_AARCH64: gcov_triple = _TRIPLE_AARCH64_QNX_FMT.format(sdp = mapped_sdp_version) else: @@ -355,6 +385,18 @@ gcc_toolchain = repository_rule( "_cc_gcov_wrapper_script": attr.label( default = "@score_bazel_cpp_toolchains//templates/linux:cc_gcov_wrapper.template", ), + "_cc_toolchain_linux_config": attr.label( + default = "@score_bazel_cpp_toolchains//templates/linux:cc_toolchain_config.bzl.template", + ), + "_cc_toolchain_linux_flags": attr.label( + default = "@score_bazel_cpp_toolchains//templates/linux:cc_toolchain_flags.bzl.template", + ), + "_cc_toolchain_qnx_config": attr.label( + default = "@score_bazel_cpp_toolchains//templates/qnx:cc_toolchain_config.bzl.template", + ), + "_cc_toolchain_qnx_flags": attr.label( + default = "@score_bazel_cpp_toolchains//templates/qnx:cc_toolchain_flags.bzl.template", + ), "_cc_toolchain_build": attr.label( default = "@score_bazel_cpp_toolchains//templates:BUILD.template", doc = "Path to the Bazel BUILD file template for the toolchain.", diff --git a/templates/cc_toolchain_config.bzl.template b/templates/cc_toolchain_config.bzl.template new file mode 100644 index 0000000..e24d78b --- /dev/null +++ b/templates/cc_toolchain_config.bzl.template @@ -0,0 +1,177 @@ +# ******************************************************************************* +# Copyright (c) 2025 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 +# ******************************************************************************* + +"""Unified GCC toolchain configuration — dispatches to the OS-specific feature module.""" + +load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") +load( + "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", + "action_config", + "flag_group", + "flag_set", + "tool", + "tool_path", +) +load("@rules_cc//cc:defs.bzl", "CcToolchainConfigInfo") +load("@rules_cc//cc/toolchains:feature_injection.bzl", "FeatureInfo", "convert_feature") +load(":cc_toolchain_%{tc_os}_config.bzl", "EXTRA_ATTRS", "make_features", "make_toolchain_config_info") +load( + ":flags.bzl", + "UNFILTERED_COMPILE_FLAGS", + "DBG_COMPILE_FLAGS", + "OPT_COMPILE_FLAGS" +) +load( + ":shared_features.bzl", + "all_actions", + "all_assemble_actions", + "all_c_compile_actions", + "all_compile_actions", + "all_cpp_compile_actions", + "all_link_actions", +) + +def _impl(ctx): + flags = struct( + unfiltered_compile_flags = UNFILTERED_COMPILE_FLAGS, + dbg_compile_flags = DBG_COMPILE_FLAGS, + opt_compile_flags = OPT_COMPILE_FLAGS, + ) + + actions = struct( + all_actions = all_actions, + all_assemble_actions = all_assemble_actions, + all_c_compile_actions = all_c_compile_actions, + all_compile_actions = all_compile_actions, + all_cpp_compile_actions = all_cpp_compile_actions, + all_link_actions = all_link_actions, + ) + + assemble_action = action_config( + action_name = ACTION_NAMES.assemble, + tools = [tool(tool = ctx.executable.cc_binary)], + ) + preprocess_assemble_action = action_config( + action_name = ACTION_NAMES.preprocess_assemble, + tools = [tool(tool = ctx.executable.cc_binary)], + ) + c_compile_action = action_config( + action_name = ACTION_NAMES.c_compile, + tools = [tool(tool = ctx.executable.cc_binary)], + ) + cpp_compile_action = action_config( + action_name = ACTION_NAMES.cpp_compile, + tools = [tool(tool = ctx.executable.cxx_binary)], + ) + cpp_link_executable_action = action_config( + action_name = ACTION_NAMES.cpp_link_executable, + tools = [tool(tool = ctx.executable.cxx_binary)], + ) + cpp_link_dynamic_library_action = action_config( + action_name = ACTION_NAMES.cpp_link_dynamic_library, + tools = [tool(tool = ctx.executable.cxx_binary)], + ) + cpp_link_nodeps_dynamic_library_action = action_config( + action_name = ACTION_NAMES.cpp_link_nodeps_dynamic_library, + tools = [tool(tool = ctx.executable.cxx_binary)], + ) + cpp_link_static_library_action = action_config( + action_name = ACTION_NAMES.cpp_link_static_library, + tools = [tool(tool = ctx.executable.ar_binary)], + implies = ["archiver_flags"], + ) + strip_action = action_config( + action_name = ACTION_NAMES.strip, + tools = [tool(tool = ctx.executable.strip_binary)], + flag_sets = [ + flag_set( + flag_groups = [ + flag_group(flags = ["-g", "-p"]), + flag_group( + iterate_over = "stripopts", + flags = ["%{stripopts}"], + ), + flag_group(flags = ["%{input_file}", "%{output_file}"]), + ], + ), + ], + ) + action_configs = [ + assemble_action, + c_compile_action, + cpp_compile_action, + cpp_link_dynamic_library_action, + cpp_link_executable_action, + cpp_link_nodeps_dynamic_library_action, + cpp_link_static_library_action, + preprocess_assemble_action, + strip_action, + ] + + features = make_features(ctx, flags, actions) + + extra_rules_based_features = depset(ctx.attr.extra_enabled_features + ctx.attr.extra_known_features) + features.extend([ + convert_feature(extra_feature[FeatureInfo], enabled = extra_feature in ctx.attr.extra_enabled_features) + for extra_feature in extra_rules_based_features.to_list() + ]) + + tool_paths = [tool_path(name = "gcov", path = "gcov_wrapper")] + + return make_toolchain_config_info( + ctx, + features, + action_configs, + tool_paths, + abi_version = "%{tc_abi_version}", + target_cpu = "%{tc_cpu}", + target_os = "%{tc_os}", + toolchain_identifier = "%{tc_identifier}", + ) + +_BASE_ATTRS = { + "ar_binary": attr.label(allow_single_file = True, executable = True, cfg = "exec", mandatory = True), + "cc_binary": attr.label(allow_single_file = True, executable = True, cfg = "exec", mandatory = True), + "cxx_binary": attr.label(allow_single_file = True, executable = True, cfg = "exec", mandatory = True), + "gcov_binary": attr.label(allow_single_file = True, executable = True, cfg = "exec", mandatory = True), + "strip_binary": attr.label(allow_single_file = True, executable = True, cfg = "exec", mandatory = True), + "target_cpu": attr.string(mandatory = True), + "target_os": attr.string(mandatory = True), + "extra_enabled_features": attr.label_list( + providers = [FeatureInfo], + default = [], + doc = """ +Extra `cc_feature` features to add to this toolchain in an initially enabled state. +This attribute has limited integration with `cc_feature`, and does not run additional correctness checks or handle things like `data` files. +This is only offered as a migration bridge for projects transitioning to rule-based toolchain configurations, or sharing of simple argument sets with older toolchains. +""", + ), + "extra_known_features": attr.label_list( + providers = [FeatureInfo], + default = [], + doc = """ +Extra `cc_feature` features to add to this toolchain in an initially disabled state. +This attribute has limited integration with `cc_feature`, and does not run additional correctness checks or handle things like `data` files. +This is only offered as a migration bridge for projects transitioning to rule-based toolchain configurations, or sharing of simple argument sets with older toolchains. +""", + ), +} + +_RULE_ATTRS = dict(_BASE_ATTRS) +_RULE_ATTRS.update(EXTRA_ATTRS) + +cc_toolchain_config = rule( + implementation = _impl, + provides = [CcToolchainConfigInfo], + attrs = _RULE_ATTRS, +) diff --git a/templates/cc_toolchain_flags.bzl.template b/templates/cc_toolchain_flags.bzl.template new file mode 100644 index 0000000..26cf500 --- /dev/null +++ b/templates/cc_toolchain_flags.bzl.template @@ -0,0 +1,54 @@ +# ******************************************************************************* +# Copyright (c) 2025 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 +# ******************************************************************************* + +""" Common compile and link flags for GCC toolchains. +""" + +load("@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", "flag_group") + +def get_flag_group(flags): + """Helper function to create a flag_group. + + Args: + flags (list[str]): A list of compiler or linker flags. + + Returns: + flag_group: A Bazel flag_group object containing the provided flags. + """ + if len(flags): + return [ + flag_group( + flags = flags, + ) + ] + return [] + +# Flags that should always be applied, without filtering. +UNFILTERED_COMPILE_FLAGS = get_flag_group([ + "-D__DATE__=\"redacted\"", + "-D__TIMESTAMP__=\"redacted\"", + "-D__TIME__=\"redacted\"", + "-Wno-builtin-macro-redefined", +]) + +# Debug compile flags. +DBG_COMPILE_FLAGS = get_flag_group([ + "-Og", + "-g3", +]) + +# Optimization compile flags. +OPT_COMPILE_FLAGS = get_flag_group([ + "-O2", + "-DNDEBUG", +]) diff --git a/templates/linux/cc_toolchain_config.bzl.template b/templates/linux/cc_toolchain_config.bzl.template index 8d28e81..a485ac0 100644 --- a/templates/linux/cc_toolchain_config.bzl.template +++ b/templates/linux/cc_toolchain_config.bzl.template @@ -11,34 +11,25 @@ # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* -"""C/C++ toolchain definition""" +"""Linux-specific GCC toolchain feature factory.""" load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") -load("@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", - "action_config", +load( + "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", "env_entry", "env_set", "feature", "feature_set", "flag_group", "flag_set", - "tool", - "tool_path", - "variable_with_value", "with_feature_set", ) -load("@rules_cc//cc:defs.bzl", "cc_common", "CcToolchainConfigInfo") -load("@rules_cc//cc/toolchains:feature_injection.bzl", "convert_feature", "FeatureInfo") -load(":flags.bzl", - "UNFILTERED_COMPILE_FLAGS", +load("@rules_cc//cc:defs.bzl", "cc_common") +load(":linux_flags.bzl", "DEFAULT_COMPILE_FLAGS", - "DEFAULT_x86_64_COMPILE_FLAGS", - "DEFAULT_ARM64_COMPILE_FLAGS", "DEFAULT_C_COMPILE_FLAGS", "DEFAULT_CXX_COMPILE_FLAGS", "DEFAULT_LINK_FLAGS", - "DBG_COMPILE_FLAGS", - "OPT_COMPILE_FLAGS", "MINIMAL_WARNINGS_FLAGS", "MINIMAL_C_WARNINGS_FLAGS", "MINIMAL_CXX_WARNINGS_FLAGS", @@ -50,97 +41,21 @@ load(":flags.bzl", "ALL_WALL_CXX_WARNINGS", "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", +load( + ":shared_features.bzl", + "make_shared_features" ) -def _impl(ctx): +_DEFAULT_x86_64_COMPILE_FLAGS = [flag_group(flags = ["-m64"])] +_DEFAULT_ARM64_COMPILE_FLAGS = [] - # Temp solution until we do not add feature injection - gnu11_feature = feature(name = "gnu11") +def make_features(ctx, flags, actions): - supports_fission_feature = feature(name = "supports_fission", enabled = True) - - assemble_action = action_config( - action_name = ACTION_NAMES.assemble, - tools = [tool(tool = ctx.executable.cc_binary)], - ) - preprocess_assemble_action = action_config( - action_name = ACTION_NAMES.preprocess_assemble, - tools = [tool(tool = ctx.executable.cc_binary)], - ) - c_compile_action = action_config( - action_name = ACTION_NAMES.c_compile, - tools = [tool(tool = ctx.executable.cc_binary)], - ) - cpp_compile_action = action_config( - action_name = ACTION_NAMES.cpp_compile, - tools = [tool(tool = ctx.executable.cxx_binary)], - ) - cpp_link_executable_action = action_config( - action_name = ACTION_NAMES.cpp_link_executable, - tools = [tool(tool = ctx.executable.cxx_binary)], - ) - cpp_link_dynamic_library_action = action_config( - action_name = ACTION_NAMES.cpp_link_dynamic_library, - tools = [tool(tool = ctx.executable.cxx_binary)], - ) - cpp_link_nodeps_dynamic_library_action = action_config( - action_name = ACTION_NAMES.cpp_link_nodeps_dynamic_library, - tools = [tool(tool = ctx.executable.cxx_binary)], - ) - cpp_link_static_library_action = action_config( - action_name = ACTION_NAMES.cpp_link_static_library, - tools = [tool(tool = ctx.executable.ar_binary)], - implies = ["archiver_flags"], - ) - strip_action = action_config( - action_name = ACTION_NAMES.strip, - tools = [tool(tool = ctx.executable.strip_binary)], - flag_sets = [ - flag_set( - flag_groups = [ - flag_group( - flags = [ - "-g", - "-p", - ], - ), - flag_group( - iterate_over = "stripopts", - flags = ["%{stripopts}"], - ), - flag_group( - flags = [ - "%{input_file}", - "%{output_file}", - ], - ), - ], - ), - ], - ) + shared = make_shared_features(flags.unfiltered_compile_flags) - action_configs = [ - assemble_action, - c_compile_action, - cpp_compile_action, - cpp_link_dynamic_library_action, - cpp_link_executable_action, - cpp_link_nodeps_dynamic_library_action, - cpp_link_static_library_action, - preprocess_assemble_action, - strip_action, - ] + gnu11_feature = feature(name = "gnu11") - shared = make_shared_features(UNFILTERED_COMPILE_FLAGS) + supports_fission_feature = feature(name = "supports_fission", enabled = True) # 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 @@ -151,7 +66,7 @@ def _impl(ctx): enabled = %{compiler_library_search_paths_switch}, env_sets = [ env_set( - actions = all_actions, + actions = actions.all_actions, env_entries = [env_entry(key = "LD_LIBRARY_PATH", value = compiler_library_search_paths)] if compiler_library_search_paths != "" else [], ), ], @@ -159,44 +74,44 @@ def _impl(ctx): target_cpu_flags = [] if ctx.attr.target_cpu == "x86_64": - target_cpu_flags = DEFAULT_x86_64_COMPILE_FLAGS + target_cpu_flags = _DEFAULT_x86_64_COMPILE_FLAGS else: - target_cpu_flags = DEFAULT_ARM64_COMPILE_FLAGS + target_cpu_flags = _DEFAULT_ARM64_COMPILE_FLAGS default_compile_flags_feature = feature( name = "default_compile_flags", enabled = True, flag_sets = [ flag_set( - actions = all_compile_actions, + actions = actions.all_compile_actions, flag_groups = DEFAULT_COMPILE_FLAGS, ), flag_set( - actions = all_compile_actions, + actions = actions.all_compile_actions, flag_groups = target_cpu_flags, ), flag_set( - actions = all_c_compile_actions, + actions = actions.all_c_compile_actions, flag_groups = [flag_group(flags = ["-std=c11"])], with_features = [with_feature_set(not_features = ["gnu11"])], ), flag_set( - actions = all_c_compile_actions, + actions = actions.all_c_compile_actions, flag_groups = [flag_group(flags = ["-std=gnu11"])], with_features = [with_feature_set(features = ["gnu11"])], ), flag_set( - actions = all_cpp_compile_actions, + actions = actions.all_cpp_compile_actions, flag_groups = DEFAULT_CXX_COMPILE_FLAGS, ), flag_set( - actions = all_compile_actions, - flag_groups = DBG_COMPILE_FLAGS, + actions = actions.all_compile_actions, + flag_groups = flags.dbg_compile_flags, with_features = [with_feature_set(features = ["dbg"])], ), flag_set( - actions = all_compile_actions, - flag_groups = OPT_COMPILE_FLAGS, + actions = actions.all_compile_actions, + flag_groups = flags.opt_compile_flags, with_features = [ with_feature_set(features = ["opt"]), with_feature_set(features = ["fastbuild"]), @@ -213,7 +128,7 @@ def _impl(ctx): sysroot_path = sysroot_files[0].path sysroot_link_flags_feature_flag_sets = [ flag_set( - actions = all_link_actions, + actions = actions.all_link_actions, flag_groups = [flag_group(flags = [ "--sysroot=" + sysroot_path, "-Wl,--sysroot=" + sysroot_path, @@ -234,16 +149,16 @@ def _impl(ctx): enabled = default_link_flags_enabled, flag_sets = [ flag_set( - actions = all_link_actions, + actions = actions.all_link_actions, flag_groups = DEFAULT_LINK_FLAGS, ), flag_set( - actions = all_link_actions, + actions = actions.all_link_actions, flag_groups = [flag_group(flags = ["-Wl,--gc-sections"])], with_features = [with_feature_set(features = ["opt"])], ), flag_set( - actions = all_link_actions, + actions = actions.all_link_actions, flag_groups = [ flag_group( flags = [ @@ -261,15 +176,15 @@ def _impl(ctx): enabled = False, flag_sets = [ flag_set( - actions = all_compile_actions, + actions = actions.all_compile_actions, flag_groups = MINIMAL_WARNINGS_FLAGS, ), flag_set( - actions = all_c_compile_actions, + actions = actions.all_c_compile_actions, flag_groups = MINIMAL_C_WARNINGS_FLAGS, ), flag_set( - actions = all_cpp_compile_actions, + actions = actions.all_cpp_compile_actions, flag_groups = MINIMAL_CXX_WARNINGS_FLAGS, ), ], @@ -281,15 +196,15 @@ def _impl(ctx): enabled = False, flag_sets = [ flag_set( - actions = all_compile_actions, + actions = actions.all_compile_actions, flag_groups = STRICT_WARNINGS_FLAGS, ), flag_set( - actions = all_cpp_compile_actions, + actions = actions.all_cpp_compile_actions, flag_groups = STRICT_CXX_WARNINGS_FLAGS, ), flag_set( - actions = all_c_compile_actions, + actions = actions.all_c_compile_actions, flag_groups = STRICT_C_WARNINGS_FLAGS, ), ], @@ -301,15 +216,15 @@ def _impl(ctx): enabled = False, flag_sets = [ flag_set( - actions = all_compile_actions, + actions = actions.all_compile_actions, flag_groups = ALL_WALL_WARNINGS, ), flag_set( - actions = all_c_compile_actions, + actions = actions.all_c_compile_actions, flag_groups = ALL_WALL_C_WARNINGS, ), flag_set( - actions = all_cpp_compile_actions, + actions = actions.all_cpp_compile_actions, flag_groups = ALL_WALL_CXX_WARNINGS, ), ], @@ -320,7 +235,7 @@ def _impl(ctx): enabled = False, flag_sets = [ flag_set( - actions = all_compile_actions, + actions = actions.all_compile_actions, flag_groups = WARNINGS_AS_ERRORS, ), ], @@ -333,7 +248,7 @@ def _impl(ctx): implies = ["default_compile_flags"], flag_sets = [ flag_set( - actions = all_compile_actions, + actions = actions.all_compile_actions, flag_groups = extra_compile_flags, ), ], @@ -346,7 +261,7 @@ def _impl(ctx): implies = ["default_compile_flags"], flag_sets = [ flag_set( - actions = all_c_compile_actions, + actions = actions.all_c_compile_actions, flag_groups = extra_c_compile_flags, ), ], @@ -359,7 +274,7 @@ def _impl(ctx): implies = ["default_compile_flags"], flag_sets = [ flag_set( - actions = all_cpp_compile_actions, + actions = actions.all_cpp_compile_actions, flag_groups = extra_cxx_compile_flags, ), ], @@ -371,7 +286,7 @@ def _impl(ctx): enabled = %{extra_link_flags_switch}, flag_sets = [ flag_set( - actions = all_link_actions, + actions = actions.all_link_actions, flag_groups = extra_link_flags, ), ], @@ -382,7 +297,7 @@ def _impl(ctx): enabled = True, flag_sets = [ flag_set( - actions = all_link_actions, + actions = actions.all_link_actions, flag_groups = [ flag_group(flags = ["-pthread"]), ], @@ -421,7 +336,7 @@ def _impl(ctx): enabled = True, flag_sets = [ flag_set( - actions = all_link_actions, + actions = actions.all_link_actions, flag_groups = [ flag_group( iterate_over = "runtime_library_search_directories", @@ -485,7 +400,7 @@ def _impl(ctx): enabled = True, flag_sets = [ flag_set( - actions = all_link_actions, + actions = actions.all_link_actions, flag_groups = [ flag_group( flags = ["-Wl,--gdb-index"], @@ -502,7 +417,7 @@ def _impl(ctx): enabled = True, flag_sets = [ flag_set( - actions = all_link_actions, + actions = actions.all_link_actions, flag_groups = [ flag_group( iterate_over = "linkstamp_paths", @@ -520,7 +435,7 @@ def _impl(ctx): enabled = True, flag_sets = [ flag_set( - actions = all_compile_actions, + actions = actions.all_compile_actions, flag_groups = [ flag_group( iterate_over = "includes", @@ -555,7 +470,7 @@ def _impl(ctx): enabled = True, flag_sets = [ flag_set( - actions = all_link_actions, + actions = actions.all_link_actions, flag_groups = [ flag_group( flags = ["-Wl,-S"], @@ -624,7 +539,7 @@ def _impl(ctx): )], ), flag_set( - actions = all_link_actions, + actions = actions.all_link_actions, flag_groups = [flag_group(flags = ["--coverage"])], ), ], @@ -634,8 +549,7 @@ def _impl(ctx): # The order of the features is relevant, they are applied in this specific order. # A command line parameter from a feature at the end of the list will appear # after a command line parameter from a feature at the beginning of the list. - - features = [ + return [ shared.no_legacy_features_feature, compiler_library_search_paths_feature, shared.dbg_feature, @@ -686,70 +600,36 @@ def _impl(ctx): gcc_coverage_map_format_feature, ] - extra_rules_based_features = depset(ctx.attr.extra_enabled_features + ctx.attr.extra_known_features) - features.extend([convert_feature(extra_feature[FeatureInfo], enabled = extra_feature in ctx.attr.extra_enabled_features) for extra_feature in extra_rules_based_features.to_list()]) +def make_toolchain_config_info(ctx, features, action_configs, tool_paths, abi_version, target_cpu, target_os, toolchain_identifier): + sysroot = None + if ctx.attr.sysroot != None: + sysroot_files = ctx.attr.sysroot[DefaultInfo].files.to_list() + if sysroot_files: + sysroot = sysroot_files[0].path - # Get builtin include directories from attribute if provided cxx_builtin_include_directories = [] if hasattr(ctx.attr, "builtin_include_directories") and ctx.attr.builtin_include_directories: cxx_builtin_include_directories = ctx.attr.builtin_include_directories - # TODO: Once https://github.com/bazelbuild/rules_cc/issues/351 is fixed remove this. - tool_paths = [tool_path(name = "gcov", path = "gcov_wrapper")] - - 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}", + abi_version = abi_version, abi_libc_version = "unknown", builtin_sysroot = sysroot, compiler = "gcc", cxx_builtin_include_directories = cxx_builtin_include_directories, - features = features, + features = features, action_configs = action_configs, host_system_name = "local", - target_system_name = "%{tc_cpu}-%{tc_os}", - target_cpu = ctx.attr.target_cpu, + target_system_name = "{}-{}".format(target_cpu, target_os), + target_cpu = target_cpu, target_libc = "unknown", - toolchain_identifier = "%{tc_identifier}", + toolchain_identifier = toolchain_identifier, tool_paths = tool_paths, ) -cc_toolchain_config = rule( - implementation = _impl, - provides = [CcToolchainConfigInfo], - attrs = { - "ar_binary": attr.label(allow_single_file = True, executable = True, cfg = "exec", mandatory = True), - "cc_binary": attr.label(allow_single_file = True, executable = True, cfg = "exec", mandatory = True), - "cxx_binary": attr.label(allow_single_file = True, executable = True, cfg = "exec", mandatory = True), - "gcov_binary": attr.label(allow_single_file = True, executable = True, cfg = "exec", mandatory = True), - "target_cpu": attr.string(mandatory = True), - "target_os": attr.string(mandatory = True), - "strip_binary": attr.label(allow_single_file = True, executable = True, cfg = "exec", mandatory = True), - "sysroot": attr.label(default = None), - "host_dir": attr.label(default = None), - "target_dir": attr.label(default = None), - "cxx_builtin_include_directories": attr.label(allow_files = True, default = None), - "extra_enabled_features": attr.label_list( - providers = [FeatureInfo], - default = [], - doc = """ -Extra `cc_feature` features to add to this toolchain in an initially enabled state. -This attribute has limited integration with `cc_feature`, and does not run additional correctness checks or handle things like `data` files. -This is only offered as a migration bridge for projects transitioning to rule-based toolchain configurations, or sharing of simple argument sets with older toolchains. -""", - ), - "extra_known_features": attr.label_list( - providers = [FeatureInfo], - default = [], - doc = """ -Extra `cc_feature` features to add to this toolchain in an initially disabled state. -This attribute has limited integration with `cc_feature`, and does not run additional correctness checks or handle things like `data` files. -This is only offered as a migration bridge for projects transitioning to rule-based toolchain configurations, or sharing of simple argument sets with older toolchains. -""", - ), - }, -) \ No newline at end of file +EXTRA_ATTRS = { + "sysroot": attr.label(default = None), + "cxx_builtin_include_directories": attr.label(allow_files = True, default = None), +} diff --git a/templates/linux/cc_toolchain_flags.bzl.template b/templates/linux/cc_toolchain_flags.bzl.template index b42f862..eee1e3b 100644 --- a/templates/linux/cc_toolchain_flags.bzl.template +++ b/templates/linux/cc_toolchain_flags.bzl.template @@ -33,14 +33,6 @@ def get_flag_group(flags): ] return [] -# Flags that should always be applied, without filtering. -UNFILTERED_COMPILE_FLAGS = get_flag_group([ - "-D__DATE__=\"redacted\"", - "-D__TIMESTAMP__=\"redacted\"", - "-D__TIME__=\"redacted\"", - "-Wno-builtin-macro-redefined", -]) - # Default compile flags when no specific build type is selected. DEFAULT_COMPILE_FLAGS = get_flag_group([ "-U_FORTIFY_SOURCE", @@ -72,18 +64,6 @@ DEFAULT_CXX_COMPILE_FLAGS = get_flag_group([ "-std=c++17", ]) -# Debug compile flags. -DBG_COMPILE_FLAGS = get_flag_group([ - "-Og", - "-g3", -]) - -# Optimization compile flags. -OPT_COMPILE_FLAGS = get_flag_group([ - "-O2", - "-DNDEBUG", -]) - # Default link flags when no specific build type is selected. DEFAULT_LINK_FLAGS = get_flag_group([ "-lm", @@ -173,7 +153,7 @@ ALL_WALL_CXX_WARNINGS = get_flag_group([ # "-Wenum-int-mismatch", not supported in GCC12.2 # "-Wargument-mismatch", cc1plus: warning: command-line option '-Wduplicate-decl-specifier' is valid for C/ObjC but not for C++ "-Wmismatched-new-delete", - "-Woverloaded-virtual", + "-Woverloaded-virtual", # -Woverloaded-virtual=1, not supported in GCC12.2 "-Wpessimizing-move", "-Wrange-loop-construct", diff --git a/templates/qnx/cc_toolchain_config.bzl.template b/templates/qnx/cc_toolchain_config.bzl.template index c023bd2..b21775a 100644 --- a/templates/qnx/cc_toolchain_config.bzl.template +++ b/templates/qnx/cc_toolchain_config.bzl.template @@ -11,32 +11,25 @@ # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* -"""C/C++ toolchain definition""" +"""QNX-specific GCC toolchain feature factory.""" load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") -load("@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", - "action_config", +load( + "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", "env_entry", "env_set", "feature", "feature_set", "flag_group", "flag_set", - "tool", - "tool_path", - "variable_with_value", "with_feature_set", ) -load("@rules_cc//cc:defs.bzl", "cc_common", "CcToolchainConfigInfo") -load("@rules_cc//cc/toolchains:feature_injection.bzl", "convert_feature", "FeatureInfo") -load(":flags.bzl", - "UNFILTERED_COMPILE_FLAGS", +load("@rules_cc//cc:defs.bzl", "cc_common") +load(":qnx_flags.bzl", "DEFAULT_COMPILE_FLAGS", "DEFAULT_C_COMPILE_FLAGS", "DEFAULT_CXX_COMPILE_FLAGS", "DEFAULT_LINK_FLAGS", - "DBG_COMPILE_FLAGS", - "OPT_COMPILE_FLAGS", "MINIMAL_WARNINGS_FLAGS", "MINIMAL_C_WARNINGS_FLAGS", "MINIMAL_CXX_WARNINGS_FLAGS", @@ -48,125 +41,42 @@ load(":flags.bzl", "ALL_WALL_CXX_WARNINGS", "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", +load( + ":shared_features.bzl", + "make_shared_features" ) -def _impl(ctx): - """ Implementation function of GCC toolchains. - """ - - assemble_action = action_config( - action_name = ACTION_NAMES.assemble, - tools = [tool(tool = ctx.executable.cc_binary)], - ) - preprocess_assemble_action = action_config( - action_name = ACTION_NAMES.preprocess_assemble, - tools = [tool(tool = ctx.executable.cc_binary)], - ) - c_compile_action = action_config( - action_name = ACTION_NAMES.c_compile, - tools = [tool(tool = ctx.executable.cc_binary)], - ) - cpp_compile_action = action_config( - action_name = ACTION_NAMES.cpp_compile, - tools = [tool(tool = ctx.executable.cxx_binary)], - ) - cpp_link_executable_action = action_config( - action_name = ACTION_NAMES.cpp_link_executable, - tools = [tool(tool = ctx.executable.cxx_binary)], - ) - cpp_link_dynamic_library_action = action_config( - action_name = ACTION_NAMES.cpp_link_dynamic_library, - tools = [tool(tool = ctx.executable.cxx_binary)], - ) - cpp_link_nodeps_dynamic_library_action = action_config( - action_name = ACTION_NAMES.cpp_link_nodeps_dynamic_library, - tools = [tool(tool = ctx.executable.cxx_binary)], - ) - cpp_link_static_library_action = action_config( - action_name = ACTION_NAMES.cpp_link_static_library, - tools = [tool(tool = ctx.executable.ar_binary)], - implies = ["archiver_flags"], - ) - strip_action = action_config( - action_name = ACTION_NAMES.strip, - tools = [tool(tool = ctx.executable.strip_binary)], - flag_sets = [ - flag_set( - flag_groups = [ - flag_group( - flags = [ - "-g", - "-p", - ], - ), - flag_group( - iterate_over = "stripopts", - flags = ["%{stripopts}"], - ), - flag_group( - flags = [ - "%{input_file}", - "%{output_file}", - ], - ), - ], - ), - ], - ) - - action_configs = [ - assemble_action, - c_compile_action, - cpp_compile_action, - cpp_link_dynamic_library_action, - cpp_link_executable_action, - cpp_link_nodeps_dynamic_library_action, - cpp_link_static_library_action, - preprocess_assemble_action, - strip_action, - ] - - shared = make_shared_features(UNFILTERED_COMPILE_FLAGS) - - # Core linking features +def make_features(ctx, flags, actions): + shared = make_shared_features(flags.unfiltered_compile_flags) default_compile_flags_feature = feature( name = "default_compile_flags", enabled = True, flag_sets = [ flag_set( - actions = all_compile_actions, + actions = actions.all_compile_actions, flag_groups = DEFAULT_COMPILE_FLAGS, ), flag_set( - actions = all_compile_actions, + actions = actions.all_compile_actions, flag_groups = [flag_group(flags = ["-V%{tc_version},gcc_nto%{tc_cpu}"])], ), flag_set( - actions = all_c_compile_actions, + actions = actions.all_c_compile_actions, flag_groups = DEFAULT_C_COMPILE_FLAGS, ), flag_set( - actions = all_cpp_compile_actions, + actions = actions.all_cpp_compile_actions, flag_groups = DEFAULT_CXX_COMPILE_FLAGS, ), flag_set( - actions = all_compile_actions, - flag_groups = DBG_COMPILE_FLAGS, + actions = actions.all_compile_actions, + flag_groups = flags.dbg_compile_flags, with_features = [with_feature_set(features = ["dbg"])], ), flag_set( - actions = all_compile_actions, - flag_groups = OPT_COMPILE_FLAGS, + actions = actions.all_compile_actions, + flag_groups = flags.opt_compile_flags, with_features = [ with_feature_set(features = ["opt"]), with_feature_set(features = ["fastbuild"]), @@ -180,11 +90,11 @@ def _impl(ctx): enabled = True, flag_sets = [ flag_set( - actions = all_link_actions, + actions = actions.all_link_actions, flag_groups = [flag_group(flags = ["-V%{tc_version},gcc_nto%{tc_cpu}_cxx"])], ), flag_set( - actions = all_link_actions, + actions = actions.all_link_actions, flag_groups = DEFAULT_LINK_FLAGS, ), ], @@ -195,15 +105,15 @@ def _impl(ctx): enabled = True, flag_sets = [ flag_set( - actions = all_compile_actions, + actions = actions.all_compile_actions, flag_groups = MINIMAL_WARNINGS_FLAGS, ), flag_set( - actions = all_c_compile_actions, + actions = actions.all_c_compile_actions, flag_groups = MINIMAL_C_WARNINGS_FLAGS, ), flag_set( - actions = all_cpp_compile_actions, + actions = actions.all_cpp_compile_actions, flag_groups = MINIMAL_CXX_WARNINGS_FLAGS, ), ], @@ -215,15 +125,15 @@ def _impl(ctx): enabled = False, flag_sets = [ flag_set( - actions = all_compile_actions, + actions = actions.all_compile_actions, flag_groups = STRICT_WARNINGS_FLAGS, ), flag_set( - actions = all_cpp_compile_actions, + actions = actions.all_cpp_compile_actions, flag_groups = STRICT_CXX_WARNINGS_FLAGS, ), flag_set( - actions = all_c_compile_actions, + actions = actions.all_c_compile_actions, flag_groups = STRICT_C_WARNINGS_FLAGS, ), ], @@ -235,15 +145,15 @@ def _impl(ctx): enabled = False, flag_sets = [ flag_set( - actions = all_compile_actions, + actions = actions.all_compile_actions, flag_groups = ALL_WALL_WARNINGS, ), flag_set( - actions = all_c_compile_actions, + actions = actions.all_c_compile_actions, flag_groups = ALL_WALL_C_WARNINGS, ), flag_set( - actions = all_cpp_compile_actions, + actions = actions.all_cpp_compile_actions, flag_groups = ALL_WALL_CXX_WARNINGS, ), ], @@ -254,7 +164,7 @@ def _impl(ctx): enabled = False, flag_sets = [ flag_set( - actions = all_compile_actions, + actions = actions.all_compile_actions, flag_groups = WARNINGS_AS_ERRORS, ), ], @@ -267,7 +177,7 @@ def _impl(ctx): implies = ["default_compile_flags"], flag_sets = [ flag_set( - actions = all_compile_actions, + actions = actions.all_compile_actions, flag_groups = extra_compile_flags, ), ], @@ -280,7 +190,7 @@ def _impl(ctx): implies = ["default_link_flags"], flag_sets = [ flag_set( - actions = all_link_actions, + actions = actions.all_link_actions, flag_groups = extra_link_flags, ), ], @@ -291,7 +201,7 @@ def _impl(ctx): enabled = False, ) - use_license_env_info_feautre = feature( + use_license_env_info_feature = feature( name = "qnx_license_env_info", enabled = %{use_license_info}, ) @@ -304,7 +214,7 @@ def _impl(ctx): enabled = True, env_sets = [ env_set( - actions = all_compile_actions + all_link_actions, + actions = actions.all_compile_actions + actions.all_link_actions, env_entries = [ env_entry(key = "QNX_HOST", value = "/proc/self/cwd/" + ctx.file.host_dir.path), env_entry(key = "QNX_TARGET", value = "/proc/self/cwd/" + ctx.file.target_dir.path), @@ -313,10 +223,10 @@ def _impl(ctx): ], ), env_set( - actions = all_compile_actions + all_link_actions, + actions = actions.all_compile_actions + actions.all_link_actions, env_entries = [env_entry(key = license_variable, value = license_value)] if license_value != "" else [], with_features = [with_feature_set(features = ["qnx_license_env_info"])], - ) + ), ], ) @@ -376,7 +286,7 @@ def _impl(ctx): enabled = True, flag_sets = [ flag_set( - actions = all_link_actions, + actions = actions.all_link_actions, flag_groups = [ flag_group( iterate_over = "runtime_library_search_directories", @@ -410,7 +320,7 @@ def _impl(ctx): )], ), flag_set( - actions = all_link_actions, + actions = actions.all_link_actions, flag_groups = [flag_group(flags = ["-lgcov"])], ), ], @@ -420,8 +330,7 @@ def _impl(ctx): # The order of the features is relevant, they are applied in this specific order. # A command line parameter from a feature at the end of the list will appear # after a command line parameter from a feature at the beginning of the list. - - features = [ + return [ shared.dbg_feature, shared.no_legacy_features_feature, shared.unfiltered_compile_flags_feature, @@ -449,7 +358,7 @@ def _impl(ctx): extra_compile_flags_feature, extra_link_flags_feature, shared.opt_feature, - use_license_env_info_feautre, + use_license_env_info_feature, sdp_env_feature, shared.supports_dynamic_linker_feature, shared.supports_pic_feature, @@ -459,64 +368,29 @@ def _impl(ctx): gcc_coverage_map_format_feature, ] - extra_rules_based_features = depset(ctx.attr.extra_enabled_features + ctx.attr.extra_known_features) - features.extend([convert_feature(extra_feature[FeatureInfo], enabled = extra_feature in ctx.attr.extra_enabled_features) for extra_feature in extra_rules_based_features.to_list()]) - +def make_toolchain_config_info(ctx, features, action_configs, tool_paths, abi_version, target_cpu, target_os, toolchain_identifier): cxx_builtin_include_directories = [ "/proc/self/cwd/{}".format(include_directory.path) for include_directory in ctx.files.cxx_builtin_include_directories ] - - # TODO: Once https://github.com/bazelbuild/rules_cc/issues/351 is fixed remove this. - tool_paths = [tool_path(name = "gcov", path = "gcov_wrapper")] - return cc_common.create_cc_toolchain_config_info( ctx = ctx, - abi_version = "%{tc_cpu}-qnx%{sdp_version}", + abi_version = abi_version, abi_libc_version = "unknown", compiler = "qcc", cxx_builtin_include_directories = cxx_builtin_include_directories, - features = features, + features = features, action_configs = action_configs, host_system_name = "local", - target_system_name = "%{tc_cpu}-qnx", - target_cpu = "%{tc_cpu}", + target_system_name = "{}-{}".format(target_cpu, target_os), + target_cpu = target_cpu, target_libc = "unknown", - toolchain_identifier = "%{tc_cpu}-qnx%{sdp_version}", + toolchain_identifier = toolchain_identifier, tool_paths = tool_paths, ) -cc_toolchain_config = rule( - implementation = _impl, - provides = [CcToolchainConfigInfo], - attrs = { - "ar_binary": attr.label(allow_single_file = True, executable = True, cfg = "exec", mandatory = True), - "cc_binary": attr.label(allow_single_file = True, executable = True, cfg = "exec", mandatory = True), - "cxx_binary": attr.label(allow_single_file = True, executable = True, cfg = "exec", mandatory = True), - "gcov_binary": attr.label(allow_single_file = True, executable = True, cfg = "exec", mandatory = True), - "strip_binary": attr.label(allow_single_file = True, executable = True, cfg = "exec", mandatory = True), - "host_dir": attr.label(allow_single_file = True, mandatory = True), - "target_dir": attr.label(allow_single_file = True, mandatory = True), - "target_cpu": attr.string(mandatory = True), - "target_os": attr.string(mandatory = True), - "cxx_builtin_include_directories": attr.label(allow_files = True, mandatory = True), - "extra_enabled_features": attr.label_list( - providers = [FeatureInfo], - default = [], - doc = """ -Extra `cc_feature` features to add to this toolchain in an initially enabled state. -This attribute has limited integration with `cc_feature`, and does not run additional correctness checks or handle things like `data` files. -This is only offered as a migration bridge for projects transitioning to rule-based toolchain configurations, or sharing of simple argument sets with older toolchains. -""", - ), - "extra_known_features": attr.label_list( - providers = [FeatureInfo], - default = [], - doc = """ -Extra `cc_feature` features to add to this toolchain in an initially disabled state. -This attribute has limited integration with `cc_feature`, and does not run additional correctness checks or handle things like `data` files. -This is only offered as a migration bridge for projects transitioning to rule-based toolchain configurations, or sharing of simple argument sets with older toolchains. -""", - ), - }, -) +EXTRA_ATTRS = { + "cxx_builtin_include_directories": attr.label(allow_files = True, mandatory = True), + "host_dir": attr.label(allow_single_file = True, mandatory = True), + "target_dir": attr.label(allow_single_file = True, mandatory = True), +} diff --git a/templates/qnx/cc_toolchain_flags.bzl.template b/templates/qnx/cc_toolchain_flags.bzl.template index ba18bc6..810fc47 100644 --- a/templates/qnx/cc_toolchain_flags.bzl.template +++ b/templates/qnx/cc_toolchain_flags.bzl.template @@ -33,14 +33,6 @@ def get_flag_group(flags): ] return [] -# Flags that should always be applied, without filtering. -UNFILTERED_COMPILE_FLAGS = get_flag_group([ - "-D__DATE__=\"redacted\"", - "-D__TIMESTAMP__=\"redacted\"", - "-D__TIME__=\"redacted\"", - "-Wno-builtin-macro-redefined", -]) - # Default compile flags when no specific build type is selected. DEFAULT_COMPILE_FLAGS = get_flag_group([ "-fno-canonical-system-headers", @@ -57,18 +49,6 @@ DEFAULT_CXX_COMPILE_FLAGS = get_flag_group([ "-std=c++17", ]) -# Debug compile flags. -DBG_COMPILE_FLAGS = get_flag_group([ - "-Og", - "-g3", -]) - -# Optimization compile flags. -OPT_COMPILE_FLAGS = get_flag_group([ - "-O2", - "-DNDEBUG", -]) - # Default link flags when no specific build type is selected. DEFAULT_LINK_FLAGS = get_flag_group([ "-Wl,-z,relro", diff --git a/templates/shared/BUILD b/templates/shared/BUILD new file mode 100644 index 0000000..e69de29 diff --git a/templates/cc_toolchain_shared_features.bzl.template b/templates/shared/cc_toolchain_shared_features.bzl.template similarity index 100% rename from templates/cc_toolchain_shared_features.bzl.template rename to templates/shared/cc_toolchain_shared_features.bzl.template diff --git a/tests/MODULE.bazel.lock b/tests/MODULE.bazel.lock index 6fe2457..ed00968 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": "dSSh8n3cAOdwaMVKE/KXyuS+8dOvtBntngyzfLzpMMk=", "usagesDigest": "dWr2zFjJ8fBvweFk2KWoZzQqJ+aKnb9A8QACQhKlUfw=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, @@ -1507,9 +1507,9 @@ "tc_system_toolchain": false, "tc_runtime_ecosystem": "", "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", + "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_config.bzl.template", + "cc_toolchain_flags": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_flags.bzl.template", + "cc_toolchain_shared_features": "@@score_bazel_cpp_toolchains+//templates/shared:cc_toolchain_shared_features.bzl.template", "use_base_constraints_only": true } }, @@ -1535,9 +1535,9 @@ "tc_system_toolchain": false, "tc_runtime_ecosystem": "", "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", + "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_config.bzl.template", + "cc_toolchain_flags": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_flags.bzl.template", + "cc_toolchain_shared_features": "@@score_bazel_cpp_toolchains+//templates/shared:cc_toolchain_shared_features.bzl.template", "use_base_constraints_only": false } }, @@ -1563,9 +1563,9 @@ "tc_system_toolchain": false, "tc_runtime_ecosystem": "", "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", + "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_config.bzl.template", + "cc_toolchain_flags": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_flags.bzl.template", + "cc_toolchain_shared_features": "@@score_bazel_cpp_toolchains+//templates/shared:cc_toolchain_shared_features.bzl.template", "use_base_constraints_only": false } }, @@ -1591,9 +1591,9 @@ "tc_system_toolchain": false, "tc_runtime_ecosystem": "", "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", + "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_config.bzl.template", + "cc_toolchain_flags": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_flags.bzl.template", + "cc_toolchain_shared_features": "@@score_bazel_cpp_toolchains+//templates/shared:cc_toolchain_shared_features.bzl.template", "use_base_constraints_only": false } }, @@ -1619,9 +1619,9 @@ "tc_system_toolchain": false, "tc_runtime_ecosystem": "", "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", + "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_config.bzl.template", + "cc_toolchain_flags": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_flags.bzl.template", + "cc_toolchain_shared_features": "@@score_bazel_cpp_toolchains+//templates/shared:cc_toolchain_shared_features.bzl.template", "use_base_constraints_only": false } }, @@ -1649,9 +1649,9 @@ "tc_system_toolchain": false, "tc_runtime_ecosystem": "", "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", + "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_config.bzl.template", + "cc_toolchain_flags": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_flags.bzl.template", + "cc_toolchain_shared_features": "@@score_bazel_cpp_toolchains+//templates/shared:cc_toolchain_shared_features.bzl.template", "use_base_constraints_only": false } }, @@ -1677,9 +1677,9 @@ "tc_system_toolchain": false, "tc_runtime_ecosystem": "", "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", + "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_config.bzl.template", + "cc_toolchain_flags": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_flags.bzl.template", + "cc_toolchain_shared_features": "@@score_bazel_cpp_toolchains+//templates/shared:cc_toolchain_shared_features.bzl.template", "use_base_constraints_only": false } }, @@ -1705,9 +1705,9 @@ "tc_system_toolchain": false, "tc_runtime_ecosystem": "", "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", + "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_config.bzl.template", + "cc_toolchain_flags": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_flags.bzl.template", + "cc_toolchain_shared_features": "@@score_bazel_cpp_toolchains+//templates/shared:cc_toolchain_shared_features.bzl.template", "use_base_constraints_only": false } }, @@ -1769,9 +1769,9 @@ "tc_system_toolchain": false, "tc_runtime_ecosystem": "autosd10", "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", + "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_config.bzl.template", + "cc_toolchain_flags": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_flags.bzl.template", + "cc_toolchain_shared_features": "@@score_bazel_cpp_toolchains+//templates/shared:cc_toolchain_shared_features.bzl.template", "use_base_constraints_only": false } }, @@ -1849,9 +1849,9 @@ "tc_system_toolchain": false, "tc_runtime_ecosystem": "ebclfsa", "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", + "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_config.bzl.template", + "cc_toolchain_flags": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_flags.bzl.template", + "cc_toolchain_shared_features": "@@score_bazel_cpp_toolchains+//templates/shared:cc_toolchain_shared_features.bzl.template", "use_base_constraints_only": false } }