Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FR] Configuring C++ flag groups based on the target platform #16845

Open
philsc opened this issue Nov 25, 2022 · 2 comments
Open

[FR] Configuring C++ flag groups based on the target platform #16845

philsc opened this issue Nov 25, 2022 · 2 comments
Labels
P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) stale Issues or PRs that are stale (no activity for 30 days) team-Rules-CPP Issues for C++ rules type: feature request

Comments

@philsc
Copy link
Contributor

philsc commented Nov 25, 2022

Description of the feature request:

I have a problem that could be solved by expanding the feature and/or flag_group functionality in C++ toolchain configuration.

In particular, I wonder if we could enhance feature like so:

feature(
    name = "feature_for_constraint",
    flag_sets = [...],
    # This features is enabled when the target platform satisfies the
    # listed constraints.
    enabled_if = [
        constraint_set([
            "//:constraint1",
            "//:constraint2",
        ]),
    ],
    implies = [...],
)

What underlying problem are you trying to solve with this feature?

We have 50 platforms we're targeting in our build. The majority of which are embedded ARM platforms. Most of those embedded ARM platforms use a single toolchain, but require slightly different compiler flags.

The way we solve this today is by defining those different flags in a per-platform feature. Those features are then turned on via a --config setting. Our .bazelrc file looks roughly equivalent to:

build:platform1 --platforms=//:platform1 --features=platform1
build:platform2 --platforms=//:platform2 --features=platform2
build:platform3 --platforms=//:platform3 --features=platform3
...
build:platform30 --platforms=//:platform30 --features=platform30

That works well enough, but we run into some challenges with transitions. Because it's hard to predict which platform you're transitioning from, we define all our transitions roughly like so:

cc_binary(
    name = "foo",
    ...
)
transition_file(
    name = "foo_platform8",
    src = ":foo",
    removed_features = ["platform%d" % i for i in range(1, 31) if i != 8],
    added_features = ["platform8"],
    target_platform = "//:platform8",
)

We basically have to remove any possible features that may exist to avoid the risk of them interfering. This works for us today, but frequently results in hard-to-debug issues when folks add new features and forget to remove it from the big list in every transition.

One solution that I'm experimenting with right now is to define a dedicated toolchain for each platform. That means that we'd have 50 individual toolchains. I think this will work, but feels more like a work around.

I am looking for a better way for toolchains to adjust features based on constraints (or maybe platforms?). The toolchains already make decisions based on other aspects of a target. I think it could do the same for

Which operating system are you running Bazel on?

amd64 Linux

What is the output of bazel info release?

N/A

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

N/A

What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

N/A

Have you found anything relevant by searching the web?

I have not found anything related to this.

Any other information, logs, or outputs that you want to share?

This idea came up when I was discussing my problem with @katre at Bazelcon last week.

The original idea involved adding functionality to flag_group. Possibly in the form of an expand_if_target_platform_has_constraints parameter or similar. This approach should also work, but is a little less expressive for triggering other features via implies and requires.

@philsc philsc changed the title Configuring C++ flag groups based on the target platform [FR] Configuring C++ flag groups based on the target platform Nov 25, 2022
@oquenchil
Copy link
Contributor

I don't think we will plan any work on expanding the syntax for C++ features in the near future. First we would probably rewrite the whole mechanism to use the generic Args interface (while making Args more powerful).

@oquenchil oquenchil added P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) and removed untriaged labels Jan 23, 2023
Copy link

Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 90 days unless any other activity occurs. If you think this issue is still relevant and should stay open, please post any comment here and the issue will no longer be marked as stale.

@github-actions github-actions bot added the stale Issues or PRs that are stale (no activity for 30 days) label Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) stale Issues or PRs that are stale (no activity for 30 days) team-Rules-CPP Issues for C++ rules type: feature request
Projects
None yet
Development

No branches or pull requests

3 participants