Skip to content

Adding select statements for build script environment and data attributes in bzlmod #3511

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

finn-ball
Copy link
Contributor

An implementation to bring some select statement functionality which are available in repository rules but not bzlmod.

Since a dict of dicts is not supported, I've opted for a dict of json string which gets decoded on the other end.

@finn-ball finn-ball force-pushed the finn/env-select branch 4 times, most recently from 15b7d65 to 72fb619 Compare July 18, 2025 15:59
Copy link
Collaborator

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable to me - ideally we'd have more expressive annotations, or a helper function to generate this stuff, but this opens up capabilities we currently lack :) Thanks!

@finn-ball
Copy link
Contributor Author

or a helper function to generate this stuff

What would a helper function look like in this scenario? I'm unsure how to add functions into MODULE files for this and we're quite limited in what we can pass into a tag class.

I had thought about adding a new tag class such as:

crate.annotation_env_select(
    crate = "foo",
    platform_triplet = "linux-x86_64-unknown",
    variables = {"FOO": "bar"},
)
crate.annotation_env_select(
    crate = "foo",
    platform_triplet = "linux-arm64-unknown",
    variables = {"FOO": "baz"},
)

But felt that was a little messy too as it isn't part of the original annotation.

Have you any suggestions?

@finn-ball finn-ball force-pushed the finn/env-select branch 2 times, most recently from 416dc52 to 9b7635b Compare July 22, 2025 07:56
@illicitonion
Copy link
Collaborator

or a helper function to generate this stuff

What would a helper function look like in this scenario? I'm unsure how to add functions into MODULE files for this and we're quite limited in what we can pass into a tag class.

These aren't currently supported by Bazel, but there's perpetually discussion about them :) sorry, I was saying "ideally" as in "if Bazel were more capable" rather than "if Finn put in more work" :D

I had thought about adding a new tag class such as:

crate.annotation_env_select(
    crate = "foo",
    platform_triplet = "linux-x86_64-unknown",
    variables = {"FOO": "bar"},
)
crate.annotation_env_select(
    crate = "foo",
    platform_triplet = "linux-arm64-unknown",
    variables = {"FOO": "baz"},
)

But felt that was a little messy too as it isn't part of the original annotation.

This kind of new tag class is probably the nicest way to express this at the moment tbh, I wouldn't complain about this API at all. But also happy to merge this as-is if you don't fancy putting it together :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants