Skip to content

Ruled Based Toolchains (PoC) #156

Open
Open

Description

@nradakovic

Epic: Rule-based C++ toolchains (PoC)

Background

The toolchains in this repository are generated per platform from templates/BUILD.template and templates/cc_toolchain_config.bzl.template. They are a hybrid of two approaches:

  • Features under features/ already use the rule-based API (cc_args, cc_feature).
  • The toolchain itself is still declared the legacy way:
    • a custom cc_toolchain_config rule hand-builds action_configs and tool_paths;
    • it is wired into the native cc_toolchain through toolchain_config;
    • gcov needs a wrapper script as a workaround for rules_cc#351.

The rule-based toolchain API in rules_cc replaces this with declarative targets (cc_tool, cc_tool_map, cc_args, cc_feature, cc_toolchain). Its API is documented here: https://github.com/bazelbuild/rules_cc/blob/main/docs/toolchain_api.md

Goal

Build a proof of concept that declares at least one toolchain per OS family fully with the rule-based API. The PoC should show whether we can drop the legacy cc_toolchain_config template. It should also record the gaps, so we can decide whether and how to migrate everything.

Scope

  • Linux GCC, QNX 8.0 SDP and EBcLfSA are the target toolchain families. The PoC may start with one family (for example Linux x86_64 GCC), but the findings must cover all three.
  • Use rules_cc 0.2.25 (the version we already depend on). Record any API features that need a newer version.
  • Keep the existing generated-repository model (gcc module extension, gcc_toolchain repository rule). Only the generated toolchain content changes.
  • The PoC runs alongside the existing toolchains. It is not a replacement, and the legacy path stays the default until a decision is made.

Out of scope

  • Removing the legacy toolchain path.
  • Changing supported SDP, GCC or SDK versions.
  • Changes to the public module extension API, unless the PoC shows they are unavoidable.

Work items

  1. Analysis
    • Map every legacy action_config, tool_path and feature to its rule-based equivalent.
    • List what the API cannot express yet: gcov handling, per-toolchain env with resolved paths (QNX_HOST/QNX_TARGET), cxx_builtin_include_directories, sysroot, strip and ar flags.
  2. Tool declarations
    • Declare cc_tool and cc_tool_map for compile, link, archive, strip, objcopy and coverage.
    • Replace the gcov_wrapper workaround if the API allows it.
    • Fix the package BUILD files so each CPU-specific tool target maps to the matching binary (for example packages/qnx/sdp/8.0/sdp.BUILD).
  3. Args and features
    • Check that the existing features/ targets work unchanged with the rule-based cc_toolchain.
    • Port anything that depends on legacy feature or flag_set constructs.
  4. Toolchain declaration
    • Add a template variant that emits the rule-based cc_toolchain, with known_features, enabled_features and the tool map.
    • Pass runfiles and all_files through the API's data attributes in place of the current filegroups.
  5. Validation
    • Build and run the existing tests under tests/ and the examples with the PoC toolchain.
    • Compare compile and link command lines (--subcommands) between the legacy and rule-based toolchains, and explain any differences.
    • Check sandboxed and remote execution (missing inputs, /proc/self/cwd paths).
  6. Findings and decision
    • Write up the gaps, workarounds and open issues, with upstream rules_cc issues for any blockers.
    • Recommend one of: migrate fully, migrate partially, or wait for upstream.

Acceptance criteria

  • At least one toolchain builds and passes the existing tests using only the rule-based API, with no cc_toolchain_config rule.
  • The legacy and PoC command lines are compared, and every difference is justified.
  • A findings document lists the blockers per toolchain family and the effort to migrate the rest.
  • The CI runs the PoC toolchain without affecting the default toolchains.

Risks and open questions

  • Rule-based toolchains are still evolving upstream, so API changes between rules_cc releases may break the PoC.
  • Which rules_cc minimum version will we require?
  • QNX needs a QNX_HOST/QNX_TARGET environment with resolved paths (rules/gcc.bzl already has a TODO for this). Label resolution in cc_args env is not supported yet.
  • gcov support: can rules_cc#351 be avoided in the new model?
  • Can the same BUILD content serve both the legacy and the new templates during the transition?

Child issues (to create)

  • Analyse the legacy-to-rule-based mapping and list the gaps
  • PoC: Linux x86_64 GCC with the rule-based toolchain
  • PoC: QNX 8.0 (SDP env, sysroot, include directories)
  • PoC: EBcLfSA
  • Remove or replace the gcov wrapper
  • CI job for PoC toolchains
  • Findings and migration recommendation

Activity

  1. added theissue type on Sep 29, 2026
  2. added
    refinement needed
    on Sep 29, 2026
  3. changed the title [-]PoC - Ruled Based Toolchains[/-] [+]Ruled Based Toolchains (PoC)[/+] on Sep 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    refinement needed

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions