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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions crate_universe/extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,22 @@ def _crate_impl(module_ctx):
repo_specific_annotations = {}
for annotation_tag in mod.tags.annotation:
annotation_dict = structs.to_dict(annotation_tag)
if annotation_dict["build_script_data_select"]:
annotation_dict["build_script_data"] = struct(
common = annotation_dict["build_script_data"],
selects = annotation_dict["build_script_data_select"],
)
annotation_dict.pop("build_script_data_select")
if annotation_dict["build_script_env_select"]:
annotation_dict["build_script_env"] = struct(
common = annotation_dict["build_script_env"],
selects = {
k: json.decode(v)
for k, v in annotation_dict["build_script_env_select"].items()
},
)
annotation_dict.pop("build_script_env_select")

repositories = annotation_dict.pop("repositories")
crate = annotation_dict.pop("crate")

Expand Down Expand Up @@ -1088,12 +1104,18 @@ _annotation = tag_class(
"build_script_data_glob": attr.string_list(
doc = "A list of glob patterns to add to a crate's `cargo_build_script::data` attribute",
),
"build_script_data_select": attr.string_list_dict(
doc = "A list of labels to add to a crate's `cargo_build_script::data` attribute. Keys should be the platform triplet. Value should be a list of labels.",
),
"build_script_deps": _relative_label_list(
doc = "A list of labels to add to a crate's `cargo_build_script::deps` attribute.",
),
"build_script_env": attr.string_dict(
doc = "Additional environment variables to set on a crate's `cargo_build_script::env` attribute.",
),
"build_script_env_select": attr.string_dict(
doc = "Additional environment variables to set on a crate's `cargo_build_script::env` attribute. Key should be the platform triplet. Value should be a JSON encoded dictionary mapping variable names to values, for example `{\"FOO\": \"bar\"}`.",
),
"build_script_link_deps": _relative_label_list(
doc = "A list of labels to add to a crate's `cargo_build_script::link_deps` attribute.",
),
Expand Down