Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.6.0
8.7.0
4 changes: 2 additions & 2 deletions .github/workflows/autosd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
cache-save: ${{ github.event_name == 'push' }}
- name: Bazel Build (basic)
run: |
bazel build --lockfile_mode=error --config=x86_64-linux-autosd10 -- //:language_and_standards_tests //:feature_verification_tests
bazel build --lockfile_mode=error --config=x86_64-linux-autosd10 --features=-default_link_flags -- //:language_and_standards_tests //:feature_verification_tests
- name: Guardrail (no legacy features)
run: |
bazel test --lockfile_mode=error --config=x86_64-linux-autosd10 -- //:guardrail_tests
bazel test --lockfile_mode=error --config=x86_64-linux-autosd10 --features=-default_link_flags -- //:guardrail_tests
8 changes: 3 additions & 5 deletions docs/generation_flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,23 @@ representation needed by the templates and repository rules.

Generates the toolchain repository. It decides whether Linux or QNX template
content is required, performs placeholder substitution, and emits the final
`BUILD`, `cc_toolchain_config.bzl`, `flags.bzl`, and Linux `gcov` wrapper
`BUILD`, `cc_toolchain_config.bzl`, and Linux `gcov` wrapper
files.

## Template Families

Linux templates:

- `templates/linux/cc_toolchain_config.bzl.template`
- `templates/linux/cc_toolchain_flags.bzl.template`
- `templates/linux/cc_gcov_wrapper.template`

QNX templates:

- `templates/qnx/cc_toolchain_config.bzl.template`
- `templates/qnx/cc_toolchain_flags.bzl.template`

Shared template:
Shared templates:

- `templates/BUILD.template`
- `templates/cc_gcov_wrapper.template`

## Important Implementation Details

Expand Down
60 changes: 60 additions & 0 deletions docs/maintenance.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,66 @@ means a broken build rather than a silent fallback.
> libraries (e.g. AutoSD) cannot link fully static binaries, so that feature is
> opt-in and its test is marked incompatible with such platforms.

## In-Progress: Declarative `features/` Catalog

`features/` defines the same toolchain features declaratively with
`@rules_cc//cc/toolchains` (`cc_feature` / `cc_args` / `cc_feature_set`), as a
parallel catalog alongside the legacy `feature()` Starlark in
`templates/*/cc_toolchain_config.bzl.template`. The **real** toolchain
generation still goes exclusively through the legacy templates, rendered by
`rules/gcc.bzl`; nothing in the repository currently consumes
`//features:linux_features` or `//features:qnx_features`.

`features/BUILD` defines two ordered `cc_feature_set` targets, `linux_features`
and `qnx_features`, whose `all_of` order intentionally mirrors the exact
feature order in the corresponding template's `features = [...]` list (order is
significant there — see the "order of the features is relevant" comment in both
templates). Platform membership (Linux-only vs. QNX-only vs. both) is expressed
purely by which set a feature is listed in; individual `cc_feature` targets no
longer carry `requires_any_of = ["//features/linux_platform"]` /
`["//features/qnx_platform"]` gates. `all_wall_warnings`, `minimal_warnings`,
`strict_warnings`, and `warnings_as_errors` were removed from `features/`
entirely — they are superseded by `score_cpp_policies` and injected via
`extra_known_features` / `extra_enabled_features` instead.

### Open problem: the `extra_*_flags` hooks

`extra_compile_flags`, `extra_c_compile_flags`, `extra_cxx_compile_flags`, and
`extra_link_flags` are intentionally **not** part of `linux_features` /
`qnx_features` yet. They don't fit the static-label model the rest of
`features/` uses:

- **Content is dynamic per toolchain instance.** The flag lists come from
`gcc.toolchain(extra_compile_flags = [...])` (see `extensions/gcc.bzl`) and
are substituted via `%{...}` placeholders directly into the generated
`cc_toolchain_config.bzl` by `rules/gcc.bzl` (`_impl`, `get_flag_groups()`) —
not a fixed BUILD label a `cc_feature_set` could reference.
- **Position is order-sensitive.** `extra_compile_flags` /
`extra_c_compile_flags` / `extra_cxx_compile_flags` must land after
`preprocessor_defines` / `default_compile_flags` and before
`user_compile_flags`; `extra_link_flags` must land near the end, after
`user_link_flags`. The existing `extra_known_features` /
`extra_enabled_features` injection mechanism (used for `score_cpp_policies`
sanitizers/warnings) always appends via `features.extend(...)` at the very
end of the list — safe for position-independent features, unsafe for these.

Options considered, decision still pending:

1. **Leave as-is.** Keep the raw `%{...}` template-substitution mechanism
exactly as today; a static label structurally can't hold per-invocation
dynamic content, so these 4 simply stay outside the `features/` catalog.
Zero risk, matches current shipped behavior.
2. **Label-typed "slots".** Add label attributes (e.g.
`extra_compile_flags_target = attr.label(providers = [CcArgsInfo])`) to the
toolchain config rule. The caller defines their own small `cc_args`/
`cc_feature` target with whatever flags they want and passes its label in;
the rule splices that label into the fixed position within the ordered
feature list — same trick as `extra_known_features`, but inserted at an
index instead of appended at the end. Preserves both order (repo controls
position) and dynamism (caller controls content). This is a real API change
touching `extensions/gcc.bzl` attrs, `rules/gcc.bzl` codegen, and
`docs/extension_api.md`.

