diff --git a/.github/workflows/autosd.yml b/.github/workflows/autosd.yml index 89260af..ff90bfc 100644 --- a/.github/workflows/autosd.yml +++ b/.github/workflows/autosd.yml @@ -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 diff --git a/docs/features.md b/docs/features.md index 486880e..bb20348 100644 --- a/docs/features.md +++ b/docs/features.md @@ -1,9 +1,7 @@ # Toolchain Features -These are the `cc_toolchain` features defined by the toolchain configs in -[`templates/linux/cc_toolchain_config.bzl.template`](../templates/linux/cc_toolchain_config.bzl.template) -and -[`templates/qnx/cc_toolchain_config.bzl.template`](../templates/qnx/cc_toolchain_config.bzl.template). +These are the `cc_toolchain` features defined by the shared toolchain config in +[`templates/cc_toolchain_config.bzl.template`](../templates/cc_toolchain_config.bzl.template). Both toolchains enable **`no_legacy_features`**, which turns off the features Bazel would otherwise add implicitly. As a result every flag the toolchain emits diff --git a/docs/generation_flow.md b/docs/generation_flow.md index 2c6820e..4542c66 100644 --- a/docs/generation_flow.md +++ b/docs/generation_flow.md @@ -23,10 +23,15 @@ toolchain repository through these steps: 1. `extensions/gcc.bzl` collects `gcc.toolchain` and `gcc.sdp` tags. 2. Package metadata is resolved from `packages/version_matrix.bzl` or from an explicit `gcc.sdp` declaration. -3. `rules/gcc.bzl` renders a BUILD file and configuration files into a new - repository. -4. Platform-specific templates from `templates/linux/` or `templates/qnx/` are - populated with CPU, version, licensing, and flag information. +3. `rules/gcc.bzl` renders the shared `templates/BUILD.template` and + `templates/cc_toolchain_config.bzl.template` into a new repository, + substituting CPU, version, licensing, and flag placeholders. +4. The rendered `BUILD` file wires in the toolchain's feature set: + per-instance features created at generation time (extra compile/link + flags, sysroot link flags, compiler library search paths) plus the + ordered `known_features`/`enabled_features` lists from + `features/custom/linux/` or `features/custom/qnx/`, which reference the + reusable `cc_feature` targets under `features/native/`. 5. The consuming workspace enables the generated toolchain with `--extra_toolchains` and compatible platform constraints. @@ -44,27 +49,26 @@ representation needed by the templates and repository rules. `rules/gcc.bzl` -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 -files. +Generates the toolchain repository. It performs placeholder substitution and +emits the final `BUILD`, `cc_toolchain_config.bzl`, and `gcov` wrapper files, +substituting OS-specific values (e.g. `compiler`, `abi_version`, +`toolchain_identifier`) into the shared templates below. -## Template Families - -Linux templates: +`features/` -- `templates/linux/cc_toolchain_config.bzl.template` -- `templates/linux/cc_toolchain_flags.bzl.template` -- `templates/linux/cc_gcov_wrapper.template` +Defines the toolchain's `cc_feature` / `cc_args` targets with +`@rules_cc//cc/toolchains`. `features/native/` holds one reusable target per +toolchain feature; `features/custom/linux/` and `features/custom/qnx/` hold +OS-specific features plus the ordered `known_features`/`enabled_features` +lists that `templates/BUILD.template` passes to `cc_toolchain_config`. -QNX templates: - -- `templates/qnx/cc_toolchain_config.bzl.template` -- `templates/qnx/cc_toolchain_flags.bzl.template` +## Template Families -Shared template: +Shared templates (used by both Linux and QNX): +- `templates/cc_toolchain_config.bzl.template` - `templates/BUILD.template` +- `templates/cc_gcov_wrapper.template` ## Important Implementation Details diff --git a/docs/maintenance.md b/docs/maintenance.md index 2a91f65..a5b65ef 100644 --- a/docs/maintenance.md +++ b/docs/maintenance.md @@ -73,6 +73,59 @@ 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. +## Toolchain Feature Catalog (`features/`) + +`features/` is the live source of the toolchain's `cc_feature` / `cc_args` +definitions, built with `@rules_cc//cc/toolchains`. It replaced the legacy +`feature()` Starlark calls that used to live directly in the per-OS +`cc_toolchain_config.bzl.template` files; `templates/cc_toolchain_config.bzl.template` +now only implements the `cc_toolchain_config` rule and turns +`known_features`/`enabled_features` labels into the toolchain's feature list — +it defines no features of its own. + +- `features/native/`: one reusable `cc_feature`/`cc_args` target per toolchain + feature (`default_compile_flags`, `include_paths`, `pic`, + `sysroot_link_flags`, ...), including the capability markers (`dbg`, `opt`, + `supports_pic`, ...). These mirror the removed legacy Bazel C++ features + one-for-one. +- `features/custom/linux/` and `features/custom/qnx/`: OS-specific features + not covered by the native set (QNX `sdp_env`, `gcc_version_flags`), plus + `make_cc_features.bzl`, which defines the ordered `_LINUX_FEATURES` / + `_QNX_FEATURES` lists of `(label, initially_enabled)` pairs. Order here + mirrors the previous templates' `features = [...]` order exactly, since + feature order determines command-line flag order. `get_feature_lists()` + returns `(known_features, enabled_features)`, and `templates/BUILD.template` + passes those straight into `cc_toolchain_config`'s `known_features` / + `enabled_features` attributes — this is what the generated toolchain + actually uses. +- Per-instance features whose content is dynamic per toolchain instance — + `extra_compile_flags`, `extra_c_compile_flags`, `extra_cxx_compile_flags`, + `extra_link_flags`, `compiler_library_search_paths`, `sysroot_link_flags` — + are *not* static `features/native/*` targets. Instead + `templates/BUILD.template` creates them at generation time (via + `make_extra_compile_features()`, `make_extra_link_features()`, + `make_compiler_library_search_paths()`, and `make_sysroot_link_flags()`, all + defined under `features/native//features.bzl`) using fixed local + target names (`:extra_compile_flags`, etc.), and `_LINUX_FEATURES` / + `_QNX_FEATURES` reference those fixed names at the correct position in the + ordered list. This keeps both feature order (repo-controlled) and + per-instance dynamic content (caller-controlled via `gcc.toolchain(...)` + attributes). +- `all_wall_warnings`, `minimal_warnings`, `strict_warnings`, and + `warnings_as_errors` are not defined anywhere in this repository — they were + removed and are superseded by `score_cpp_policies`, injected via + `extra_known_features` / `extra_enabled_features` (same mechanism as the + sanitizers). + +> **Known cleanup item:** `features/BUILD` also defines two `cc_feature_set` +> targets (`linux` and `qnx`) that group the same features for +> `requires_any_of`/`requires_all_of`-style constraints. Nothing in this +> repository currently references them — `cc_toolchain_config`'s +> `known_features`/`enabled_features` attributes require individual +> `FeatureInfo`-providing labels, not a `cc_feature_set` grouping (see the +> `compute_feature_lists()` docstring in `features/make_cc_features.bzl`). +> These should either be wired to a consumer or removed. + ## Common Gotchas - runtime-specific toolchains may need extra include and link flags that do not diff --git a/docs/migration_guide.md b/docs/migration_guide.md index 17e40ef..b5c5a22 100644 --- a/docs/migration_guide.md +++ b/docs/migration_guide.md @@ -56,18 +56,15 @@ reproducible toolchain: ### The explicit (current) model -Both toolchain configs set: - -```starlark -no_legacy_features_feature = feature(name = "no_legacy_features", enabled = True) -``` +Both toolchain configs always enable `no_legacy_features` — a `cc_feature` +defined in `features/native/markers` and listed as initially-enabled in the +ordered feature list built by `features/custom/linux/make_cc_features.bzl` / +`features/custom/qnx/make_cc_features.bzl`. With this enabled, Bazel injects **nothing** implicitly. Every compile, link, and archive flag must come from a feature (or other toolchain wiring) declared -explicitly in -[`templates/linux/cc_toolchain_config.bzl.template`](../templates/linux/cc_toolchain_config.bzl.template) -or -[`templates/qnx/cc_toolchain_config.bzl.template`](../templates/qnx/cc_toolchain_config.bzl.template). +explicitly under [`features/`](../features) and wired in by +[`templates/cc_toolchain_config.bzl.template`](../templates/cc_toolchain_config.bzl.template). The practical consequence: the command line is now fully described by this repository's feature set. What you see documented in @@ -95,8 +92,8 @@ toolchain, are summarized below. | `--sysroot` handling | **Supported, explicit (Linux)** | `sysroot_link_flags` at link; compile relies on `cxx_builtin_include_directories` | | Compiler / archiver / strip tool binding | **Supported, wiring** | `action_config` entries, not legacy `tool_paths` | | `gcov` | **Supported, wiring** | `tool_paths` (`gcov_wrapper`) | -| Warnings (e.g. `-Wall`) added by default | **Linux: opt-in · QNX: on by default** | `minimal_warnings` (includes `-Wall`) is enabled by default on QNX but disabled on Linux. `strict_warnings` / `all_wall_warnings` are opt-in on both. | -| `-Werror` | **Not implicit — opt-in** | `warnings_as_errors` (disabled by default) | +| Warnings (e.g. `-Wall`) added by default | **Not part of this toolchain — injected** | `minimal_warnings` / `strict_warnings` / `all_wall_warnings` are defined by `score_cpp_policies`, not this toolchain, and only become available once brought in via `extra_known_features` / `extra_enabled_features`. | +| `-Werror` | **Not part of this toolchain — injected** | `warnings_as_errors`, defined by `score_cpp_policies` and injected the same way as the other warning features. | | Sanitizers (asan/lsan/tsan/ubsan) | **Not part of this toolchain — injected (Linux)** | Defined by `score_cpp_policies` (`score_asan` / `score_lsan` / `score_tsan` / `score_ubsan`) and brought in via `extra_known_features` / `extra_enabled_features` | | Fully static link (`-static`) | **Not implicit — opt-in** | `fully_static_link` (disabled by default) | | `-pthread` | **Not implicit — opt-in (Linux)** | `use_pthread` (disabled by default) | @@ -106,11 +103,11 @@ toolchain, are summarized below. Three categories deserve special attention because they are the most frequent migration surprises: -1. **Warnings differ by platform.** On **Linux**, all warning features are - opt-in — if you expected `-Wall`-style warnings you must enable them. On - **QNX**, `minimal_warnings` (which includes `-Wall`) is enabled by default, - so those warnings do *not* disappear; `strict_warnings`, - `all_wall_warnings`, and `-Werror` remain opt-in on both platforms. +1. **Warnings are not part of this toolchain on either platform.** All + warning-level features (`minimal_warnings`, `strict_warnings`, + `all_wall_warnings`, `warnings_as_errors`/`-Werror`) are defined by + `score_cpp_policies` and only become available once injected via + `extra_known_features` / `extra_enabled_features`. 2. **`-pthread` and fully-static linking are opt-in.** These emit nothing until you enable the corresponding feature. 3. **Sanitizers are not part of this toolchain.** They are defined by the @@ -212,13 +209,21 @@ now?" case. **Symptom:** Code that used to warn (or fail on warnings) now builds clean. -**Cause:** On **Linux**, all warning features are opt-in, so nothing is added by -default under `no_legacy_features`. On **QNX**, `minimal_warnings` (`-Wall`) is -enabled by default, but `strict_warnings`, `all_wall_warnings`, and `-Werror` -are still opt-in — so stricter diagnostics can still appear to "disappear". +**Cause:** Warning-level features are not defined by this toolchain at all — +they are defined by `score_cpp_policies` and are only available once injected +into the toolchain via `extra_known_features` / `extra_enabled_features` (see +[Extension API](extension_api.md#feature-injection)). -**Fix:** Enable the warning features you want. To restore a strict, fail-fast -profile build-wide: +**Fix:** Inject the desired warning feature(s) from `score_cpp_policies` on +`gcc.toolchain(...)`, then enable them like any other feature: + +```starlark +gcc.toolchain( + name = "score_gcc_toolchain", + ... + extra_known_features = ["@score_cpp_policies//features:strict_warnings", "@score_cpp_policies//features:warnings_as_errors"], +) +``` ```bash # .bazelrc @@ -236,6 +241,9 @@ cc_library( ) ``` +> The exact `score_cpp_policies` feature labels above are illustrative — see +> that module's documentation for the authoritative target names. + ### Scenario B — "Undefined reference to pthread symbols" **Symptom:** Links fail with `pthread_*` undefined references. diff --git a/docs/repository_layout.md b/docs/repository_layout.md index a1e45ae..df80351 100644 --- a/docs/repository_layout.md +++ b/docs/repository_layout.md @@ -25,6 +25,7 @@ The repository is organized by subsystem rather than by platform product: |- tests/ Test workspace and validation suites |- extensions/ Bzlmod extension entry points |- packages/ Toolchain package descriptors and version matrix +|- features/ Declarative cc_feature/cc_args toolchain-feature definitions |- rules/ Repository rules and shared helpers |- templates/ Generated file templates for toolchain repositories `- tools/ Standalone utility scripts @@ -50,13 +51,24 @@ archives. The most important file is `packages/version_matrix.bzl`, which maps logical toolchain identifiers to URLs, checksums, build files, and any required extra flags. +`features/` + +Holds declarative `cc_feature` / `cc_args` toolchain-feature definitions built +with `@rules_cc//cc/toolchains`. `features/native/` has one reusable target +per toolchain feature (mirroring the legacy Bazel C++ features); the +OS-specific `features/custom/linux/` and `features/custom/qnx/` packages hold +platform-only features (e.g. QNX `sdp_env`, `gcc_version_flags`) plus the +ordered `known_features`/`enabled_features` lists that +`templates/BUILD.template` passes to `cc_toolchain_config`. + `templates/` -Holds the template files used by repository rules. These templates are -rendered into the generated toolchain repository and differ between Linux and -QNX because the execution environment, sysroot layout, and licensing model are -different. -> NOTE: Future plan is to have a single template for toolchain configuration. +Holds the shared template files rendered by repository rules into the +generated toolchain repository: `BUILD.template`, +`cc_toolchain_config.bzl.template`, and `cc_gcov_wrapper.template`. A single +template pair now covers both Linux and QNX; OS-specific behavior comes from +placeholder substitution in `rules/gcc.bzl` and from the OS-specific feature +lists in `features/custom/`, not from separate template directories. `tests/` diff --git a/extensions/gcc.bzl b/extensions/gcc.bzl index fee2620..23fb14f 100644 --- a/extensions/gcc.bzl +++ b/extensions/gcc.bzl @@ -209,8 +209,7 @@ 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_config": "@score_bazel_cpp_toolchains//templates:cc_toolchain_config.bzl.template", "gcc_version": tag.version, "name": tag.name, "use_base_constraints_only": tag.use_base_constraints_only, @@ -424,7 +423,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"], ) diff --git a/features/BUILD b/features/BUILD new file mode 100644 index 0000000..7863c58 --- /dev/null +++ b/features/BUILD @@ -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/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/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"], +) diff --git a/features/custom/linux/BUILD b/features/custom/linux/BUILD new file mode 100644 index 0000000..e69de29 diff --git a/features/custom/linux/make_cc_features.bzl b/features/custom/linux/make_cc_features.bzl new file mode 100644 index 0000000..6e64324 --- /dev/null +++ b/features/custom/linux/make_cc_features.bzl @@ -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() diff --git a/features/custom/qnx/BUILD b/features/custom/qnx/BUILD new file mode 100644 index 0000000..e69de29 diff --git a/features/custom/qnx/gcc_version_flags/BUILD b/features/custom/qnx/gcc_version_flags/BUILD new file mode 100644 index 0000000..6e049e2 --- /dev/null +++ b/features/custom/qnx/gcc_version_flags/BUILD @@ -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"], +) diff --git a/features/custom/qnx/make_cc_features.bzl b/features/custom/qnx/make_cc_features.bzl new file mode 100644 index 0000000..3f5196f --- /dev/null +++ b/features/custom/qnx/make_cc_features.bzl @@ -0,0 +1,86 @@ +# ******************************************************************************* +# 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 +# ******************************************************************************* + +def compute_feature_lists(target_os): + """Returns the flat known/enabled feature label lists for target_os. + + Unlike cc_feature_set (which groups features for requires_any_of/requires_all_of + constraints and does not itself provide FeatureInfo), cc_toolchain_config's + known_features/enabled_features attrs require every entry to individually + provide FeatureInfo — so this returns plain lists of cc_feature labels rather + than a single grouping target. + + Per-instance features (extra_compile_flags, extra_c_compile_flags, + extra_cxx_compile_flags, extra_link_flags, sysroot_link_flags, + compiler_library_search_paths) are baked into _LINUX_FEATURES/_QNX_FEATURES + directly since their target names never change across toolchain instances — + see templates/BUILD.template for where those targets get created. + + Args: + target_os: "linux" or "qnx". + + Returns: + (known_features, enabled_features) tuple of flat label lists. + """ + +_QNX_FEATURES = [ + ("@score_bazel_cpp_toolchains//features/native/markers:dbg", False), # Bazel auto-toggles via -c dbg + ("@score_bazel_cpp_toolchains//features/native/markers:no_legacy_features", True), + ("@score_bazel_cpp_toolchains//features/native/unfiltered_compile_flags", True), + ("@score_bazel_cpp_toolchains//features/custom/qnx/gcc_version_flags", True), + ("@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/markers:dependency_file_named_implicitly", False), + ("@score_bazel_cpp_toolchains//features/native/dependency_file", 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/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/markers:coverage", False), # opt-in + ("@score_bazel_cpp_toolchains//features/native/markers:opt", False), # Bazel auto-toggles via -c opt + (":sdp_env", True), # per-instance, see templates/BUILD.template + ("@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/runtime_library_search_directories", True), + ("@score_bazel_cpp_toolchains//features/native/gcc_coverage_map_format", False), # opt-in +] + +def qnx_known_features(): + """Full ordered list of QNX feature labels — order drives flag order.""" + return [label for label, _enabled in _QNX_FEATURES] + +def qnx_enabled_features(): + """Subset of QNX feature labels that start enabled — order is irrelevant here.""" + return [label for label, enabled in _QNX_FEATURES if enabled] + +def get_feature_lists(): + """Returns the flat known/enabled feature label lists for QNX. + + Returns: + (known_features, enabled_features) tuple of flat label lists. + """ + return qnx_known_features(), qnx_enabled_features() diff --git a/features/custom/qnx/sdp_env/BUILD b/features/custom/qnx/sdp_env/BUILD new file mode 100644 index 0000000..e69de29 diff --git a/features/custom/qnx/sdp_env/feature.bzl b/features/custom/qnx/sdp_env/feature.bzl new file mode 100644 index 0000000..dcdd34b --- /dev/null +++ b/features/custom/qnx/sdp_env/feature.bzl @@ -0,0 +1,63 @@ +# ******************************************************************************* +# 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") + +_ACTIONS = [ + "@rules_cc//cc/toolchains/actions:compile_actions", + "@rules_cc//cc/toolchains/actions:link_actions", +] + +def make_sdp_env_feature( + host_dir, + target_dir, + license_path, + license_info_variable, + license_info_value): + """Creates a feature for the sdp_env toolchain. + + Args: + host_dir: str, resolved path to the SDP host directory. + target_dir: str, resolved path to the SDP target directory. + license_path: str, path to the license file. + license_info_variable: str, name of an extra license env var, "" if none. + license_info_value: str, value of that extra license env var, "" if none. + + Returns: + A feature definition for the sdp_env toolchain. + """ + + # cc_args' `env` has no mechanism to resolve labels/format custom + # placeholders (see validate_env_variables in rules_cc) -- host_dir/ + # target_dir must already be plain resolved path strings. + env = { + "QNX_HOST": host_dir, + "QNX_TARGET": target_dir, + "QNX_CONFIGURATION_EXCLUSIVE": "/var/tmp/.qnx", + "QNX_SHARED_LICENSE_FILE": license_path, + } + if license_info_value: + env[license_info_variable] = license_info_value + + cc_args( + name = "sdp_env_args", + actions = _ACTIONS, + env = env, + ) + + cc_feature( + name = "sdp_env", + feature_name = "sdp_env", + args = [":sdp_env_args"], + ) diff --git a/features/make_cc_features.bzl b/features/make_cc_features.bzl new file mode 100644 index 0000000..2fabe32 --- /dev/null +++ b/features/make_cc_features.bzl @@ -0,0 +1,27 @@ +def compute_feature_lists(target_os): + """Returns the flat known/enabled feature label lists for target_os. + + Unlike cc_feature_set (which groups features for requires_any_of/requires_all_of + constraints and does not itself provide FeatureInfo), cc_toolchain_config's + known_features/enabled_features attrs require every entry to individually + provide FeatureInfo — so this returns plain lists of cc_feature labels rather + than a single grouping target. + + Per-instance features (extra_compile_flags, extra_c_compile_flags, + extra_cxx_compile_flags, extra_link_flags, sysroot_link_flags, + compiler_library_search_paths) are baked into _LINUX_FEATURES/_QNX_FEATURES + directly since their target names never change across toolchain instances — + see templates/BUILD.template for where those targets get created. + + Args: + target_os: "linux" or "qnx". + + Returns: + (known_features, enabled_features) tuple of flat label lists. + """ + if target_os == "linux": + return linux_known_features(), linux_enabled_features() + elif target_os == "qnx": + return qnx_known_features(), qnx_enabled_features() + else: + fail("Unsupported target_os '{}', expected 'linux' or 'qnx'".format(target_os)) diff --git a/features/native/archiver_flags/BUILD b/features/native/archiver_flags/BUILD new file mode 100644 index 0000000..030860d --- /dev/null +++ b/features/native/archiver_flags/BUILD @@ -0,0 +1,77 @@ +# ******************************************************************************* +# 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:args.bzl", "cc_args") +load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature") +load("@rules_cc//cc/toolchains:nested_args.bzl", "cc_nested_args") + +cc_args( + name = "archiver_static_flag_args", + actions = ["@rules_cc//cc/toolchains/actions:ar_actions"], + args = ["rcsD"], + visibility = ["//visibility:public"], +) + +cc_args( + name = "archiver_output_execpath_args", + actions = ["@rules_cc//cc/toolchains/actions:ar_actions"], + args = ["{output_execpath}"], + format = {"output_execpath": "@rules_cc//cc/toolchains/variables:output_execpath"}, + requires_not_none = "@rules_cc//cc/toolchains/variables:output_execpath", + visibility = ["//visibility:public"], +) + +cc_nested_args( + name = "archiver_object_file_entry", + args = ["{lib_name}"], + format = {"lib_name": "@rules_cc//cc/toolchains/variables:libraries_to_link.name"}, + requires_equal = "@rules_cc//cc/toolchains/variables:libraries_to_link.type", + requires_equal_value = "object_file", +) + +cc_nested_args( + name = "archiver_object_file_group_entry", + args = ["{object_file}"], + format = {"object_file": "@rules_cc//cc/toolchains/variables:libraries_to_link.object_files"}, + iterate_over = "@rules_cc//cc/toolchains/variables:libraries_to_link.object_files", + requires_equal = "@rules_cc//cc/toolchains/variables:libraries_to_link.type", + requires_equal_value = "object_file_group", +) + +cc_nested_args( + name = "archiver_iterate_libraries", + iterate_over = "@rules_cc//cc/toolchains/variables:libraries_to_link", + nested = [ + ":archiver_object_file_entry", + ":archiver_object_file_group_entry", + ], +) + +cc_args( + name = "archiver_libraries_args", + actions = ["@rules_cc//cc/toolchains/actions:ar_actions"], + nested = [":archiver_iterate_libraries"], + requires_not_none = "@rules_cc//cc/toolchains/variables:libraries_to_link", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "archiver_flags", + args = [ + ":archiver_static_flag_args", + ":archiver_output_execpath_args", + ":archiver_libraries_args", + ], + feature_name = "archiver_flags", + visibility = ["//visibility:public"], +) diff --git a/features/native/compiler_input_flags/BUILD b/features/native/compiler_input_flags/BUILD new file mode 100644 index 0000000..01612f2 --- /dev/null +++ b/features/native/compiler_input_flags/BUILD @@ -0,0 +1,34 @@ +# ******************************************************************************* +# 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:args.bzl", "cc_args") +load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature") + +cc_args( + name = "compiler_input_flags_args", + actions = ["@rules_cc//cc/toolchains/actions:compile_actions"], + args = [ + "-c", + "{source_file}", + ], + format = {"source_file": "@rules_cc//cc/toolchains/variables:source_file"}, + requires_not_none = "@rules_cc//cc/toolchains/variables:source_file", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "compiler_input_flags", + args = [":compiler_input_flags_args"], + feature_name = "compiler_input_flags", + visibility = ["//visibility:public"], +) diff --git a/features/native/compiler_library_search_paths/BUILD b/features/native/compiler_library_search_paths/BUILD new file mode 100644 index 0000000..61e203a --- /dev/null +++ b/features/native/compiler_library_search_paths/BUILD @@ -0,0 +1,16 @@ +# ******************************************************************************* +# 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 +# ******************************************************************************* + +# Instantiated per-toolchain via make_compiler_library_search_paths() in +# features.bzl, since each toolchain has different search paths — see +# templates/BUILD.template. diff --git a/features/native/compiler_library_search_paths/features.bzl b/features/native/compiler_library_search_paths/features.bzl new file mode 100644 index 0000000..3cfb0aa --- /dev/null +++ b/features/native/compiler_library_search_paths/features.bzl @@ -0,0 +1,45 @@ +# ******************************************************************************* +# 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") + +_ALL_ACTIONS = [ + "@rules_cc//cc/toolchains/actions:compile_actions", + "@rules_cc//cc/toolchains/actions:link_actions", + "@rules_cc//cc/toolchains/actions:strip", + "@rules_cc//cc/toolchains/actions:ar_actions", +] + +def make_compiler_library_search_paths(compiler_library_search_paths): + """Creates the compiler_library_search_paths feature. + + Sets LD_LIBRARY_PATH for every toolchain action (compile, link, archive, + strip) so the compiler/linker/ar/strip binaries themselves can find their + own runtime shared libraries. This is unrelated to the artifacts being + built, so it's an env var applied to all actions, not a linker flag. + + Args: + compiler_library_search_paths: colon-joined path string, "" if none. + """ + cc_args( + name = "compiler_library_search_paths_args", + actions = _ALL_ACTIONS, + env = {"LD_LIBRARY_PATH": compiler_library_search_paths} if compiler_library_search_paths else {}, + ) + + cc_feature( + name = "compiler_library_search_paths", + args = [":compiler_library_search_paths_args"], + feature_name = "compiler_library_search_paths", + ) diff --git a/features/native/compiler_output_flags/BUILD b/features/native/compiler_output_flags/BUILD new file mode 100644 index 0000000..3adc126 --- /dev/null +++ b/features/native/compiler_output_flags/BUILD @@ -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 +# ******************************************************************************* + +load("@rules_cc//cc/toolchains:args.bzl", "cc_args") +load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature") + +cc_args( + name = "output_assembly_file_args", + actions = ["@rules_cc//cc/toolchains/actions:compile_actions"], + args = ["-S"], + requires_not_none = "@rules_cc//cc/toolchains/variables:output_assembly_file", + visibility = ["//visibility:public"], +) + +cc_args( + name = "output_preprocess_file_args", + actions = ["@rules_cc//cc/toolchains/actions:compile_actions"], + args = ["-E"], + requires_not_none = "@rules_cc//cc/toolchains/variables:output_preprocess_file", + visibility = ["//visibility:public"], +) + +cc_args( + name = "output_file_args", + actions = ["@rules_cc//cc/toolchains/actions:compile_actions"], + args = [ + "-o", + "{output_file}", + ], + format = {"output_file": "@rules_cc//cc/toolchains/variables:output_file"}, + requires_not_none = "@rules_cc//cc/toolchains/variables:output_file", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "compiler_output_flags", + args = [ + ":output_assembly_file_args", + ":output_preprocess_file_args", + ":output_file_args", + ], + feature_name = "compiler_output_flags", + visibility = ["//visibility:public"], +) diff --git a/features/native/default_compile_flags/BUILD b/features/native/default_compile_flags/BUILD new file mode 100644 index 0000000..45c0eb2 --- /dev/null +++ b/features/native/default_compile_flags/BUILD @@ -0,0 +1,161 @@ +# ******************************************************************************* +# 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:args.bzl", "cc_args") +load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature") +load("@rules_cc//cc/toolchains:feature_constraint.bzl", "cc_feature_constraint") + +cc_args( + name = "default_compile_flags_args", + actions = ["@rules_cc//cc/toolchains/actions:compile_actions"], + args = select( + { + "@platforms//os:linux": [ + "-U_FORTIFY_SOURCE", + "-D_XOPEN_SOURCE=700", + "-fstack-protector", + "-fdiagnostics-color=always", + "-fno-omit-frame-pointer", + "-ffunction-sections", + "-fdata-sections", + "-fno-canonical-system-headers", + "-no-canonical-prefixes", + "-z noexecstack", + ], + "@platforms//os:qnx": [ + "-fno-canonical-system-headers", + ], + "//conditions:default": [], + }, + ), +) + +# x86_64 requires -m64; other architectures need no CPU flags here +cc_args( + name = "target_cpu_flags_args", + actions = ["@rules_cc//cc/toolchains/actions:compile_actions"], + args = select({ + "@platforms//cpu:x86_64": ["-m64"], + "//conditions:default": [], + }), + visibility = ["//visibility:public"], +) + +cc_feature_constraint( + name = "not_gnu11", + none_of = ["//features/native/markers:gnu11"], +) + +cc_feature_constraint( + name = "is_gnu11", + all_of = ["//features/native/markers:gnu11"], +) + +cc_args( + name = "c_std_c11_args", + actions = ["@rules_cc//cc/toolchains/actions:c_compile_actions"], + args = ["-std=c11"], + requires_any_of = [":not_gnu11"], +) + +cc_args( + name = "c_std_gnu11_args", + actions = ["@rules_cc//cc/toolchains/actions:c_compile_actions"], + args = ["-std=gnu11"], + requires_any_of = [":is_gnu11"], +) + +cc_args( + name = "default_cxx_compile_flags_args", + actions = ["@rules_cc//cc/toolchains/actions:cpp_compile_actions"], + args = ["-std=c++17"] + + select({ + "@platforms//os:qnx": [ + "-D_QNX_SOURCE", + ], + "//conditions:default": [], + }), +) + +cc_feature_constraint( + name = "is_dbg", + all_of = ["//features/native/markers:dbg"], +) + +cc_args( + name = "dbg_compile_flags_args", + actions = ["@rules_cc//cc/toolchains/actions:compile_actions"], + args = [ + "-Og", + "-g3", + ], + requires_any_of = [":is_dbg"], +) + +cc_feature_constraint( + name = "is_opt", + all_of = ["//features/native/markers:opt"], +) + +cc_feature_constraint( + name = "is_fastbuild", + all_of = ["//features/native/markers:fastbuild"], +) + +cc_args( + name = "opt_compile_flags_args", + actions = ["@rules_cc//cc/toolchains/actions:compile_actions"], + args = [ + "-O2", + "-DNDEBUG", + ], + requires_any_of = [ + ":is_opt", + ":is_fastbuild", + ], +) + +cc_args( + name = "gcc_compile_flag_version_args", + actions = ["@rules_cc//cc/toolchains/actions:compile_actions"], + args = select({ + "@score_bazel_platform//settings:aarch64-qnx8": [ + "-V{version},gcc_nto{cpu}".format( + cpu = "aarch64le", + version = "12.2.0", + ), + ], + "@score_bazel_platform//settings:x86_64-qnx8": [ + "-V{version},gcc_nto{cpu}".format( + cpu = "x86_64", + version = "12.2.0", + ), + ], + "//conditions:default": [], + }), +) + +cc_feature( + name = "default_compile_flags", + args = [ + ":default_compile_flags_args", + ":target_cpu_flags_args", + ":c_std_c11_args", + ":c_std_gnu11_args", + ":default_cxx_compile_flags_args", + ":dbg_compile_flags_args", + ":opt_compile_flags_args", + ], + feature_name = "default_compile_flags", + visibility = ["//visibility:public"], +) diff --git a/features/native/default_link_flags/BUILD b/features/native/default_link_flags/BUILD new file mode 100644 index 0000000..f586f61 --- /dev/null +++ b/features/native/default_link_flags/BUILD @@ -0,0 +1,90 @@ +# ******************************************************************************* +# 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:args.bzl", "cc_args") +load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature") +load("@rules_cc//cc/toolchains:feature_constraint.bzl", "cc_feature_constraint") + +cc_feature_constraint( + name = "is_opt", + all_of = ["//features/native/markers:opt"], +) + +# compress-debug only when neither opt nor fastbuild +cc_feature_constraint( + name = "not_opt_not_fastbuild", + none_of = [ + "//features/native/markers:opt", + "//features/native/markers:fastbuild", + ], +) + +# Linux base link flags +cc_args( + name = "linux_base_link_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + args = [ + "-lm", + "-ldl", + "-lrt", + "-static-libstdc++", + "-static-libgcc", + ], + visibility = ["//visibility:public"], +) + +cc_args( + name = "linux_opt_link_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + args = ["-Wl,--gc-sections"], + requires_any_of = [":is_opt"], + visibility = ["//visibility:public"], +) + +cc_args( + name = "linux_debug_compress_link_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + args = ["-Wl,--compress-debug-sections=zlib"], + requires_any_of = [":not_opt_not_fastbuild"], + visibility = ["//visibility:public"], +) + +# QNX static link flags (the -V routing flag stays in toolchain config template) +cc_args( + name = "qnx_base_link_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + args = [ + "-Wl,-z,relro", + "-Wl,-z,now", + "-Wl,--push-state", + "-Wl,--as-needed", + "-lc++", + "-lm", + "-Wl,--pop-state", + ], + visibility = ["//visibility:public"], +) + +cc_feature( + name = "default_link_flags", + args = select({ + "@platforms//os:linux": [ + ":linux_base_link_args", + ":linux_opt_link_args", + ":linux_debug_compress_link_args", + ], + "@platforms//os:qnx": [":qnx_base_link_args"], + }), + feature_name = "default_link_flags", + visibility = ["//visibility:public"], +) diff --git a/features/native/dependency_file/BUILD b/features/native/dependency_file/BUILD new file mode 100644 index 0000000..5abf755 --- /dev/null +++ b/features/native/dependency_file/BUILD @@ -0,0 +1,88 @@ +# ******************************************************************************* +# 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:args.bzl", "cc_args") +load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature") +load("@rules_cc//cc/toolchains:feature_constraint.bzl", "cc_feature_constraint") + +_COMPILE_ACTIONS = [ + "@rules_cc//cc/toolchains/actions:assemble", + "@rules_cc//cc/toolchains/actions:preprocess_assemble", + "@rules_cc//cc/toolchains/actions:c_compile", + "@rules_cc//cc/toolchains/actions:cpp_compile", + "@rules_cc//cc/toolchains/actions:cpp_module_compile", + "@rules_cc//cc/toolchains/actions:cpp_header_parsing", +] + +# Linux: standard -MD -MF flags +cc_args( + name = "dependency_file_linux_args", + actions = _COMPILE_ACTIONS, + args = [ + "-MD", + "-MF", + "{dependency_file}", + ], + format = {"dependency_file": "@rules_cc//cc/toolchains/variables:dependency_file"}, + requires_not_none = "@rules_cc//cc/toolchains/variables:dependency_file", + visibility = ["//visibility:public"], +) + +# QNX: QCC-wrapped flags — explicit filename (dependency_file_named_implicitly is NOT active) +cc_feature_constraint( + name = "not_dep_named_implicitly", + none_of = ["//features/native/markers:dependency_file_named_implicitly"], +) + +cc_args( + name = "dependency_file_qnx_explicit_args", + actions = _COMPILE_ACTIONS, + args = [ + "-Wc,-MD,{dependency_file}", + "-Wp,-MD,{dependency_file}", + ], + format = {"dependency_file": "@rules_cc//cc/toolchains/variables:dependency_file"}, + requires_any_of = [":not_dep_named_implicitly"], + requires_not_none = "@rules_cc//cc/toolchains/variables:dependency_file", + visibility = ["//visibility:public"], +) + +# QNX: QCC-wrapped flags — implicit filename (dependency_file_named_implicitly IS active) +cc_feature_constraint( + name = "is_dep_named_implicitly", + all_of = ["//features/native/markers:dependency_file_named_implicitly"], +) + +cc_args( + name = "dependency_file_qnx_implicit_args", + actions = _COMPILE_ACTIONS, + args = [ + "-Wc,-MD", + "-Wp,-MD", + ], + requires_any_of = [":is_dep_named_implicitly"], + visibility = ["//visibility:public"], +) + +cc_feature( + name = "dependency_file", + args = select({ + "@platforms//os:linux": [":dependency_file_linux_args"], + "@platforms//os:qnx": [ + ":dependency_file_qnx_explicit_args", + ":dependency_file_qnx_implicit_args", + ], + }), + feature_name = "dependency_file", + visibility = ["//visibility:public"], +) diff --git a/features/native/extra_compile_flags/BUILD b/features/native/extra_compile_flags/BUILD new file mode 100644 index 0000000..e69de29 diff --git a/features/native/extra_compile_flags/features.bzl b/features/native/extra_compile_flags/features.bzl new file mode 100644 index 0000000..eb2fd38 --- /dev/null +++ b/features/native/extra_compile_flags/features.bzl @@ -0,0 +1,58 @@ +# ******************************************************************************* +# 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") + +def make_extra_compile_features( + extra_compile_flags = None, + extra_c_compile_flags = None, + extra_cxx_compile_flags = None): + cc_args( + name = "extra_compile_flags_args", + actions = ["@rules_cc//cc/toolchains/actions:source_compile_actions"], + args = extra_compile_flags, + ) + + cc_feature( + name = "extra_compile_flags", + args = [":extra_compile_flags_args"], + feature_name = "extra_compile_flags", + implies = ["@score_bazel_cpp_toolchains//features/native/default_compile_flags"], + ) + + cc_args( + name = "extra_c_compile_flags_args", + actions = ["@rules_cc//cc/toolchains/actions:c_compile_actions"], + args = extra_c_compile_flags, + ) + + cc_feature( + name = "extra_c_compile_flags", + args = [":extra_c_compile_flags_args"], + feature_name = "extra_c_compile_flags", + implies = ["@score_bazel_cpp_toolchains//features/native/default_compile_flags"], + ) + + cc_args( + name = "extra_cxx_compile_flags_args", + actions = ["@rules_cc//cc/toolchains/actions:cpp_compile_actions"], + args = extra_cxx_compile_flags, + ) + + cc_feature( + name = "extra_cxx_compile_flags", + args = [":extra_cxx_compile_flags_args"], + feature_name = "extra_cxx_compile_flags", + implies = ["@score_bazel_cpp_toolchains//features/native/default_compile_flags"], + ) diff --git a/features/native/extra_link_flags/BUILD b/features/native/extra_link_flags/BUILD new file mode 100644 index 0000000..e69de29 diff --git a/features/native/extra_link_flags/features.bzl b/features/native/extra_link_flags/features.bzl new file mode 100644 index 0000000..a030201 --- /dev/null +++ b/features/native/extra_link_flags/features.bzl @@ -0,0 +1,29 @@ +# ******************************************************************************* +# 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") + +def make_extra_link_features( + extra_link_flags = None): + cc_args( + name = "extra_link_flags_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + args = extra_link_flags, + ) + + cc_feature( + name = "extra_link_flags", + args = [":extra_link_flags_args"], + feature_name = "extra_link_flags", + ) diff --git a/features/native/fission_support/BUILD b/features/native/fission_support/BUILD new file mode 100644 index 0000000..7e749dc --- /dev/null +++ b/features/native/fission_support/BUILD @@ -0,0 +1,30 @@ +# ******************************************************************************* +# 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:args.bzl", "cc_args") +load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature") + +cc_args( + name = "fission_support_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + args = ["-Wl,--gdb-index"], + requires_not_none = "@rules_cc//cc/toolchains/variables:is_using_fission", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "fission_support", + args = [":fission_support_args"], + feature_name = "fission_support", + visibility = ["//visibility:public"], +) diff --git a/features/native/force_pic_flags/BUILD b/features/native/force_pic_flags/BUILD new file mode 100644 index 0000000..22c9f0d --- /dev/null +++ b/features/native/force_pic_flags/BUILD @@ -0,0 +1,30 @@ +# ******************************************************************************* +# 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:args.bzl", "cc_args") +load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature") + +cc_args( + name = "force_pic_flags_args", + actions = ["@rules_cc//cc/toolchains/actions:cpp_link_executable"], + args = ["-pie"], + requires_not_none = "@rules_cc//cc/toolchains/variables:force_pic", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "force_pic_flags", + args = [":force_pic_flags_args"], + feature_name = "force_pic_flags", + visibility = ["//visibility:public"], +) diff --git a/features/native/fully_static_link/BUILD b/features/native/fully_static_link/BUILD new file mode 100644 index 0000000..f128a0e --- /dev/null +++ b/features/native/fully_static_link/BUILD @@ -0,0 +1,33 @@ +# ******************************************************************************* +# 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:args.bzl", "cc_args") +load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature") + +cc_args( + name = "fully_static_link_args", + actions = [ + "@rules_cc//cc/toolchains/actions:cpp_link_executable", + "@rules_cc//cc/toolchains/actions:cpp_link_dynamic_library", + "@rules_cc//cc/toolchains/actions:cpp_link_nodeps_dynamic_library", + ], + args = ["-static"], + visibility = ["//visibility:public"], +) + +cc_feature( + name = "fully_static_link", + args = [":fully_static_link_args"], + feature_name = "fully_static_link", + visibility = ["//visibility:public"], +) diff --git a/features/native/gcc_coverage_map_format/BUILD b/features/native/gcc_coverage_map_format/BUILD new file mode 100644 index 0000000..71816a7 --- /dev/null +++ b/features/native/gcc_coverage_map_format/BUILD @@ -0,0 +1,62 @@ +# ******************************************************************************* +# 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:args.bzl", "cc_args") +load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature") +load("@rules_cc//cc/toolchains:feature_set.bzl", "cc_feature_set") + +cc_feature_set( + name = "requires_coverage", + all_of = ["//features/native/markers:coverage"], + visibility = ["//visibility:public"], +) + +cc_args( + name = "coverage_compile_args", + actions = [ + "@rules_cc//cc/toolchains/actions:c_compile", + "@rules_cc//cc/toolchains/actions:cpp_compile", + "@rules_cc//cc/toolchains/actions:cpp_module_compile", + "@rules_cc//cc/toolchains/actions:preprocess_assemble", + ], + args = [ + "-fprofile-arcs", + "-ftest-coverage", + ], + visibility = ["//visibility:public"], +) + +cc_args( + name = "linux_coverage_link_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + args = ["--coverage"], + visibility = ["//visibility:public"], +) + +cc_args( + name = "qnx_coverage_link_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + args = ["-lgcov"], + visibility = ["//visibility:public"], +) + +cc_feature( + name = "gcc_coverage_map_format", + args = [":coverage_compile_args"] + select({ + "@platforms//os:linux": [":linux_coverage_link_args"], + "@platforms//os:qnx": [":qnx_coverage_link_args"], + }), + feature_name = "gcc_coverage_map_format", + requires_any_of = [":requires_coverage"], + visibility = ["//visibility:public"], +) diff --git a/features/native/include_paths/BUILD b/features/native/include_paths/BUILD new file mode 100644 index 0000000..676bab8 --- /dev/null +++ b/features/native/include_paths/BUILD @@ -0,0 +1,59 @@ +# ******************************************************************************* +# 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:args.bzl", "cc_args") +load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature") + +cc_args( + name = "quote_include_paths_args", + actions = ["@rules_cc//cc/toolchains/actions:source_compile_actions"], + args = [ + "-iquote", + "{quote_include_paths}", + ], + format = {"quote_include_paths": "@rules_cc//cc/toolchains/variables:quote_include_paths"}, + iterate_over = "@rules_cc//cc/toolchains/variables:quote_include_paths", + visibility = ["//visibility:public"], +) + +cc_args( + name = "include_paths_args", + actions = ["@rules_cc//cc/toolchains/actions:source_compile_actions"], + args = ["-I{include_paths}"], + format = {"include_paths": "@rules_cc//cc/toolchains/variables:include_paths"}, + iterate_over = "@rules_cc//cc/toolchains/variables:include_paths", + visibility = ["//visibility:public"], +) + +cc_args( + name = "system_include_paths_args", + actions = ["@rules_cc//cc/toolchains/actions:source_compile_actions"], + args = [ + "-isystem", + "{system_include_paths}", + ], + format = {"system_include_paths": "@rules_cc//cc/toolchains/variables:system_include_paths"}, + iterate_over = "@rules_cc//cc/toolchains/variables:system_include_paths", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "include_paths", + args = [ + ":quote_include_paths_args", + ":include_paths_args", + ":system_include_paths_args", + ], + feature_name = "include_paths", + visibility = ["//visibility:public"], +) diff --git a/features/native/includes/BUILD b/features/native/includes/BUILD new file mode 100644 index 0000000..f0dc8dd --- /dev/null +++ b/features/native/includes/BUILD @@ -0,0 +1,35 @@ +# ******************************************************************************* +# 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:args.bzl", "cc_args") +load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature") + +cc_args( + name = "includes_args", + actions = ["@rules_cc//cc/toolchains/actions:source_compile_actions"], + args = [ + "-include", + "{includes}", + ], + format = {"includes": "@rules_cc//cc/toolchains/variables:includes"}, + iterate_over = "@rules_cc//cc/toolchains/variables:includes", + requires_not_none = "@rules_cc//cc/toolchains/variables:includes", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "includes", + args = [":includes_args"], + feature_name = "includes", + visibility = ["//visibility:public"], +) diff --git a/features/native/libraries_to_link/BUILD b/features/native/libraries_to_link/BUILD new file mode 100644 index 0000000..09e96a5 --- /dev/null +++ b/features/native/libraries_to_link/BUILD @@ -0,0 +1,105 @@ +# ******************************************************************************* +# 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:args.bzl", "cc_args") +load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature") +load("@rules_cc//cc/toolchains:nested_args.bzl", "cc_nested_args") + +# static_library: dispatch on is_whole_archive +cc_nested_args( + name = "whole_archive_static_library", + args = [ + "-Wl,--whole-archive", + "{lib_name}", + "-Wl,--no-whole-archive", + ], + format = {"lib_name": "@rules_cc//cc/toolchains/variables:libraries_to_link.name"}, + requires_true = "@rules_cc//cc/toolchains/variables:libraries_to_link.is_whole_archive", +) + +cc_nested_args( + name = "non_whole_archive_static_library", + args = ["{lib_name}"], + format = {"lib_name": "@rules_cc//cc/toolchains/variables:libraries_to_link.name"}, + requires_false = "@rules_cc//cc/toolchains/variables:libraries_to_link.is_whole_archive", +) + +cc_nested_args( + name = "static_library_dispatch", + nested = [ + ":whole_archive_static_library", + ":non_whole_archive_static_library", + ], + requires_equal = "@rules_cc//cc/toolchains/variables:libraries_to_link.type", + requires_equal_value = "static_library", +) + +cc_nested_args( + name = "object_file_entry", + args = ["{lib_name}"], + format = {"lib_name": "@rules_cc//cc/toolchains/variables:libraries_to_link.name"}, + requires_equal = "@rules_cc//cc/toolchains/variables:libraries_to_link.type", + requires_equal_value = "object_file", +) + +cc_nested_args( + name = "object_file_group_entry", + args = ["{object_file}"], + format = {"object_file": "@rules_cc//cc/toolchains/variables:libraries_to_link.object_files"}, + iterate_over = "@rules_cc//cc/toolchains/variables:libraries_to_link.object_files", + requires_equal = "@rules_cc//cc/toolchains/variables:libraries_to_link.type", + requires_equal_value = "object_file_group", +) + +cc_nested_args( + name = "dynamic_library_entry", + args = ["-l{lib_name}"], + format = {"lib_name": "@rules_cc//cc/toolchains/variables:libraries_to_link.name"}, + requires_equal = "@rules_cc//cc/toolchains/variables:libraries_to_link.type", + requires_equal_value = "dynamic_library", +) + +cc_nested_args( + name = "versioned_dynamic_library_entry", + args = ["-l:{lib_name}"], + format = {"lib_name": "@rules_cc//cc/toolchains/variables:libraries_to_link.name"}, + requires_equal = "@rules_cc//cc/toolchains/variables:libraries_to_link.type", + requires_equal_value = "versioned_dynamic_library", +) + +cc_nested_args( + name = "iterate_libraries", + iterate_over = "@rules_cc//cc/toolchains/variables:libraries_to_link", + nested = [ + ":static_library_dispatch", + ":object_file_entry", + ":object_file_group_entry", + ":dynamic_library_entry", + ":versioned_dynamic_library_entry", + ], +) + +cc_args( + name = "libraries_to_link_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + nested = [":iterate_libraries"], + requires_not_none = "@rules_cc//cc/toolchains/variables:libraries_to_link", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "libraries_to_link", + args = [":libraries_to_link_args"], + feature_name = "libraries_to_link", + visibility = ["//visibility:public"], +) diff --git a/features/native/library_search_directories/BUILD b/features/native/library_search_directories/BUILD new file mode 100644 index 0000000..1f65428 --- /dev/null +++ b/features/native/library_search_directories/BUILD @@ -0,0 +1,32 @@ +# ******************************************************************************* +# 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:args.bzl", "cc_args") +load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature") + +cc_args( + name = "library_search_directories_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + args = ["-L{library_search_directories}"], + format = {"library_search_directories": "@rules_cc//cc/toolchains/variables:library_search_directories"}, + iterate_over = "@rules_cc//cc/toolchains/variables:library_search_directories", + requires_not_none = "@rules_cc//cc/toolchains/variables:library_search_directories", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "library_search_directories", + args = [":library_search_directories_args"], + feature_name = "library_search_directories", + visibility = ["//visibility:public"], +) diff --git a/features/native/linker_param_file/BUILD b/features/native/linker_param_file/BUILD new file mode 100644 index 0000000..cc097bb --- /dev/null +++ b/features/native/linker_param_file/BUILD @@ -0,0 +1,34 @@ +# ******************************************************************************* +# 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:args.bzl", "cc_args") +load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature") + +cc_args( + name = "linker_param_file_args", + actions = [ + "@rules_cc//cc/toolchains/actions:link_actions", + "@rules_cc//cc/toolchains/actions:ar_actions", + ], + args = ["@{linker_param_file}"], + format = {"linker_param_file": "@rules_cc//cc/toolchains/variables:linker_param_file"}, + requires_not_none = "@rules_cc//cc/toolchains/variables:linker_param_file", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "linker_param_file", + args = [":linker_param_file_args"], + feature_name = "linker_param_file", + visibility = ["//visibility:public"], +) diff --git a/features/native/linkstamps/BUILD b/features/native/linkstamps/BUILD new file mode 100644 index 0000000..4dd5b32 --- /dev/null +++ b/features/native/linkstamps/BUILD @@ -0,0 +1,32 @@ +# ******************************************************************************* +# 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:args.bzl", "cc_args") +load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature") + +cc_args( + name = "linkstamps_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + args = ["{linkstamp_paths}"], + format = {"linkstamp_paths": "@rules_cc//cc/toolchains/variables:linkstamp_paths"}, + iterate_over = "@rules_cc//cc/toolchains/variables:linkstamp_paths", + requires_not_none = "@rules_cc//cc/toolchains/variables:linkstamp_paths", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "linkstamps", + args = [":linkstamps_args"], + feature_name = "linkstamps", + visibility = ["//visibility:public"], +) diff --git a/features/native/markers/BUILD b/features/native/markers/BUILD new file mode 100644 index 0000000..29691d7 --- /dev/null +++ b/features/native/markers/BUILD @@ -0,0 +1,90 @@ +# ******************************************************************************* +# 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.bzl", "cc_feature") + +# Capability markers — enabled state is set at toolchain assembly, not here. +cc_feature( + name = "no_legacy_features", + feature_name = "no_legacy_features", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "supports_pic", + feature_name = "supports_pic", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "supports_dynamic_linker", + feature_name = "supports_dynamic_linker", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "dbg", + feature_name = "dbg", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "opt", + feature_name = "opt", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "fastbuild", + feature_name = "fastbuild", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "coverage", + feature_name = "coverage", + visibility = ["//visibility:public"], +) + +## Linux specific +cc_feature( + name = "supports_fission", + feature_name = "supports_fission", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "supports_header_path_normalization", + feature_name = "supports_header_path_normalization", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "gnu11", + feature_name = "gnu11", + visibility = ["//visibility:public"], +) + +## QNX only +cc_feature( + name = "dependency_file_named_implicitly", + feature_name = "dependency_file_named_implicitly", + visibility = ["//visibility:public"], +) + +# Linked runtime control +cc_feature( + name = "static_link_cpp_runtimes", + feature_name = "static_link_cpp_runtimes", + visibility = ["//visibility:public"], +) diff --git a/features/native/output_execpath_flags/BUILD b/features/native/output_execpath_flags/BUILD new file mode 100644 index 0000000..e9cbcdb --- /dev/null +++ b/features/native/output_execpath_flags/BUILD @@ -0,0 +1,34 @@ +# ******************************************************************************* +# 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:args.bzl", "cc_args") +load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature") + +cc_args( + name = "output_execpath_flags_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + args = [ + "-o", + "{output_execpath}", + ], + format = {"output_execpath": "@rules_cc//cc/toolchains/variables:output_execpath"}, + requires_not_none = "@rules_cc//cc/toolchains/variables:output_execpath", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "output_execpath_flags", + args = [":output_execpath_flags_args"], + feature_name = "output_execpath_flags", + visibility = ["//visibility:public"], +) diff --git a/features/native/per_object_debug_info/BUILD b/features/native/per_object_debug_info/BUILD new file mode 100644 index 0000000..6e284d8 --- /dev/null +++ b/features/native/per_object_debug_info/BUILD @@ -0,0 +1,39 @@ +# ******************************************************************************* +# 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:args.bzl", "cc_args") +load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature") + +cc_args( + name = "per_object_debug_info_args", + actions = [ + "@rules_cc//cc/toolchains/actions:assemble", + "@rules_cc//cc/toolchains/actions:preprocess_assemble", + "@rules_cc//cc/toolchains/actions:c_compile", + "@rules_cc//cc/toolchains/actions:cpp_compile", + "@rules_cc//cc/toolchains/actions:cpp_module_codegen", + ], + args = [ + "-gsplit-dwarf", + "-g", + ], + requires_not_none = "@rules_cc//cc/toolchains/variables:per_object_debug_info_file", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "per_object_debug_info", + args = [":per_object_debug_info_args"], + feature_name = "per_object_debug_info", + visibility = ["//visibility:public"], +) diff --git a/features/native/pic/BUILD b/features/native/pic/BUILD new file mode 100644 index 0000000..5d0c864 --- /dev/null +++ b/features/native/pic/BUILD @@ -0,0 +1,37 @@ +# ******************************************************************************* +# 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:args.bzl", "cc_args") +load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature") + +cc_args( + name = "pic_args", + actions = [ + "@rules_cc//cc/toolchains/actions:assemble", + "@rules_cc//cc/toolchains/actions:preprocess_assemble", + "@rules_cc//cc/toolchains/actions:c_compile", + "@rules_cc//cc/toolchains/actions:cpp_compile", + "@rules_cc//cc/toolchains/actions:cpp_module_codegen", + "@rules_cc//cc/toolchains/actions:cpp_module_compile", + ], + args = ["-fPIC"], + requires_not_none = "@rules_cc//cc/toolchains/variables:pic", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "pic", + args = [":pic_args"], + feature_name = "pic", + visibility = ["//visibility:public"], +) diff --git a/features/native/preprocessor_defines/BUILD b/features/native/preprocessor_defines/BUILD new file mode 100644 index 0000000..b7bf963 --- /dev/null +++ b/features/native/preprocessor_defines/BUILD @@ -0,0 +1,31 @@ +# ******************************************************************************* +# 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:args.bzl", "cc_args") +load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature") + +cc_args( + name = "preprocessor_defines_args", + actions = ["@rules_cc//cc/toolchains/actions:source_compile_actions"], + args = ["-D{preprocessor_defines}"], + format = {"preprocessor_defines": "@rules_cc//cc/toolchains/variables:preprocessor_defines"}, + iterate_over = "@rules_cc//cc/toolchains/variables:preprocessor_defines", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "preprocessor_defines", + args = [":preprocessor_defines_args"], + feature_name = "preprocessor_defines", + visibility = ["//visibility:public"], +) diff --git a/features/native/random_seed/BUILD b/features/native/random_seed/BUILD new file mode 100644 index 0000000..d0c33d1 --- /dev/null +++ b/features/native/random_seed/BUILD @@ -0,0 +1,36 @@ +# ******************************************************************************* +# 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:args.bzl", "cc_args") +load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature") + +cc_args( + name = "random_seed_args", + actions = [ + "@rules_cc//cc/toolchains/actions:c_compile", + "@rules_cc//cc/toolchains/actions:cpp_compile", + "@rules_cc//cc/toolchains/actions:cpp_module_compile", + "@rules_cc//cc/toolchains/actions:cpp_module_codegen", + ], + args = ["-frandom-seed={output_file}"], + format = {"output_file": "@rules_cc//cc/toolchains/variables:output_file"}, + requires_not_none = "@rules_cc//cc/toolchains/variables:output_file", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "random_seed", + args = [":random_seed_args"], + feature_name = "random_seed", + visibility = ["//visibility:public"], +) diff --git a/features/native/runtime_library_search_directories/BUILD b/features/native/runtime_library_search_directories/BUILD new file mode 100644 index 0000000..5c248fd --- /dev/null +++ b/features/native/runtime_library_search_directories/BUILD @@ -0,0 +1,74 @@ +# ******************************************************************************* +# 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:args.bzl", "cc_args") +load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature") +load("@rules_cc//cc/toolchains:nested_args.bzl", "cc_nested_args") + +# Linux: fork rpath on is_cc_test +cc_nested_args( + name = "linux_rpath_test", + args = ["-Wl,-rpath,$ORIGIN/{dir}"], + format = {"dir": "@rules_cc//cc/toolchains/variables:runtime_library_search_directories"}, + requires_true = "@rules_cc//cc/toolchains/variables:is_cc_test", +) + +cc_nested_args( + name = "linux_rpath_exec", + args = ["-Wl,-rpath,$EXEC_ORIGIN/{dir}"], + format = {"dir": "@rules_cc//cc/toolchains/variables:runtime_library_search_directories"}, + requires_false = "@rules_cc//cc/toolchains/variables:is_cc_test", +) + +cc_nested_args( + name = "linux_rpath_iterate", + iterate_over = "@rules_cc//cc/toolchains/variables:runtime_library_search_directories", + nested = [ + ":linux_rpath_test", + ":linux_rpath_exec", + ], +) + +cc_args( + name = "runtime_dirs_linux_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + nested = [":linux_rpath_iterate"], + requires_not_none = "@rules_cc//cc/toolchains/variables:runtime_library_search_directories", + visibility = ["//visibility:public"], +) + +# QNX: always $EXEC_ORIGIN, QCC uses -Wl,-rpath +cc_nested_args( + name = "qnx_rpath_iterate", + args = ["-Wl,-rpath,$EXEC_ORIGIN/{dir}"], + format = {"dir": "@rules_cc//cc/toolchains/variables:runtime_library_search_directories"}, + iterate_over = "@rules_cc//cc/toolchains/variables:runtime_library_search_directories", +) + +cc_args( + name = "runtime_dirs_qnx_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + nested = [":qnx_rpath_iterate"], + requires_not_none = "@rules_cc//cc/toolchains/variables:runtime_library_search_directories", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "runtime_library_search_directories", + args = select({ + "@platforms//os:linux": [":runtime_dirs_linux_args"], + "@platforms//os:qnx": [":runtime_dirs_qnx_args"], + }), + feature_name = "runtime_library_search_directories", + visibility = ["//visibility:public"], +) diff --git a/features/native/shared_flag/BUILD b/features/native/shared_flag/BUILD new file mode 100644 index 0000000..8b5d30d --- /dev/null +++ b/features/native/shared_flag/BUILD @@ -0,0 +1,29 @@ +# ******************************************************************************* +# 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:args.bzl", "cc_args") +load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature") + +cc_args( + name = "shared_flag_args", + actions = ["@rules_cc//cc/toolchains/actions:dynamic_library_link_actions"], + args = ["-shared"], + visibility = ["//visibility:public"], +) + +cc_feature( + name = "shared_flag", + args = [":shared_flag_args"], + feature_name = "shared_flag", + visibility = ["//visibility:public"], +) diff --git a/features/native/static_libgcc/BUILD b/features/native/static_libgcc/BUILD new file mode 100644 index 0000000..af35773 --- /dev/null +++ b/features/native/static_libgcc/BUILD @@ -0,0 +1,39 @@ +# ******************************************************************************* +# 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:args.bzl", "cc_args") +load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature") +load("@rules_cc//cc/toolchains:feature_constraint.bzl", "cc_feature_constraint") + +cc_feature_constraint( + name = "is_static_link_cpp_runtimes", + all_of = ["//features/native/markers:static_link_cpp_runtimes"], +) + +cc_args( + name = "static_libgcc_args", + actions = [ + "@rules_cc//cc/toolchains/actions:cpp_link_executable", + "@rules_cc//cc/toolchains/actions:cpp_link_dynamic_library", + ], + args = ["-static-libgcc"], + requires_any_of = [":is_static_link_cpp_runtimes"], + visibility = ["//visibility:public"], +) + +cc_feature( + name = "static_libgcc", + args = [":static_libgcc_args"], + feature_name = "static_libgcc", + visibility = ["//visibility:public"], +) diff --git a/features/native/strip_debug_symbols/BUILD b/features/native/strip_debug_symbols/BUILD new file mode 100644 index 0000000..6d5626f --- /dev/null +++ b/features/native/strip_debug_symbols/BUILD @@ -0,0 +1,30 @@ +# ******************************************************************************* +# 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:args.bzl", "cc_args") +load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature") + +cc_args( + name = "strip_debug_symbols_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + args = ["-Wl,-S"], + requires_not_none = "@rules_cc//cc/toolchains/variables:strip_debug_symbols", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "strip_debug_symbols", + args = [":strip_debug_symbols_args"], + feature_name = "strip_debug_symbols", + visibility = ["//visibility:public"], +) diff --git a/features/native/sysroot_link_flags/BUILD b/features/native/sysroot_link_flags/BUILD new file mode 100644 index 0000000..73b762d --- /dev/null +++ b/features/native/sysroot_link_flags/BUILD @@ -0,0 +1,15 @@ +# ******************************************************************************* +# 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 +# ******************************************************************************* + +# Instantiated per-toolchain via make_sysroot_link_flags() in features.bzl, since +# each toolchain has a different sysroot directory — see templates/BUILD.template. diff --git a/features/native/sysroot_link_flags/features.bzl b/features/native/sysroot_link_flags/features.bzl new file mode 100644 index 0000000..90fa0cf --- /dev/null +++ b/features/native/sysroot_link_flags/features.bzl @@ -0,0 +1,38 @@ +# ******************************************************************************* +# 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:feature.bzl", "cc_feature") +load("@rules_cc//cc/toolchains/args:sysroot.bzl", "cc_sysroot") + +def make_sysroot_link_flags(target_os, sysroot): + """Creates the sysroot_link_flags feature for this toolchain's sysroot directory. + + cc_sysroot already emits "--sysroot={sysroot}" on its own; only the extra + "-Wl,--sysroot={sysroot}" needs to be listed here. + + Args: + sysroot: label of the directory rule for this toolchain's sysroot. + """ + if target_os == "linux": + cc_sysroot( + name = "sysroot_link_flags_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + args = ["-Wl,--sysroot={sysroot}"], + sysroot = sysroot, + ) + + cc_feature( + name = "sysroot_link_flags", + args = [":sysroot_link_flags_args"], + feature_name = "sysroot_link_flags", + ) diff --git a/features/native/unfiltered_compile_flags/BUILD b/features/native/unfiltered_compile_flags/BUILD new file mode 100644 index 0000000..8ea2d00 --- /dev/null +++ b/features/native/unfiltered_compile_flags/BUILD @@ -0,0 +1,37 @@ +# ******************************************************************************* +# 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:args.bzl", "cc_args") +load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature") + +cc_args( + name = "unfiltered_compile_flags_args", + actions = [ + "@rules_cc//cc/toolchains/actions:c_compile_actions", + "@rules_cc//cc/toolchains/actions:cpp_compile_actions", + ], + args = [ + "-D__DATE__=\"redacted\"", + "-D__TIMESTAMP__=\"redacted\"", + "-D__TIME__=\"redacted\"", + "-Wno-builtin-macro-redefined", + ], + visibility = ["//visibility:public"], +) + +cc_feature( + name = "unfiltered_compile_flags", + args = [":unfiltered_compile_flags_args"], + feature_name = "unfiltered_compile_flags", + visibility = ["//visibility:public"], +) diff --git a/features/native/use_pthread/BUILD b/features/native/use_pthread/BUILD new file mode 100644 index 0000000..85922fc --- /dev/null +++ b/features/native/use_pthread/BUILD @@ -0,0 +1,29 @@ +# ******************************************************************************* +# 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:args.bzl", "cc_args") +load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature") + +cc_args( + name = "use_pthread_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + args = ["-pthread"], + visibility = ["//visibility:public"], +) + +cc_feature( + name = "use_pthread", + args = [":use_pthread_args"], + feature_name = "use_pthread", + visibility = ["//visibility:public"], +) diff --git a/features/native/user_compile_flags/BUILD b/features/native/user_compile_flags/BUILD new file mode 100644 index 0000000..f5a6702 --- /dev/null +++ b/features/native/user_compile_flags/BUILD @@ -0,0 +1,32 @@ +# ******************************************************************************* +# 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:args.bzl", "cc_args") +load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature") + +cc_args( + name = "user_compile_flags_args", + actions = ["@rules_cc//cc/toolchains/actions:compile_actions"], + args = ["{user_compile_flags}"], + format = {"user_compile_flags": "@rules_cc//cc/toolchains/variables:user_compile_flags"}, + iterate_over = "@rules_cc//cc/toolchains/variables:user_compile_flags", + requires_not_none = "@rules_cc//cc/toolchains/variables:user_compile_flags", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "user_compile_flags", + args = [":user_compile_flags_args"], + feature_name = "user_compile_flags", + visibility = ["//visibility:public"], +) diff --git a/features/native/user_link_flags/BUILD b/features/native/user_link_flags/BUILD new file mode 100644 index 0000000..d4e30f2 --- /dev/null +++ b/features/native/user_link_flags/BUILD @@ -0,0 +1,32 @@ +# ******************************************************************************* +# 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:args.bzl", "cc_args") +load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature") + +cc_args( + name = "user_link_flags_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + args = ["{user_link_flags}"], + format = {"user_link_flags": "@rules_cc//cc/toolchains/variables:user_link_flags"}, + iterate_over = "@rules_cc//cc/toolchains/variables:user_link_flags", + requires_not_none = "@rules_cc//cc/toolchains/variables:user_link_flags", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "user_link_flags", + args = [":user_link_flags_args"], + feature_name = "user_link_flags", + visibility = ["//visibility:public"], +) diff --git a/packages/linux/aarch64/autosd/10.0/autosd.BUILD b/packages/linux/aarch64/autosd/10.0/autosd.BUILD index daedfc5..44b2e8f 100644 --- a/packages/linux/aarch64/autosd/10.0/autosd.BUILD +++ b/packages/linux/aarch64/autosd/10.0/autosd.BUILD @@ -59,3 +59,7 @@ filegroup( "lib64/**", ]), ) + +filegroup( + name = "cxx_builtin_include_directories", +) diff --git a/packages/linux/aarch64/ebclfsa/0.1.0/ebclfsa.BUILD b/packages/linux/aarch64/ebclfsa/0.1.0/ebclfsa.BUILD index d909382..44a2303 100644 --- a/packages/linux/aarch64/ebclfsa/0.1.0/ebclfsa.BUILD +++ b/packages/linux/aarch64/ebclfsa/0.1.0/ebclfsa.BUILD @@ -71,3 +71,7 @@ filegroup( name = "sysroot_dir", srcs = ["."], ) + +filegroup( + name = "cxx_builtin_include_directories", +) diff --git a/packages/linux/aarch64/ebclfsa/2.0.0-beta2/ebclfsa.BUILD b/packages/linux/aarch64/ebclfsa/2.0.0-beta2/ebclfsa.BUILD index ed71b2d..6624468 100644 --- a/packages/linux/aarch64/ebclfsa/2.0.0-beta2/ebclfsa.BUILD +++ b/packages/linux/aarch64/ebclfsa/2.0.0-beta2/ebclfsa.BUILD @@ -74,3 +74,7 @@ filegroup( name = "sysroot_dir", srcs = ["."], ) + +filegroup( + name = "cxx_builtin_include_directories", +) \ No newline at end of file diff --git a/packages/linux/aarch64/gcc/12.2.0/gcc.BUILD b/packages/linux/aarch64/gcc/12.2.0/gcc.BUILD index 4725a73..170a138 100644 --- a/packages/linux/aarch64/gcc/12.2.0/gcc.BUILD +++ b/packages/linux/aarch64/gcc/12.2.0/gcc.BUILD @@ -54,3 +54,7 @@ filegroup( name = "sysroot_dir", srcs = ["aarch64-unknown-linux-gnu/sysroot"], ) + +filegroup( + name = "cxx_builtin_include_directories", +) diff --git a/packages/linux/aarch64/gcc/15.3.0/gcc.BUILD b/packages/linux/aarch64/gcc/15.3.0/gcc.BUILD index 4725a73..170a138 100644 --- a/packages/linux/aarch64/gcc/15.3.0/gcc.BUILD +++ b/packages/linux/aarch64/gcc/15.3.0/gcc.BUILD @@ -54,3 +54,7 @@ filegroup( name = "sysroot_dir", srcs = ["aarch64-unknown-linux-gnu/sysroot"], ) + +filegroup( + name = "cxx_builtin_include_directories", +) diff --git a/packages/linux/x86_64/gcc/12.2.0/gcc.BUILD b/packages/linux/x86_64/gcc/12.2.0/gcc.BUILD index dc6fbb1..088dab4 100644 --- a/packages/linux/x86_64/gcc/12.2.0/gcc.BUILD +++ b/packages/linux/x86_64/gcc/12.2.0/gcc.BUILD @@ -54,3 +54,7 @@ filegroup( name = "sysroot_dir", srcs = ["x86_64-unknown-linux-gnu/sysroot"], ) + +filegroup( + name = "cxx_builtin_include_directories", +) diff --git a/packages/linux/x86_64/gcc/15.3.0/gcc.BUILD b/packages/linux/x86_64/gcc/15.3.0/gcc.BUILD index dc6fbb1..088dab4 100644 --- a/packages/linux/x86_64/gcc/15.3.0/gcc.BUILD +++ b/packages/linux/x86_64/gcc/15.3.0/gcc.BUILD @@ -54,3 +54,7 @@ filegroup( name = "sysroot_dir", srcs = ["x86_64-unknown-linux-gnu/sysroot"], ) + +filegroup( + name = "cxx_builtin_include_directories", +) diff --git a/rules/common.bzl b/rules/common.bzl index ad756d6..b61011c 100644 --- a/rules/common.bzl +++ b/rules/common.bzl @@ -22,6 +22,19 @@ load("@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", "flag_group") # uses the older identifier. SDP_VERSION_MAPPING = {"8.0.4": "8.0.0"} +def get_flag_strings(flags): + """Converts a list of warning flags into a Bazel flag group representation. + + Args: + flags (list[str]): A list of compiler warning flags. + + Returns: + str: A formatted string representing the flag group in Bazel syntax. + """ + if len(flags): + return "[" + ", ".join(['"%s"' % f for f in flags]) + "]" + return "None" + def get_flag_groups(flags): """Converts a list of warning flags into a Bazel flag group representation. diff --git a/rules/gcc.bzl b/rules/gcc.bzl index 1a9504b..27df5fb 100644 --- a/rules/gcc.bzl +++ b/rules/gcc.bzl @@ -14,7 +14,7 @@ """ Module rule for defining GCC toolchains in Bazel. """ -load("@score_bazel_cpp_toolchains//rules:common.bzl", "SDP_VERSION_MAPPING", "get_flag_groups", "label_list_to_string") +load("@score_bazel_cpp_toolchains//rules:common.bzl", "SDP_VERSION_MAPPING", "get_flag_groups", "get_flag_strings", "label_list_to_string") # Constants _OS_QNX = "qnx" @@ -52,8 +52,7 @@ def _get_cc_config_linux(rctx): Returns: str: BUILD file content defining filegroup and cc_toolchain_config for Linux. """ - return """ -filegroup( + return """filegroup( name = "all_files", srcs = [ "@{tc_pkg_repo}//:all_files", @@ -71,6 +70,9 @@ cc_toolchain_config( sysroot = "@{tc_pkg_repo}//:sysroot_dir", target_cpu = "{tc_cpu}", target_os = "{tc_os}", + known_features = _KNOWN_FEATURES, + enabled_features = _ENABLED_FEATURES, + cxx_builtin_include_directories = ["@{tc_pkg_repo}//:cxx_builtin_include_directories"], extra_known_features = {tc_extra_known_features}, extra_enabled_features = {tc_extra_enabled_features}, visibility = ["//visibility:public"], @@ -108,11 +110,11 @@ cc_toolchain_config( cxx_binary = "@{tc_pkg_repo}//:cxx", gcov_binary = "@{tc_pkg_repo}//:gcov", strip_binary = "@{tc_pkg_repo}//:strip", - host_dir = "@{tc_pkg_repo}//:host_dir", - target_dir = "@{tc_pkg_repo}//:target_dir", - cxx_builtin_include_directories = "@{tc_pkg_repo}//:cxx_builtin_include_directories", + cxx_builtin_include_directories = ["@{tc_pkg_repo}//:cxx_builtin_include_directories"], target_cpu = "{tc_cpu}", target_os = "{tc_os}", + known_features = _KNOWN_FEATURES, + enabled_features = _ENABLED_FEATURES, extra_known_features = {tc_extra_known_features}, extra_enabled_features = {tc_extra_enabled_features}, visibility = ["//visibility:public"], @@ -125,6 +127,34 @@ cc_toolchain_config( tc_extra_enabled_features = label_list_to_string(rctx.attr.extra_enabled_features), ) +def get_custom_cc_features_linux(rctx): + return "" + +def get_custom_cc_features_qnx(rctx, canonical_pkg_name): + # host_dir/target_dir must be plain resolved paths, not labels: cc_args' + # `env` rejects format() variables that aren't builtin cc_toolchain + # variables ("The variable host_dir does not exist"). + + # TODO: Once Bazel enables label resolution in cc_args' env, we can use labels instead of resolved paths. + + custom_load = """load("@score_bazel_cpp_toolchains//features/custom/qnx/sdp_env:feature.bzl", "make_sdp_env_feature")""" + custom_features = """ +make_sdp_env_feature( + host_dir = "{host_dir}", + target_dir = "{target_dir}", + license_path = "{license_path}", + license_info_variable = "{license_info_variable}", + license_info_value = "{license_info_value}", +) +""".format( + host_dir = "/proc/self/cwd/external/{canonical_pkg}/host/linux/x86_64".format(canonical_pkg = canonical_pkg_name), + target_dir = "/proc/self/cwd/external/{canonical_pkg}/target/qnx".format(canonical_pkg = canonical_pkg_name), + license_path = rctx.attr.license_path, + license_info_variable = rctx.attr.license_info_variable, + license_info_value = rctx.attr.license_info_value, + ) + return custom_load, custom_features + def _normalize_cpu(cpu): """Converts CPU name to its normalized form for toolchain paths. @@ -210,10 +240,22 @@ def _impl(rctx): tc_identifier_short_2 = "-{}".format(rctx.attr.tc_runtime_ecosystem) tc_identifier_long_2 = "[\"@score_bazel_platforms//runtime_es:{}\"]".format(rctx.attr.tc_runtime_ecosystem) + # Get canonical repository name for the toolchain package + canonical_pkg_name = _get_canonical_pkg_name(rctx) + + # Replace %{toolchain_pkg}% placeholder in extra flags with canonical name + def replace_placeholder(flags): + return [flag.replace(_PLACEHOLDER_TOOLCHAIN_PKG, canonical_pkg_name) for flag in flags] + + compiler_library_search_paths = replace_placeholder(rctx.attr.tc_compiler_library_search_paths) + compiler_library_search_paths_str = ":".join(["/proc/self/cwd/" + entry for entry in compiler_library_search_paths]) + rctx.template( "BUILD", rctx.attr._cc_toolchain_build, { + "%{tc_custom_feature_load}": get_custom_cc_features_qnx(rctx, canonical_pkg_name)[0] if rctx.attr.tc_os == _OS_QNX else "", + "%{tc_custom_features}": get_custom_cc_features_qnx(rctx, canonical_pkg_name)[1] if rctx.attr.tc_os == _OS_QNX else "", "%{cc_toolchain_config}": cc_toolchain_config, "%{tc_cpu}": rctx.attr.tc_cpu, "%{tc_identifier}": tc_identifier, @@ -221,6 +263,12 @@ def _impl(rctx): "%{tc_pkg_repo}": rctx.attr.tc_pkg_repo, "%{tc_runtime_es}": rctx.attr.tc_runtime_ecosystem, "%{tc_version}": rctx.attr.gcc_version, + "%{tc_sysroot}": "@{tc_pkg_repo}//:sysroot_dir".format(tc_pkg_repo = rctx.attr.tc_pkg_repo), + "%{tc_extra_compile_flags}": get_flag_strings(replace_placeholder(rctx.attr.extra_compile_flags)), + "%{tc_extra_c_compile_flags}": get_flag_strings(replace_placeholder(rctx.attr.extra_c_compile_flags)), + "%{tc_extra_cxx_compile_flags}": get_flag_strings(replace_placeholder(rctx.attr.extra_cxx_compile_flags)), + "%{tc_extra_link_flags}": get_flag_strings(replace_placeholder(rctx.attr.extra_link_flags)), + "%{tc_compiler_library_search_paths}": compiler_library_search_paths_str, "%{tc_identifier_short_1}": tc_identifier_short_1, "%{tc_identifier_short_2}": tc_identifier_short_2, "%{tc_identifier_long_1}": tc_identifier_long_1, @@ -228,22 +276,14 @@ def _impl(rctx): }, ) - # Get canonical repository name for the toolchain package - canonical_pkg_name = _get_canonical_pkg_name(rctx) - - # Replace %{toolchain_pkg}% placeholder in extra flags with canonical name - def replace_placeholder(flags): - return [flag.replace(_PLACEHOLDER_TOOLCHAIN_PKG, canonical_pkg_name) for flag in flags] - extra_compile_flags = get_flag_groups(replace_placeholder(rctx.attr.extra_compile_flags)) extra_c_compile_flags = get_flag_groups(replace_placeholder(rctx.attr.extra_c_compile_flags)) extra_cxx_compile_flags = get_flag_groups(replace_placeholder(rctx.attr.extra_cxx_compile_flags)) 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]), + "%{compiler_library_search_paths}": compiler_library_search_paths_str, "%{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", @@ -252,6 +292,7 @@ def _impl(rctx): "%{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, + "%{tc_compiler}": "gcc", "%{tc_cpu}": _normalize_cpu(rctx.attr.tc_cpu), "%{tc_identifier}": "gcc", "%{tc_runtime_es}": rctx.attr.tc_runtime_ecosystem, @@ -260,12 +301,16 @@ def _impl(rctx): if rctx.attr.tc_os == _OS_QNX: mapped_sdp_version = _apply_sdp_version_mapping(rctx.attr.sdp_version) + qnx_identifier = "{cpu}-qnx{sdp}".format(cpu = _normalize_cpu(rctx.attr.tc_cpu), sdp = mapped_sdp_version) extra_template_dict = { "%{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_abi_version}": qnx_identifier, + "%{tc_compiler}": "qcc", "%{tc_cpu_cxx}": _normalize_cpu(rctx.attr.tc_cpu), + "%{tc_identifier}": qnx_identifier, "%{use_license_info}": "False" if rctx.attr.license_info_value == "" else "True", } template_dict = dict_union(template_dict, extra_template_dict) @@ -276,12 +321,6 @@ def _impl(rctx): template_dict, ) - rctx.template( - "flags.bzl", - rctx.attr.cc_toolchain_flags, - {}, - ) - 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 @@ -320,9 +359,6 @@ gcc_toolchain = repository_rule( "cc_toolchain_config": attr.label( doc = "Path to the cc_config.bzl template file.", ), - "cc_toolchain_flags": attr.label( - doc = "Path to the Bazel BUILD file template for the toolchain.", - ), "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."), @@ -344,7 +380,7 @@ gcc_toolchain = repository_rule( "tc_runtime_ecosystem": attr.string(doc = "Runtime ecosystem."), "tc_system_toolchain": attr.bool(doc = "Boolean flag to state if this is a system toolchain"), "_cc_gcov_wrapper_script": attr.label( - default = "@score_bazel_cpp_toolchains//templates/linux:cc_gcov_wrapper.template", + default = "@score_bazel_cpp_toolchains//templates:cc_gcov_wrapper.template", ), "_cc_toolchain_build": attr.label( default = "@score_bazel_cpp_toolchains//templates:BUILD.template", diff --git a/templates/BUILD.template b/templates/BUILD.template index b7548da..55520bb 100644 --- a/templates/BUILD.template +++ b/templates/BUILD.template @@ -15,8 +15,37 @@ """ load("@rules_cc//cc:defs.bzl", "cc_toolchain") +load("@score_bazel_cpp_toolchains//features/custom/%{tc_os}:make_cc_features.bzl", "get_feature_lists") +load("@score_bazel_cpp_toolchains//features/native/extra_compile_flags:features.bzl", "make_extra_compile_features") +load("@score_bazel_cpp_toolchains//features/native/extra_link_flags:features.bzl", "make_extra_link_features") +load("@score_bazel_cpp_toolchains//features/native/compiler_library_search_paths:features.bzl", "make_compiler_library_search_paths") +load("@score_bazel_cpp_toolchains//features/native/sysroot_link_flags:features.bzl", "make_sysroot_link_flags") +%{tc_custom_feature_load} load(":cc_toolchain_config.bzl", "cc_toolchain_config") +make_extra_compile_features( + extra_compile_flags = %{tc_extra_compile_flags}, + extra_c_compile_flags = %{tc_extra_c_compile_flags}, + extra_cxx_compile_flags = %{tc_extra_cxx_compile_flags}, +) + +make_extra_link_features( + extra_link_flags = %{tc_extra_link_flags} +) + +make_compiler_library_search_paths( + compiler_library_search_paths = "%{tc_compiler_library_search_paths}", +) + +make_sysroot_link_flags( + target_os = "%{tc_os}", + sysroot = "%{tc_sysroot}", +) +%{tc_custom_features} +# known_features must list every feature (enabled or opt-in); enabled_features is +# the order-irrelevant subset that should start on. See compute_feature_lists(). +_KNOWN_FEATURES, _ENABLED_FEATURES = get_feature_lists() + filegroup( name = "empty", ) diff --git a/templates/linux/cc_gcov_wrapper.template b/templates/cc_gcov_wrapper.template similarity index 100% rename from templates/linux/cc_gcov_wrapper.template rename to templates/cc_gcov_wrapper.template diff --git a/templates/cc_toolchain_config.bzl.template b/templates/cc_toolchain_config.bzl.template new file mode 100644 index 0000000..5b9a426 --- /dev/null +++ b/templates/cc_toolchain_config.bzl.template @@ -0,0 +1,178 @@ +# ******************************************************************************* +# 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 +# ******************************************************************************* + +"""C/C++ toolchain definition""" + +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", "cc_common", "CcToolchainConfigInfo") +load("@rules_cc//cc/toolchains:feature_injection.bzl", "convert_feature", "FeatureInfo") + +def _impl(ctx): + 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 = [ + convert_feature(known_feature[FeatureInfo], enabled = known_feature in ctx.attr.enabled_features) + for known_feature in ctx.attr.known_features + ] + + 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()]) + + # Get builtin include directories from attribute if provided + cxx_builtin_include_directories = [ + "/proc/self/cwd/{}".format(include_directory.path) + for include_directory in ctx.files.cxx_builtin_include_directories + ] + + sysroot = None + if ctx.attr.sysroot != None: + sysroot = ctx.attr.sysroot[DefaultInfo].files.to_list()[0].path + + # 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_abi_version}", + abi_libc_version = "unknown", + builtin_sysroot = sysroot, + compiler = "%{tc_compiler}", + cxx_builtin_include_directories = cxx_builtin_include_directories, + features = features, + action_configs = action_configs, + host_system_name = "local", + target_system_name = "%{tc_cpu}-%{tc_os}", + target_cpu = ctx.attr.target_cpu, + target_libc = "unknown", + toolchain_identifier = "%{tc_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), + "target_cpu": attr.string(mandatory = True), + "target_os": attr.string(mandatory = True), + "sysroot": attr.label(default = None), + "cxx_builtin_include_directories": attr.label_list(allow_files = True, default = []), + "known_features": attr.label_list( + providers = [FeatureInfo], + mandatory = True, + ), + "enabled_features": attr.label_list( + providers = [FeatureInfo], + 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. +""", + ), + }, +) diff --git a/templates/linux/cc_toolchain_config.bzl.template b/templates/linux/cc_toolchain_config.bzl.template deleted file mode 100644 index c5480ff..0000000 --- a/templates/linux/cc_toolchain_config.bzl.template +++ /dev/null @@ -1,1050 +0,0 @@ -# ******************************************************************************* -# 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 -# ******************************************************************************* - -"""C/C++ toolchain definition""" - -load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") -load("@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", - "action_config", - "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", - "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", -) - -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( - 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, - ] - - # 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. - compiler_library_search_paths = "%{compiler_library_search_paths}" - compiler_library_search_paths_feature = feature( - name = "compiler_library_search_paths", - enabled = %{compiler_library_search_paths_switch}, - env_sets = [ - env_set( - actions = all_actions, - env_entries = [env_entry(key = "LD_LIBRARY_PATH", value = compiler_library_search_paths)] if compiler_library_search_paths != "" else [], - ), - ], - ) - - 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 - else: - 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, - flag_groups = DEFAULT_COMPILE_FLAGS, - ), - flag_set( - actions = all_compile_actions, - flag_groups = target_cpu_flags, - ), - flag_set( - 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, - flag_groups = [flag_group(flags = ["-std=gnu11"])], - with_features = [with_feature_set(features = ["gnu11"])], - ), - flag_set( - actions = all_cpp_compile_actions, - flag_groups = DEFAULT_CXX_COMPILE_FLAGS, - ), - flag_set( - actions = all_compile_actions, - flag_groups = DBG_COMPILE_FLAGS, - with_features = [with_feature_set(features = ["dbg"])], - ), - flag_set( - actions = all_compile_actions, - flag_groups = OPT_COMPILE_FLAGS, - with_features = [ - with_feature_set(features = ["opt"]), - with_feature_set(features = ["fastbuild"]), - ], - ), - ], - ) - - # Add sysroot linker flags as a separate feature (always enabled) - sysroot_link_flags_feature_flag_sets = [] - if ctx.attr.sysroot != None: - sysroot_files = ctx.attr.sysroot[DefaultInfo].files.to_list() - if sysroot_files: - sysroot_path = sysroot_files[0].path - sysroot_link_flags_feature_flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [flag_group(flags = [ - "--sysroot=" + sysroot_path, - "-Wl,--sysroot=" + sysroot_path, - ])], - ), - ] - - sysroot_link_flags_feature = feature( - name = "sysroot_link_flags", - enabled = True, - flag_sets = sysroot_link_flags_feature_flag_sets, - ) - - # Only enable default link flags if extra link flags are not provided - default_link_flags_enabled = not %{extra_link_flags_switch} - default_link_flags_feature = feature( - name = "default_link_flags", - enabled = default_link_flags_enabled, - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = DEFAULT_LINK_FLAGS, - ), - flag_set( - 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, - flag_groups = [ - flag_group( - flags = [ - "-Wl,--compress-debug-sections=zlib", - ], - ), - ], - with_features = [with_feature_set(not_features = ["opt"])], - ), - ], - ) - - extra_compile_flags = %{extra_compile_flags} - extra_compile_flags_feature = feature( - name = "extra_compile_flags", - enabled = %{extra_compile_flags_switch}, - implies = ["default_compile_flags"], - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = extra_compile_flags, - ), - ], - ) - - extra_c_compile_flags = %{extra_c_compile_flags} - extra_c_compile_flags_feature = feature( - name = "extra_c_compile_flags", - enabled = %{extra_c_compile_flags_switch}, - implies = ["default_compile_flags"], - flag_sets = [ - flag_set( - actions = all_c_compile_actions, - flag_groups = extra_c_compile_flags, - ), - ], - ) - - extra_cxx_compile_flags = %{extra_cxx_compile_flags} - extra_cxx_compile_flags_feature = feature( - name = "extra_cxx_compile_flags", - enabled = %{extra_cxx_compile_flags_switch}, - implies = ["default_compile_flags"], - flag_sets = [ - flag_set( - actions = all_cpp_compile_actions, - flag_groups = extra_cxx_compile_flags, - ), - ], - ) - - extra_link_flags = %{extra_link_flags} - extra_link_flags_feature = feature( - name = "extra_link_flags", - enabled = %{extra_link_flags_switch}, - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = extra_link_flags, - ), - ], - ) - - pthread_feature = feature( - name = "use_pthread", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [ - flag_group(flags = ["-pthread"]), - ], - ), - ], - ) - - 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, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.objc_compile, - ACTION_NAMES.objcpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.clif_match, - ], - flag_groups = [ - flag_group( - flags = ["-MD", "-MF", "%{dependency_file}"], - expand_if_available = "dependency_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}"], - expand_if_available = "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, - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [ - flag_group( - iterate_over = "runtime_library_search_directories", - flag_groups = [ - flag_group( - flags = ["-Wl,-rpath,$ORIGIN/%{runtime_library_search_directories}"], - expand_if_true = "is_cc_test", - ), - flag_group( - flags = ["-Wl,-rpath,$EXEC_ORIGIN/%{runtime_library_search_directories}"], - expand_if_false = "is_cc_test", - ), - ], - expand_if_available = "runtime_library_search_directories", - ), - ], - ), - ], - ) - - 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. - # - # These mirror features that Bazel's legacy toolchain machinery would add - # automatically. All except fully_static_link are guarded (via - # expand_if_available or with_features) so they are no-ops for normal builds - # and only emit flags when the relevant build mode is active (e.g. --fission, - # --force_pic, --stamp). They are therefore enabled by default. - # - # fully_static_link is left DISABLED by default because it emits -static - # unconditionally, which would force fully static linking for every target. - # Users who want it must opt in explicitly, e.g. via `--features=`. - # ------------------------------------------------------------------------ - - # Fission: emit split DWARF debug info into separate .dwo files at compile. - per_object_debug_info_feature = feature( - name = "per_object_debug_info", - 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, - ], - flag_groups = [ - flag_group( - flags = ["-gsplit-dwarf", "-g"], - expand_if_available = "per_object_debug_info_file", - ), - ], - ), - ], - ) - - # Fission: emit a .gdb_index section at link when fission is in use. - fission_support_feature = feature( - name = "fission_support", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [ - flag_group( - flags = ["-Wl,--gdb-index"], - expand_if_available = "is_using_fission", - ), - ], - ), - ], - ) - - # Pass linkstamp object files to the linker (used with --stamp). - linkstamps_feature = feature( - name = "linkstamps", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [ - flag_group( - iterate_over = "linkstamp_paths", - flags = ["%{linkstamp_paths}"], - expand_if_available = "linkstamp_paths", - ), - ], - ), - ], - ) - - # Force-include headers via -include (the `includes` build variable). - includes_feature = feature( - name = "includes", - enabled = True, - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = [ - flag_group( - iterate_over = "includes", - flags = ["-include", "%{includes}"], - expand_if_available = "includes", - ), - ], - ), - ], - ) - - # Build position-independent executables under --force_pic. - force_pic_flags_feature = feature( - name = "force_pic_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = [ACTION_NAMES.cpp_link_executable], - flag_groups = [ - flag_group( - flags = ["-pie"], - expand_if_available = "force_pic", - ), - ], - ), - ], - ) - - # Strip debug symbols at link time. - strip_debug_symbols_feature = feature( - name = "strip_debug_symbols", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [ - flag_group( - flags = ["-Wl,-S"], - expand_if_available = "strip_debug_symbols", - ), - ], - ), - ], - ) - - # Statically link libgcc (paired with static_link_cpp_runtimes). - static_libgcc_feature = feature( - name = "static_libgcc", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.cpp_link_executable, - ACTION_NAMES.cpp_link_dynamic_library, - ], - flag_groups = [flag_group(flags = ["-static-libgcc"])], - with_features = [ - with_feature_set(features = ["static_link_cpp_runtimes"]), - ], - ), - ], - ) - - # Fully static link (-static) under --dynamic_mode=fully. - fully_static_link_feature = feature( - name = "fully_static_link", - enabled = False, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.cpp_link_executable, - ACTION_NAMES.cpp_link_dynamic_library, - ACTION_NAMES.cpp_link_nodeps_dynamic_library, - ], - flag_groups = [flag_group(flags = ["-static"])], - ), - ], - ) - - # Feature to disable absolute path warnings for system headers - supports_header_path_normalization = feature( - name = "supports_header_path_normalization", - enabled = True, - ) - - coverage_feature = feature(name = "coverage") - gcc_coverage_map_format_feature = feature( - name = "gcc_coverage_map_format", - provides = ["profile"], - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.preprocess_assemble, - ], - flag_groups = [flag_group( - expand_if_available = "gcov_gcno_file", - flags = ["-fprofile-arcs", "-ftest-coverage"], - )], - ), - flag_set( - actions = all_link_actions, - flag_groups = [flag_group(flags = ["--coverage"])], - ), - ], - requires = [feature_set(features = ["coverage"])], - ) - - # 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 = [ - no_legacy_features_feature, - compiler_library_search_paths_feature, - dbg_feature, - unfiltered_compile_flags_feature, - gnu11_feature, - default_compile_flags_feature, - random_seed_feature, - include_paths_feature, - preprocessor_defines_feature, - extra_compile_flags_feature, - extra_c_compile_flags_feature, - extra_cxx_compile_flags_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, - archiver_flags_feature, - linker_param_file_feature, - library_search_directories_feature, - shared_flag_feature, - output_execpath_flags_feature, - runtime_library_search_directories_feature, - libraries_to_link_feature, - user_link_flags_feature, - linkstamps_feature, - fission_support_feature, - force_pic_flags_feature, - strip_debug_symbols_feature, - static_libgcc_feature, - fully_static_link_feature, - sysroot_link_flags_feature, - pthread_feature, - extra_link_flags_feature, - opt_feature, - supports_dynamic_linker_feature, - supports_pic_feature, - pic_feature, - supports_header_path_normalization, - supports_fission_feature, - coverage_feature, - 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()]) - - # 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_libc_version = "unknown", - builtin_sysroot = sysroot, - compiler = "gcc", - cxx_builtin_include_directories = cxx_builtin_include_directories, - features = features, - action_configs = action_configs, - host_system_name = "local", - target_system_name = "%{tc_cpu}-%{tc_os}", - target_cpu = ctx.attr.target_cpu, - target_libc = "unknown", - toolchain_identifier = "%{tc_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 diff --git a/templates/linux/cc_toolchain_flags.bzl.template b/templates/linux/cc_toolchain_flags.bzl.template deleted file mode 100644 index 416275e..0000000 --- a/templates/linux/cc_toolchain_flags.bzl.template +++ /dev/null @@ -1,95 +0,0 @@ -# ******************************************************************************* -# 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", -]) - -# Default compile flags when no specific build type is selected. -DEFAULT_COMPILE_FLAGS = get_flag_group([ - "-U_FORTIFY_SOURCE", - "-D_XOPEN_SOURCE=700", - "-fstack-protector", - "-fdiagnostics-color=always", - "-fno-omit-frame-pointer", - "-ffunction-sections", - "-fdata-sections", - "-fno-canonical-system-headers", - "-no-canonical-prefixes", - "-z noexecstack", -]) - -# TODO: Check if we need this. -DEFAULT_x86_64_COMPILE_FLAGS = get_flag_group([ - "-m64", -]) - -DEFAULT_ARM64_COMPILE_FLAGS = get_flag_group([ -]) - -# Default compile flags for C language when no specific build type is selected. -DEFAULT_C_COMPILE_FLAGS = get_flag_group([ -]) - -# Default compile flags for C++ language when no specific build type is selected. -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", - "-ldl", - "-lrt", - "-static-libstdc++", - "-static-libgcc", -]) - diff --git a/templates/qnx/cc_toolchain_config.bzl.template b/templates/qnx/cc_toolchain_config.bzl.template deleted file mode 100644 index 4c8f06a..0000000 --- a/templates/qnx/cc_toolchain_config.bzl.template +++ /dev/null @@ -1,817 +0,0 @@ -# ******************************************************************************* -# 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 -# ******************************************************************************* - -"""C/C++ toolchain definition""" - -load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") -load("@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", - "action_config", - "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", - "DEFAULT_COMPILE_FLAGS", - "DEFAULT_C_COMPILE_FLAGS", - "DEFAULT_CXX_COMPILE_FLAGS", - "DEFAULT_LINK_FLAGS", - "DBG_COMPILE_FLAGS", - "OPT_COMPILE_FLAGS", -) - -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)], - ) - 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, - ] - - # 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}"], - expand_if_available = "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", - enabled = True, - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = DEFAULT_COMPILE_FLAGS, - ), - flag_set( - actions = all_compile_actions, - flag_groups = [flag_group(flags = ["-V%{tc_version},gcc_nto%{tc_cpu}"])], - ), - flag_set( - actions = all_c_compile_actions, - flag_groups = DEFAULT_C_COMPILE_FLAGS, - ), - flag_set( - actions = all_cpp_compile_actions, - flag_groups = DEFAULT_CXX_COMPILE_FLAGS, - ), - flag_set( - actions = all_compile_actions, - flag_groups = DBG_COMPILE_FLAGS, - with_features = [with_feature_set(features = ["dbg"])], - ), - flag_set( - actions = all_compile_actions, - flag_groups = OPT_COMPILE_FLAGS, - with_features = [ - with_feature_set(features = ["opt"]), - with_feature_set(features = ["fastbuild"]), - ], - ), - ], - ) - - default_link_flags_feature = feature( - name = "default_link_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [flag_group(flags = ["-V%{tc_version},gcc_nto%{tc_cpu}_cxx"])], - ), - flag_set( - actions = all_link_actions, - flag_groups = DEFAULT_LINK_FLAGS, - ), - ], - ) - - extra_compile_flags = %{extra_compile_flags} - extra_compile_flags_feature = feature( - name = "extra_compile_flags", - enabled = %{extra_compile_flags_switch}, - implies = ["default_compile_flags"], - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = extra_compile_flags, - ), - ], - ) - - extra_link_flags = %{extra_link_flags} - extra_link_flags_feature = feature( - name = "extra_link_flags", - enabled = %{extra_link_flags_switch}, - implies = ["default_link_flags"], - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = extra_link_flags, - ), - ], - ) - 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", - enabled = False, - ) - - use_license_env_info_feautre = feature( - name = "qnx_license_env_info", - enabled = %{use_license_info}, - ) - - license_variable = "%{license_info_variable}" - license_value = "%{license_info_value}" - - sdp_env_feature = feature( - name = "sdp_env", - enabled = True, - env_sets = [ - env_set( - actions = all_compile_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), - env_entry(key = "QNX_CONFIGURATION_EXCLUSIVE", value = "/var/tmp/.qnx"), - env_entry(key = "QNX_SHARED_LICENSE_FILE", value = "%{license_path}"), - ], - ), - env_set( - actions = all_compile_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"])], - ) - ], - ) - - dependency_file_feature = feature( - name = "dependency_file", - 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_compile, - ACTION_NAMES.objc_compile, - ACTION_NAMES.objcpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.clif_match, - ], - flag_groups = [flag_group( - flags = [ - "-Wc,-MD,%{dependency_file}", - "-Wp,-MD,%{dependency_file}", - ], - expand_if_available = "dependency_file", - )], - with_features = [ - with_feature_set(not_features = ["dependency_file_named_implicitly"]), - ], - ), - flag_set( - actions = [ - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.objc_compile, - ACTION_NAMES.objcpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.clif_match, - ], - flag_groups = [flag_group(flags = [ - "-Wc,-MD", - "-Wp,-MD", - ])], - with_features = [ - with_feature_set(features = ["dependency_file_named_implicitly"]), - ], - ), - ], - ) - - # QNX uses -Wl,-rpath instead of -rpath - runtime_library_search_directories_feature = feature( - name = "runtime_library_search_directories", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [ - flag_group( - iterate_over = "runtime_library_search_directories", - flag_groups = [ - flag_group( - flags = ["-Wl,-rpath,$EXEC_ORIGIN/%{runtime_library_search_directories}"], - ), - ], - expand_if_available = "runtime_library_search_directories", - ), - ], - ), - ], - ) - - coverage_feature = feature(name = "coverage") - gcc_coverage_map_format_feature = feature( - name = "gcc_coverage_map_format", - provides = ["profile"], - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.preprocess_assemble, - ], - flag_groups = [flag_group( - expand_if_available = "gcov_gcno_file", - flags = ["-fprofile-arcs", "-ftest-coverage"], - )], - ), - flag_set( - actions = all_link_actions, - flag_groups = [flag_group(flags = ["-lgcov"])], - ), - ], - ) - - # 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 = [ - dbg_feature, - no_legacy_features_feature, - unfiltered_compile_flags_feature, - default_compile_flags_feature, - random_seed_feature, - include_paths_feature, - preprocessor_defines_feature, - extra_compile_flags_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, - archiver_flags_feature, - linker_param_file_feature, - library_search_directories_feature, - shared_flag_feature, - output_execpath_flags_feature, - libraries_to_link_feature, - user_link_flags_feature, - coverage_feature, - extra_link_flags_feature, - opt_feature, - use_license_env_info_feautre, - sdp_env_feature, - supports_dynamic_linker_feature, - supports_pic_feature, - pic_feature, - runtime_library_search_directories_feature, - 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()]) - - 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_libc_version = "unknown", - compiler = "qcc", - cxx_builtin_include_directories = cxx_builtin_include_directories, - features = features, - action_configs = action_configs, - host_system_name = "local", - target_system_name = "%{tc_cpu}-qnx", - target_cpu = "%{tc_cpu}", - target_libc = "unknown", - toolchain_identifier = "%{tc_cpu}-qnx%{sdp_version}", - 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. -""", - ), - }, -) diff --git a/templates/qnx/cc_toolchain_flags.bzl.template b/templates/qnx/cc_toolchain_flags.bzl.template deleted file mode 100644 index 52c2bf3..0000000 --- a/templates/qnx/cc_toolchain_flags.bzl.template +++ /dev/null @@ -1,81 +0,0 @@ -# ******************************************************************************* -# 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", -]) - -# Default compile flags when no specific build type is selected. -DEFAULT_COMPILE_FLAGS = get_flag_group([ - "-fno-canonical-system-headers", -]) - -# Default compile flags for C language when no specific build type is selected. -DEFAULT_C_COMPILE_FLAGS = get_flag_group([ - "-std=c11", -]) - -# Default compile flags for C++ language when no specific build type is selected. -DEFAULT_CXX_COMPILE_FLAGS = get_flag_group([ - "-D_QNX_SOURCE", - "-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", - "-Wl,-z,now", - "-Wl,--push-state", - "-Wl,--as-needed", - "-lc++", - "-lm", - "-Wl,--pop-state", -]) diff --git a/tests/.bazelversion b/tests/.bazelversion index e7fdef7..acd405b 100644 --- a/tests/.bazelversion +++ b/tests/.bazelversion @@ -1 +1 @@ -8.4.2 +8.6.0 diff --git a/tests/MODULE.bazel.lock b/tests/MODULE.bazel.lock index 0d7218f..fc24e7e 100644 --- a/tests/MODULE.bazel.lock +++ b/tests/MODULE.bazel.lock @@ -1,5 +1,5 @@ { - "lockFileVersion": 18, + "lockFileVersion": 24, "registryFileHashes": { "https://bcr.bazel.build/bazel_registry.json": "8a28e4aff06ee60aed2a8c281907fb8bcbf3b753c91fb5a5c57da3215d5b3497", "https://bcr.bazel.build/modules/abseil-cpp/20210324.2/MODULE.bazel": "7cd0312e064fde87c8d1cd79ba06c876bd23630c83466e9500321be55c96ace2", @@ -606,7 +606,7 @@ "moduleExtensions": { "@@aspect_rules_js+//npm:extensions.bzl%pnpm": { "general": { - "bzlTransitiveDigest": "c+aduAtzWJ+Sfmy4J0UmLN9iqbGkiP1HPlR9NZBfOdU=", + "bzlTransitiveDigest": "mBV5IQWX7FWfZbz6MJP8c7oawhjJCmyPytourZpcJ94=", "usagesDigest": "ZYGEy1FrDUNPBzAzD+ujlHkMEsVPMYOvpHm9RhUexUE=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, @@ -704,7 +704,7 @@ }, "@@aspect_rules_py+//py:extensions.bzl%py_tools": { "general": { - "bzlTransitiveDigest": "dAWBz6nfg2GIP7kchPavcBdWoHNQ67aXhXo4MPJJqNk=", + "bzlTransitiveDigest": "VfJYy1B5v3oMq9SNoz4hGTKf+uJgqbxHJYD8rdhivHo=", "usagesDigest": "NC1b49l5tenTBVWEUGzzC0j5Kg1GH+l5lBw5JRCldIU=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, @@ -846,7 +846,7 @@ }, "@@pybind11_bazel+//:internal_configure.bzl%internal_configure_extension": { "general": { - "bzlTransitiveDigest": "G7xCmtNWXRuBtChRgB5OK5+gmM8Uoy8Mec/B7j3fhqs=", + "bzlTransitiveDigest": "NFQjcZF+fAvf5fDH+pqsx4JrfzP9PuHBz6S6ZutIbnw=", "usagesDigest": "D1r3lfzMuUBFxgG8V6o0bQTLMk3GkaGOaPzw53wrwyw=", "recordedFileInputs": { "@@pybind11_bazel+//MODULE.bazel": "e6f4c20442eaa7c90d7190d8dc539d0ab422f95c65a57cc59562170c58ae3d34" @@ -876,7 +876,7 @@ }, "@@rules_buf+//buf:extensions.bzl%buf": { "general": { - "bzlTransitiveDigest": "nziVPz62Pjv2JecWM9NXmhpU/OjKhPz1MT9++4ObLUw=", + "bzlTransitiveDigest": "dSWqckK2ILN7aDIDHfv+Qrl1fb1hF7o7MDXY6T8C41s=", "usagesDigest": "vxN6C2h72rUERbAmd1476FWpxdxo1NhYoY5JSFXJT3g=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, @@ -901,7 +901,7 @@ }, "@@rules_fuzzing+//fuzzing/private:extensions.bzl%non_module_dependencies": { "general": { - "bzlTransitiveDigest": "v2H25KPHEkN56IHR41S67Kzp5Xjxd75GBiazhON8jzc=", + "bzlTransitiveDigest": "4LouzhF/yT117s7peGnNs9ROomiJXC6Zl5R0oI21jho=", "usagesDigest": "wy6ISK6UOcBEjj/mvJ/S3WeXoO67X+1llb9yPyFtPgc=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, @@ -984,7 +984,7 @@ }, "@@rules_kotlin+//src/main/starlark/core/repositories:bzlmod_setup.bzl%rules_kotlin_extensions": { "general": { - "bzlTransitiveDigest": "OlvsB0HsvxbR8ZN+J9Vf00X/+WVz/Y/5Xrq2LgcVfdo=", + "bzlTransitiveDigest": "nvW/NrBXlAmiQw99EMGKkLaD2KbNp2mQDlxdfpr+0Ls=", "usagesDigest": "QI2z8ZUR+mqtbwsf2fLqYdJAkPOHdOV+tF2yVAUgRzw=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, @@ -1218,7 +1218,7 @@ }, "@@rules_rust+//crate_universe/private:internal_extensions.bzl%cu_nr": { "general": { - "bzlTransitiveDigest": "oRwNDJU+OUmkvm5VgB12Uzf5d82zFgjjyx2akug8OTs=", + "bzlTransitiveDigest": "LY3h7UGxJswyK9i5VjXKBDtH6q5lVEKqAAl5FCJt5qE=", "usagesDigest": "dQ7SQZ7uSSL3vVKSMBKRxKJUm9OVrZZA+S1/QQfT570=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, @@ -1370,7 +1370,7 @@ }, "@@score_bazel_cpp_toolchains+//extensions:gcc.bzl%gcc": { "general": { - "bzlTransitiveDigest": "YbbJoOHV79wbmLSzyW0+FVq+0ih1OuW6v1am9MzMOmg=", + "bzlTransitiveDigest": "dffSoCJVMsbso/wS4jpQI/Uab9lB/i4ftLn6XkLcoAc=", "usagesDigest": "3BxGiccNNlFja9y/vd4+7TlTcgtjWIybmed7P06K9QM=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, @@ -1532,8 +1532,7 @@ "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_config": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_config.bzl.template", "use_base_constraints_only": true } }, @@ -1559,8 +1558,7 @@ "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_config": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_config.bzl.template", "use_base_constraints_only": false } }, @@ -1586,8 +1584,7 @@ "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_config": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_config.bzl.template", "use_base_constraints_only": false } }, @@ -1613,8 +1610,7 @@ "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_config": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_config.bzl.template", "use_base_constraints_only": false } }, @@ -1640,8 +1636,7 @@ "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_config": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_config.bzl.template", "use_base_constraints_only": false } }, @@ -1669,8 +1664,7 @@ "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_config": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_config.bzl.template", "use_base_constraints_only": false } }, @@ -1696,8 +1690,7 @@ "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_config": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_config.bzl.template", "use_base_constraints_only": false } }, @@ -1723,8 +1716,7 @@ "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_config": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_config.bzl.template", "use_base_constraints_only": false } }, @@ -1786,8 +1778,7 @@ "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_config": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_config.bzl.template", "use_base_constraints_only": false } }, @@ -1865,8 +1856,7 @@ "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_config": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_config.bzl.template", "use_base_constraints_only": false } }, @@ -1945,8 +1935,7 @@ "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_config": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_config.bzl.template", "use_base_constraints_only": false } } @@ -1977,7 +1966,7 @@ }, "@@score_rules_imagefs+//extensions:imagefs.bzl%imagefs": { "general": { - "bzlTransitiveDigest": "x/MeLfkCFKL5zGGdqxO8ikFOoWzlkB1VBe5tts2t0NI=", + "bzlTransitiveDigest": "6ZLANe53LXwcnne1ZrZm9GkJ9H5VdsCLSgSNHyUrqA4=", "usagesDigest": "4LvOoMbWgpZh1KrPMaxsrJ/9n3DRlU6JijkThVx2Cw0=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, @@ -2028,5 +2017,171 @@ ] } } + }, + "facts": { + "@@rules_go+//go:extensions.bzl%go_sdk": { + "1.25.0": { + "aix_ppc64": [ + "go1.25.0.aix-ppc64.tar.gz", + "e5234a7dac67bc86c528fe9752fc9d63557918627707a733ab4cac1a6faed2d4" + ], + "darwin_amd64": [ + "go1.25.0.darwin-amd64.tar.gz", + "5bd60e823037062c2307c71e8111809865116714d6f6b410597cf5075dfd80ef" + ], + "darwin_arm64": [ + "go1.25.0.darwin-arm64.tar.gz", + "544932844156d8172f7a28f77f2ac9c15a23046698b6243f633b0a0b00c0749c" + ], + "dragonfly_amd64": [ + "go1.25.0.dragonfly-amd64.tar.gz", + "5ed3cf9a810a1483822538674f1336c06b51aa1b94d6d545a1a0319a48177120" + ], + "freebsd_386": [ + "go1.25.0.freebsd-386.tar.gz", + "abea5d5c6697e6b5c224731f2158fe87c602996a2a233ac0c4730cd57bf8374e" + ], + "freebsd_amd64": [ + "go1.25.0.freebsd-amd64.tar.gz", + "86e6fe0a29698d7601c4442052dac48bd58d532c51cccb8f1917df648138730b" + ], + "freebsd_arm": [ + "go1.25.0.freebsd-arm.tar.gz", + "d90b78e41921f72f30e8bbc81d9dec2cff7ff384a33d8d8debb24053e4336bfe" + ], + "freebsd_arm64": [ + "go1.25.0.freebsd-arm64.tar.gz", + "451d0da1affd886bfb291b7c63a6018527b269505db21ce6e14724f22ab0662e" + ], + "freebsd_riscv64": [ + "go1.25.0.freebsd-riscv64.tar.gz", + "7b565f76bd8bda46549eeaaefe0e53b251e644c230577290c0f66b1ecdb3cdbe" + ], + "illumos_amd64": [ + "go1.25.0.illumos-amd64.tar.gz", + "b1e1fdaab1ad25aa1c08d7a36c97d45d74b98b89c3f78c6d2145f77face54a2c" + ], + "linux_386": [ + "go1.25.0.linux-386.tar.gz", + "8c602dd9d99bc9453b3995d20ce4baf382cc50855900a0ece5de9929df4a993a" + ], + "linux_amd64": [ + "go1.25.0.linux-amd64.tar.gz", + "2852af0cb20a13139b3448992e69b868e50ed0f8a1e5940ee1de9e19a123b613" + ], + "linux_arm64": [ + "go1.25.0.linux-arm64.tar.gz", + "05de75d6994a2783699815ee553bd5a9327d8b79991de36e38b66862782f54ae" + ], + "linux_armv6l": [ + "go1.25.0.linux-armv6l.tar.gz", + "a5a8f8198fcf00e1e485b8ecef9ee020778bf32a408a4e8873371bfce458cd09" + ], + "linux_loong64": [ + "go1.25.0.linux-loong64.tar.gz", + "cab86b1cf761b1cb3bac86a8877cfc92e7b036fc0d3084123d77013d61432afc" + ], + "linux_mips": [ + "go1.25.0.linux-mips.tar.gz", + "d66b6fb74c3d91b9829dc95ec10ca1f047ef5e89332152f92e136cf0e2da5be1" + ], + "linux_mips64": [ + "go1.25.0.linux-mips64.tar.gz", + "4082e4381a8661bc2a839ff94ba3daf4f6cde20f8fb771b5b3d4762dc84198a2" + ], + "linux_mips64le": [ + "go1.25.0.linux-mips64le.tar.gz", + "70002c299ec7f7175ac2ef673b1b347eecfa54ae11f34416a6053c17f855afcc" + ], + "linux_mipsle": [ + "go1.25.0.linux-mipsle.tar.gz", + "b00a3a39eff099f6df9f1c7355bf28e4589d0586f42d7d4a394efb763d145a73" + ], + "linux_ppc64": [ + "go1.25.0.linux-ppc64.tar.gz", + "df166f33bd98160662560a72ff0b4ba731f969a80f088922bddcf566a88c1ec1" + ], + "linux_ppc64le": [ + "go1.25.0.linux-ppc64le.tar.gz", + "0f18a89e7576cf2c5fa0b487a1635d9bcbf843df5f110e9982c64df52a983ad0" + ], + "linux_riscv64": [ + "go1.25.0.linux-riscv64.tar.gz", + "c018ff74a2c48d55c8ca9b07c8e24163558ffec8bea08b326d6336905d956b67" + ], + "linux_s390x": [ + "go1.25.0.linux-s390x.tar.gz", + "34e5a2e19f2292fbaf8783e3a241e6e49689276aef6510a8060ea5ef54eee408" + ], + "netbsd_386": [ + "go1.25.0.netbsd-386.tar.gz", + "f8586cdb7aa855657609a5c5f6dbf523efa00c2bbd7c76d3936bec80aa6c0aba" + ], + "netbsd_amd64": [ + "go1.25.0.netbsd-amd64.tar.gz", + "ae8dc1469385b86a157a423bb56304ba45730de8a897615874f57dd096db2c2a" + ], + "netbsd_arm": [ + "go1.25.0.netbsd-arm.tar.gz", + "1ff7e4cc764425fc9dd6825eaee79d02b3c7cafffbb3691687c8d672ade76cb7" + ], + "netbsd_arm64": [ + "go1.25.0.netbsd-arm64.tar.gz", + "e1b310739f26724216aa6d7d7208c4031f9ff54c9b5b9a796ddc8bebcb4a5f16" + ], + "openbsd_386": [ + "go1.25.0.openbsd-386.tar.gz", + "4802a9b20e533da91adb84aab42e94aa56cfe3e5475d0550bed3385b182e69d8" + ], + "openbsd_amd64": [ + "go1.25.0.openbsd-amd64.tar.gz", + "c016cd984bebe317b19a4f297c4f50def120dc9788490540c89f28e42f1dabe1" + ], + "openbsd_arm": [ + "go1.25.0.openbsd-arm.tar.gz", + "a1e31d0bf22172ddde42edf5ec811ef81be43433df0948ece52fecb247ccfd8d" + ], + "openbsd_arm64": [ + "go1.25.0.openbsd-arm64.tar.gz", + "343ea8edd8c218196e15a859c6072d0dd3246fbbb168481ab665eb4c4140458d" + ], + "openbsd_ppc64": [ + "go1.25.0.openbsd-ppc64.tar.gz", + "694c14da1bcaeb5e3332d49bdc2b6d155067648f8fe1540c5de8f3cf8e157154" + ], + "openbsd_riscv64": [ + "go1.25.0.openbsd-riscv64.tar.gz", + "aa510ad25cf54c06cd9c70b6d80ded69cb20188ac6e1735655eef29ff7e7885f" + ], + "plan9_386": [ + "go1.25.0.plan9-386.tar.gz", + "46f8cef02086cf04bf186c5912776b56535178d4cb319cd19c9fdbdd29231986" + ], + "plan9_amd64": [ + "go1.25.0.plan9-amd64.tar.gz", + "29b34391d84095e44608a228f63f2f88113a37b74a79781353ec043dfbcb427b" + ], + "plan9_arm": [ + "go1.25.0.plan9-arm.tar.gz", + "0a047107d13ebe7943aaa6d54b1d7bbd2e45e68ce449b52915a818da715799c2" + ], + "solaris_amd64": [ + "go1.25.0.solaris-amd64.tar.gz", + "9977f9e4351984364a3b2b78f8b88bfd1d339812356d5237678514594b7d3611" + ], + "windows_386": [ + "go1.25.0.windows-386.zip", + "df9f39db82a803af0db639e3613a36681ab7a42866b1384b3f3a1045663961a7" + ], + "windows_amd64": [ + "go1.25.0.windows-amd64.zip", + "89efb4f9b30812eee083cc1770fdd2913c14d301064f6454851428f9707d190b" + ], + "windows_arm64": [ + "go1.25.0.windows-arm64.zip", + "27bab004c72b3d7bd05a69b6ec0fc54a309b4b78cc569dd963d8b3ec28bfdb8c" + ] + } + } } } diff --git a/tests/guardrails/README.md b/tests/guardrails/README.md index f93f0b5..41d149d 100644 --- a/tests/guardrails/README.md +++ b/tests/guardrails/README.md @@ -61,9 +61,10 @@ Problems detected: To fix it: -- Re-add / re-enable the `no_legacy_features` feature (`enabled = True`) in the - toolchain config templates under `templates/linux/` and `templates/qnx/`, and - keep it in each template's `features` list. +- Re-add / re-enable the `no_legacy_features` feature (`enabled = True`) in + `features/custom/linux/make_cc_features.bzl` and + `features/custom/qnx/make_cc_features.bzl`, and keep it in the ordered + `_LINUX_FEATURES` / `_QNX_FEATURES` list. - Provide any behavior you need through an **explicit** feature rather than relying on a Bazel legacy default. See [docs/migration_guide.md](../../docs/migration_guide.md) for the supported diff --git a/tests/guardrails/legacy_feature_guard.bzl b/tests/guardrails/legacy_feature_guard.bzl index 5e7f22b..618c1a7 100644 --- a/tests/guardrails/legacy_feature_guard.bzl +++ b/tests/guardrails/legacy_feature_guard.bzl @@ -98,8 +98,8 @@ def _impl(ctx): " * None of Bazel's implicit legacy C++ features are active.", "", "How to fix:", - " * Re-add / re-enable `{}` in the toolchain config templates".format(_CONTRACT_MARKER), - " under templates/linux/ and templates/qnx/.", + " * Re-add / re-enable `{}` in features/custom/linux/make_cc_features.bzl".format(_CONTRACT_MARKER), + " and features/custom/qnx/make_cc_features.bzl.", " * Provide any needed behavior through an explicit feature instead of", " relying on Bazel legacy defaults.", " * See tests/guardrails/README.md for details.",