rules_rust
rules_rust copied to clipboard
Cannot use `crate.select` inside certain crate.annotations (e.g. build_script_data)
It seems like crate.select can't be used in a variety of crate.annotations, including build_script_data.
There is this example in the rules_rust repo of using the results of a crate.select in a list for rustc_flags, it is out of date. To reproduce:
crates_repository(
name = "rust_crates",
annotations = {
"zstd-sys": [
crate.annotation(
build_script_data = crate.select(
selects = {
"@rules_rust//rust/platform:myplatform": [
"//:mytarget",
],
},
common = [],
),
build_script_env = crate.select(
selects = {
"@rules_rust//rust/platform:myplatform": {
"ZSTD_SYS_USE_PKG_CONFIG": "1",
},
},
common = {},
),
),
],
})
The build_script_env annotation works, but the addition of the crate.select in build_script_data causes the following error.
File "/home/ubuntu/.bazel-output-cache/0f174b5402e5e096a67deb6762266f43/external/rules_rust/crate_universe/private/crate.bzl", line 188, column 48, in _annotation
build_script_data = _stringify_list(build_script_data),
File "/home/ubuntu/.bazel-output-cache/0f174b5402e5e096a67deb6762266f43/external/rules_rust/crate_universe/private/crate.bzl", line 230, column 29, in _stringify_list
return [str(x) for x in values]
Error: type 'struct' is not iterable
The issue seems to be here in the rules_rust codebase. The call to _stringify_list in crate.bzl breaks on a crate.build_script_data, since the result of crate.select is a struct.
Is it possible to remove or rework the invocation of _stringify_list there, so that the select struct can be passed along?