## Common Gotchas

- runtime-specific toolchains may need extra include and link flags that do not
Expand Down
2 changes: 0 additions & 2 deletions extensions/gcc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ def _get_toolchains(tags):
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),
"gcc_version": tag.version,
"name": tag.name,
"use_base_constraints_only": tag.use_base_constraints_only,
Expand Down Expand Up @@ -416,7 +415,6 @@ def _impl(mctx):
tc_runtime_ecosystem = toolchain_info["tc_runtime_ecosystem"],
gcc_version = toolchain_info["gcc_version"],
cc_toolchain_config = toolchain_info["cc_toolchain_config"],
cc_toolchain_flags = toolchain_info["cc_toolchain_flags"],
use_base_constraints_only = toolchain_info["use_base_constraints_only"],
)

Expand Down
99 changes: 99 additions & 0 deletions features/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# *******************************************************************************
# 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
# *******************************************************************************

load("@rules_cc//cc/toolchains:feature_set.bzl", "cc_feature_set")

# Order mirrors templates/linux/cc_toolchain_config.bzl.template's `features = [...]` list,
# since feature order determines command-line flag order.
cc_feature_set(
name = "linux",
all_of = [
"//features/native/markers:no_legacy_features",
"//features/native/compiler_library_search_paths",
"//features/native/markers:dbg",
"//features/native/unfiltered_compile_flags",
"//features/native/markers:gnu11",
"//features/native/default_compile_flags",
"//features/native/random_seed",
"//features/native/include_paths",
"//features/native/preprocessor_defines",
"//features/native/user_compile_flags",
"//features/native/compiler_input_flags",
"//features/native/compiler_output_flags",
"//features/native/dependency_file",
"//features/native/per_object_debug_info",
"//features/native/includes",
"//features/native/default_link_flags",
"//features/native/archiver_flags",
"//features/native/linker_param_file",
"//features/native/library_search_directories",
"//features/native/shared_flag",
"//features/native/output_execpath_flags",
"//features/native/runtime_library_search_directories",
"//features/native/libraries_to_link",
"//features/native/user_link_flags",
"//features/native/linkstamps",
"//features/native/fission_support",
"//features/native/force_pic_flags",
"//features/native/strip_debug_symbols",
"//features/native/static_libgcc",
"//features/native/fully_static_link",
"//features/native/sysroot_link_flags",
"//features/native/use_pthread",
"//features/native/markers:opt",
"//features/native/markers:supports_dynamic_linker",
"//features/native/markers:supports_pic",
"//features/native/pic",
"//features/native/markers:supports_header_path_normalization",
"//features/native/markers:supports_fission",
"//features/native/markers:coverage",
"//features/native/gcc_coverage_map_format",
],
visibility = ["//visibility:public"],
)

# Order mirrors templates/qnx/cc_toolchain_config.bzl.template's `features = [...]` list,
# since feature order determines command-line flag order.
cc_feature_set(
name = "qnx",
all_of = [
"//features/native/markers:dbg",
"//features/native/markers:no_legacy_features",
"//features/native/unfiltered_compile_flags",
"//features/native/default_compile_flags",
"//features/native/random_seed",
"//features/native/include_paths",
"//features/native/preprocessor_defines",
"//features/native/user_compile_flags",
"//features/native/compiler_input_flags",
"//features/native/compiler_output_flags",
"//features/native/markers:dependency_file_named_implicitly",
"//features/native/dependency_file",
"//features/native/default_link_flags",
"//features/native/archiver_flags",
"//features/native/linker_param_file",
"//features/native/library_search_directories",
"//features/native/shared_flag",
"//features/native/output_execpath_flags",
"//features/native/libraries_to_link",
"//features/native/user_link_flags",
"//features/native/markers:coverage",
"//features/native/markers:opt",
"//features/native/markers:supports_dynamic_linker",
"//features/native/markers:supports_pic",
"//features/native/pic",
"//features/native/runtime_library_search_directories",
"//features/native/gcc_coverage_map_format",
],
visibility = ["//visibility:public"],
)
Empty file added features/custom/linux/BUILD
Empty file.
75 changes: 75 additions & 0 deletions features/custom/linux/make_cc_features.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# *******************************************************************************
# 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
# *******************************************************************************

_LINUX_FEATURES = [
("@score_bazel_cpp_toolchains//features/native/markers:no_legacy_features", True),
(":compiler_library_search_paths", True), # per-instance, see templates/BUILD.template
("@score_bazel_cpp_toolchains//features/native/markers:dbg", False), # Bazel auto-toggles via -c dbg
("@score_bazel_cpp_toolchains//features/native/unfiltered_compile_flags", True),
("@score_bazel_cpp_toolchains//features/native/markers:gnu11", False), # opt-in
("@score_bazel_cpp_toolchains//features/native/default_compile_flags", True),
("@score_bazel_cpp_toolchains//features/native/random_seed", True),
("@score_bazel_cpp_toolchains//features/native/include_paths", True),
("@score_bazel_cpp_toolchains//features/native/preprocessor_defines", True),
(":extra_compile_flags", True), # per-instance, see templates/BUILD.template
(":extra_c_compile_flags", True), # per-instance, see templates/BUILD.template
(":extra_cxx_compile_flags", True), # per-instance, see templates/BUILD.template
("@score_bazel_cpp_toolchains//features/native/user_compile_flags", True),
("@score_bazel_cpp_toolchains//features/native/compiler_input_flags", True),
("@score_bazel_cpp_toolchains//features/native/compiler_output_flags", True),
("@score_bazel_cpp_toolchains//features/native/dependency_file", True),
("@score_bazel_cpp_toolchains//features/native/per_object_debug_info", True),
("@score_bazel_cpp_toolchains//features/native/includes", True),
("@score_bazel_cpp_toolchains//features/native/default_link_flags", True),
("@score_bazel_cpp_toolchains//features/native/archiver_flags", True),
("@score_bazel_cpp_toolchains//features/native/linker_param_file", True),
("@score_bazel_cpp_toolchains//features/native/library_search_directories", True),
("@score_bazel_cpp_toolchains//features/native/shared_flag", True),
("@score_bazel_cpp_toolchains//features/native/output_execpath_flags", True),
("@score_bazel_cpp_toolchains//features/native/runtime_library_search_directories", True),
("@score_bazel_cpp_toolchains//features/native/libraries_to_link", True),
("@score_bazel_cpp_toolchains//features/native/user_link_flags", True),
(":extra_link_flags", True), # per-instance, see templates/BUILD.template
("@score_bazel_cpp_toolchains//features/native/linkstamps", True),
("@score_bazel_cpp_toolchains//features/native/fission_support", True),
("@score_bazel_cpp_toolchains//features/native/force_pic_flags", True),
("@score_bazel_cpp_toolchains//features/native/strip_debug_symbols", True),
("@score_bazel_cpp_toolchains//features/native/static_libgcc", True),
("@score_bazel_cpp_toolchains//features/native/fully_static_link", False), # opt-in
(":sysroot_link_flags", True), # per-instance, see templates/BUILD.template
("@score_bazel_cpp_toolchains//features/native/use_pthread", True),
("@score_bazel_cpp_toolchains//features/native/markers:opt", False), # Bazel auto-toggles via -c opt
("@score_bazel_cpp_toolchains//features/native/markers:supports_dynamic_linker", True),
("@score_bazel_cpp_toolchains//features/native/markers:supports_pic", True),
("@score_bazel_cpp_toolchains//features/native/pic", True),
("@score_bazel_cpp_toolchains//features/native/markers:supports_header_path_normalization", True),
("@score_bazel_cpp_toolchains//features/native/markers:supports_fission", True),
("@score_bazel_cpp_toolchains//features/native/markers:coverage", False), # opt-in
("@score_bazel_cpp_toolchains//features/native/gcc_coverage_map_format", False), # opt-in (+ requires "coverage")
]

def linux_known_features():
"""Full ordered list of Linux feature labels — order drives flag order."""
return [label for label, _enabled in _LINUX_FEATURES]

def linux_enabled_features():
"""Subset of Linux feature labels that start enabled — order is irrelevant here."""
return [label for label, enabled in _LINUX_FEATURES if enabled]

def get_feature_lists():
"""Returns the flat known/enabled feature label lists for Linux.

Returns:
(known_features, enabled_features) tuple of flat label lists.
"""
return linux_known_features(), linux_enabled_features()
Empty file added features/custom/qnx/BUILD
Empty file.
43 changes: 43 additions & 0 deletions features/custom/qnx/gcc_version_flags/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# *******************************************************************************
# 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
# *******************************************************************************

load("@rules_cc//cc/toolchains:args.bzl", "cc_args")
load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature")

cc_args(
name = "qnx_gcc_version_compile_args",
actions = ["@rules_cc//cc/toolchains/actions:compile_actions"],
args = select({
"@score_bazel_platforms//settings:aarch64-qnx8": ["-V12.2.0,gcc_ntoaarch64le"],
"@score_bazel_platforms//settings:x86_64-qnx8": ["-V12.2.0,gcc_ntox86_64"],
}),
)

cc_args(
name = "qnx_gcc_version_link_args",
actions = ["@rules_cc//cc/toolchains/actions:link_actions"],
args = select({
"@score_bazel_platforms//settings:aarch64-qnx8": ["-V12.2.0,gcc_ntoaarch64le_cxx"],
"@score_bazel_platforms//settings:x86_64-qnx8": ["-V12.2.0,gcc_ntox86_64_cxx"],
}),
)

cc_feature(
name = "gcc_version_flags",
args = [
":qnx_gcc_version_compile_args",
":qnx_gcc_version_link_args",
],
feature_name = "gcc_version_flags",
visibility = ["//visibility:public"],
)
Loading