Skip to content

Control of flag propagation through an exec cfg transition #28320

Closed

Description

@JonathanPerry651

Description of the feature request:

I am trying out the scope api in custom starlark flags with transitions. I would like to scope my key as "project", but I would also like to retain the flag setting over the exec transition - the flag controls behaviour both in the runtime of my target and also in the behaviour of some of my custom rules.

I discovered --experimental_propagate_custom_flag, but @fmeum pointed out that scopes are supposed to replace it.

(EDIT (twice) - it turns out that if I do all of: scope = "project", "experimental_propagate_custom_flags=//:my_flag" and "incompatible_exclude_starlark_flags_from_exec_config=true", then I get the behaviour I want, at least for my flag. That seems like a rather drastic change though, as who knows what other flags I'm suddenly resetting...

And in fact, with bazel 9.0.0rc6 if you have this combination of flags, and also have a rules_js target which goes through an exec transition, then you get a build failure in the postinstall hook of react with a file not found. If useful I can try to cook up a repro, just let me know.)

As it stands I believe I have to just be careful and not use "exec" in my code. Is that right, or have I missed something?

Thanks!

Which category does this issue belong to?

Configurability

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

No response

Which operating system are you running Bazel on?

ubuntu

What is the output of bazel info release?

9.0.0rc6

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

No response

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


Have you found anything relevant by searching the web?

No response

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

No response

