Skip to content

Conversation

@martin4861
Copy link
Contributor

@martin4861 martin4861 commented Oct 23, 2025

Previously compile options have been added to copts by the macros cc_library. Those compile options are meant for compilers like clang or gcc. This tight coupling of macros and compile options makes it impossible to implement any other compiler toolchains, which do not use gcc's or clang's compile options.

To overcome this problem this tight coupling needs to be relaxed. In order to do so, we use Bazel's features. A feature is implemented as follows:

swift_rtti_feature = feature(
    name = "rtti_feature",
    flag_sets = [
        flag_set(
            actions = [ACTION_NAMES.cpp_compile],
            flag_groups = [flag_group(flags = ["-frtti"])],
        ),
    ],
)

Different toolchains might have different compile options for features and are using the abstraction layer using feature.

The features can be simplify activated using cc_library(..., features = ["rtti_feature"], ...). The activation is handled by the macros in defs2.bzl.

This PR consists of multiple changes:

  • toolchains now implement the features for compile option selection by the macros.
  • the new macros in defs2.bzl support the selection of features, whereas the legacy macros in defs.bzl stay unchanged.
  • defs2.bzl provides new macros, which set different levels of features, depending on the needed coding quality level (see the extensive doc in defs2.bzl.)

@martin4861 martin4861 force-pushed the martin4861/bazel-compiler-flags-with-tests branch from febf6e1 to 6215f56 Compare October 23, 2025 16:22
@martin4861 martin4861 force-pushed the martin4861/bazel-compiler-flags-with-tests branch from 6215f56 to eeead94 Compare October 24, 2025 13:38
@martin4861 martin4861 force-pushed the martin4861/bazel-compiler-flags-with-tests branch 2 times, most recently from a242f07 to eeead94 Compare November 20, 2025 09:33
@martin4861 martin4861 marked this pull request as ready for review November 20, 2025 14:52
@martin4861 martin4861 requested review from a team as code owners November 20, 2025 14:52
@martin4861 martin4861 requested review from sbmueller and removed request for a team November 20, 2025 14:52
@martin4861 martin4861 force-pushed the martin4861/bazel-compiler-flags-with-tests branch from c1726eb to 003475e Compare November 20, 2025 15:24
@sbmueller sbmueller removed their request for review November 21, 2025 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants