Skip to content

Commit f855550

Browse files
committed
Adding select statements for build script environment and data attributes in bzlmod.
1 parent 62d7317 commit f855550

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

crate_universe/extensions.bzl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,22 @@ def _crate_impl(module_ctx):
868868
repo_specific_annotations = {}
869869
for annotation_tag in mod.tags.annotation:
870870
annotation_dict = structs.to_dict(annotation_tag)
871+
if annotation_dict["build_script_data_select"]:
872+
annotation_dict["build_script_data"] = struct(
873+
common = annotation_dict["build_script_data"],
874+
selects = annotation_dict["build_script_data_select"],
875+
)
876+
annotation_dict.pop("build_script_data_select")
877+
if annotation_dict["build_script_env_select"]:
878+
annotation_dict["build_script_env"] = struct(
879+
common = annotation_dict["build_script_env"],
880+
selects = {
881+
k: json.decode(v)
882+
for k, v in annotation_dict["build_script_env_select"].items()
883+
},
884+
)
885+
annotation_dict.pop("build_script_env_select")
886+
871887
repositories = annotation_dict.pop("repositories")
872888
crate = annotation_dict.pop("crate")
873889

@@ -1088,12 +1104,18 @@ _annotation = tag_class(
10881104
"build_script_data_glob": attr.string_list(
10891105
doc = "A list of glob patterns to add to a crate's `cargo_build_script::data` attribute",
10901106
),
1107+
"build_script_data_select": attr.string_list_dict(
1108+
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.",
1109+
),
10911110
"build_script_deps": _relative_label_list(
10921111
doc = "A list of labels to add to a crate's `cargo_build_script::deps` attribute.",
10931112
),
10941113
"build_script_env": attr.string_dict(
10951114
doc = "Additional environment variables to set on a crate's `cargo_build_script::env` attribute.",
10961115
),
1116+
"build_script_env_select": attr.string_dict(
1117+
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\"}`.",
1118+
),
10971119
"build_script_link_deps": _relative_label_list(
10981120
doc = "A list of labels to add to a crate's `cargo_build_script::link_deps` attribute.",
10991121
),

0 commit comments

Comments
 (0)