Activity

  1. fmeum commented on Jan 16, 2026

    @fmeum
    Collaborator

    @gregestren @aranguyen I think we talked about this before. Should we extend the API so that resetting on project boundaries and on exec transitions can be configured independently?

  2. added
    P2We'll consider working on this in future. (Assignee optional)
    and removed
    untriagedHas not yet been seen by appropriate subteam
    on Jan 20, 2026
  3. gregestren commented on Jan 20, 2026

    @gregestren
    Contributor

    would like to scope my key as "project", but I would also like to retain the flag setting over the exec transition - the flag controls behaviour both in the runtime of my target and also in the behaviour of some of my custom rules.

    It's true the current scope API doesn't let you combine.

    Are you trying to model //myproject:foo --exec_transition--> //myproject:tool --//other_project:dep? So the flag propagates until //other_project:dep?

    But with //myproject:foo --> //other_project:dep --exec_transition--> //myproject:tool the flag resets before the exec transition?

    In other words, are you comfortable with the invariant that a project-scoped flag propagates through an unbroken chain of project dependencies, but as soon as you leave the project it resets? And if it leaves the project before the exec transition then it won't get its value back in the exec config?

    and "incompatible_exclude_starlark_flags_from_exec_config=true

    FYI incompatible_exclude_starlark_flags_from_exec_config=true is default for bazel@head. The only reason we didn't flip it for 9.0 was to give people more time to respond if their projects need updating. I wonder if you're finding examples of that.

    As it stands I believe I have to just be careful and not use "exec" in my code.

    What do you mean here?

  4. JonathanPerry651 commented on Jan 21, 2026

    @JonathanPerry651
    ContributorAuthor

    In other words, are you comfortable with the invariant that a project-scoped flag propagates through an unbroken chain of project dependencies, but as soon as you leave the project it resets? And if it leaves the project before the exec transition then it won't get its value back in the exec config?

    Yes - this is exactly what I want. That's probably because I'm a 'leaf' repo, only consuming other repos (and thus never have the my project -> other project -> my project situation).

    and "incompatible_exclude_starlark_flags_from_exec_config=true

    FYI incompatible_exclude_starlark_flags_from_exec_config=true is default for bazel@head. The only reason we didn't flip it for 9.0 was to give people more time to respond if their projects need updating. I wonder if you're finding examples of that.

    Interesting thank you

    As it stands I believe I have to just be careful and not use "exec" in my code.

    What do you mean here?

    I think this story changes a bit with the point you made above that we think the rules_js behaviour will require remediation. So let's ignore that comment. But here's the overall setup of my world, I'd be grateful for a steer on how you would like me to model it in this API. I'm obviously super open to be told I'm misunderstanding the world:

    So: I have code which generates yamls for my infra. It's essentially a compile step, .java -> .yaml. That code gets wired up through an executable = True, cfg = "exec" attr on a custom rule. The behaviour of that code is controlled by my label_flags above.
    That code consumes the results of actions which build+push container images to my artifact repo. The behaviour of those containers also are controlled by my label_flags above. Those container images also contain rules_js code.

    'Above' the generation code, the value of the label_flag is transitioned to point at configuration for the target environment.

    So right now it goes like this:

    Top level 'all environments' target (label_flag = 'unconfigured', 'target' config) -> Per target (label_flag = 'my env', 'target' config) -> Yaml generation binary (label_flag = 'my env', 'exec' config) -> Container image construction (label_flag = 'my env', 'exec' config) -> Java/Go/rules_js Application Code (label_flag = 'my env', 'exec' config)

    There are several branches off that chain which go into external repos (rules_go, rules_js for example). Since I'm a leaf repo, those branches never return and cannot possibly be affected by my label_flag.

  5. JonathanPerry651 commented on Feb 21, 2026

    @JonathanPerry651
    ContributorAuthor

    @gregestren / @fmeum - did you have any further thoughts on this? I note it went to P2 which seems encouraging!

    I'm hitting walls with my use of transitions, and am about to be forced into much sadder places, so I'd be very excited to hear any news :). For your info - the place I'm being forced to is I will have to move all my config resolution to the edges of my build graph, which will be really nasty - I'll have to late bind several java_binary targets and wrap them up in resolved config somehow, and repush container_images, rewriting hashes in my k8s config, and so forth.

    Thank you

  6. fmeum commented on Feb 21, 2026

    @fmeum
    Collaborator

    @gregestren With the current API, what do you think of introducing a project_exec scope (name TBD)? I would still prefer us collecting the full "algebraic data type" that a scope could really be and then determining the best way to specify the scope syntax-wise. This capability is still pretty new and there's value in getting the API in good shape.

  7. JonathanPerry651 commented on Feb 23, 2026

    @JonathanPerry651
    ContributorAuthor

    I guess a hack around might be to use a custom_exec_scope_target, and then read both, preferring whichever is non-default

    Edit - well that was a total misread of the branch of the codebase, so… off that

  8. 6 remaining items

  9. gregestren commented on Mar 20, 2026

    @gregestren
    Contributor

    Haven't forgotten - just lots of end of quarter attention demands. I'll schedule specific time next week to respond.

  10. JonathanPerry651 commented on Mar 23, 2026

    @JonathanPerry651
    ContributorAuthor

    Understood and much appreciated

  11. gregestren commented on Mar 25, 2026

    @gregestren
    Contributor

    Hi @JonathanPerry651 Re:

    Top level 'all environments' target (label_flag = 'unconfigured', 'target' config) -> Per target (label_flag = 'my env', 'target' config) -> Yaml generation binary (label_flag = 'my env', 'exec' config) -> Container image construction (label_flag = 'my env', 'exec' config) -> Java/Go/rules_js Application Code (label_flag = 'my env', 'exec' config)

    Can you clarify exactly what purpose cfg = "exec" serves? I just want to double-check the core need.

    What I'm getting at is that while compiler tools need to be built in "exec" configurations, they often run in target configurations. So a common pattern is a target-configured library will build a tool dependency in the "exec" config, then construct a target-configured action that runs the tool with whatever parameters make sense from the target configuration.

    So your java -> yaml binary: does building that binary require the my_env settings? Or can it be built independently of those settings, then integrated into an action that the target-configured "Per target" node creates, and the action can parameterize itself from my_env from there?

    I realize the container image construction is a deeper dep. Not sure if that changes this analyses?

  12. JonathanPerry651 commented on Mar 25, 2026

    @JonathanPerry651
    ContributorAuthor

    @gregestren - thanks for looking. I think it would probably be possible to restructure the code this way for a subset of use cases, but two points.

    One - to solve for all of them, I would basically end up back at the ‘late binding config’ state of the world, which becomes super intrusive and a nasty client api.

    Two - I can’t be sure that I have actually covered everything: all it takes is a single stray “exec”, and suddenly I have the wrong configuration in production…

    So I think if I could not rely on propagation through exec, I would have to switch to the manual late binding approach.

  13. JonathanPerry651 commented on Apr 1, 2026

    @JonathanPerry651
    ContributorAuthor

    @gregestren did that make sense? Is this an approach you see as interesting/useful?

    Thanks!

  14. gregestren commented on Apr 3, 2026

    @gregestren
    Contributor

    Friendly ping, [@gregestren](https://github.com/gregestren) - would you be ok with merging this as a stopgap, with the understanding that the api will change? If so I’m happy to submit the pr and make whatever changes.

    How about updating the existing "project" value to propagate through exec? I'd support that. There's no strong reason to break the existing setting at the exec boundary.

  15. JonathanPerry651 commented on Apr 4, 2026

    @JonathanPerry651
    ContributorAuthor

    Love it. I’ll submit a PR asap. Thank you!

  16. JonathanPerry651 commented on Apr 5, 2026

    @JonathanPerry651
    ContributorAuthor

    @gregestren submitted. I think I cleaned it all up to be worth your review, but all feedback welcome. thanks again for your time!

  17. keith commented on Jun 16, 2026

    @keith
    Member

    Is there a doc somewhere with the planned end state for all of this? I haven't seen scope = "exec:--... mentioned anywhere

  18. gregestren commented on Jun 17, 2026

    @gregestren
    Contributor

    Did scope = "exec:--//:host_modular_config", work for you?

    We wrote that a hack API and are hoping something more principled can evolve at some point down the line. That's the main reason for not publicizing it.

    It also has some unintuitive technical limitations. I can't remember if it requires equivalent --foo --host_foo flag aliases to properly work.

  19. keith commented on Jun 17, 2026

    @keith
    Member

    Still testing to make sure but I believe it does. The issue otherwise for that repo is they're using that as a compilation_mode type setting so if it is dropped through a second level exec transition you end up building artifacts in multiple configurations when you shouldn't be

  20. iancha1992 commented on Jun 26, 2026

    @iancha1992
    Member

    This feature has been included in Bazel 9.2.0 RC1. Please test out the release candidate and report any issues as soon as possible.
    If you're using Bazelisk, you can point to the latest RC by setting USE_BAZEL_VERSION=9.2.0rc1. Thanks!

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

    P2We'll consider working on this in future. (Assignee optional)team-Configurabilityplatforms, toolchains, cquery, select(), config transitionstype: feature request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions