Skip to content
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

Cannot use crate.select inside certain crate.annotations (e.g. build_script_data) #2940

Open
tshaynik opened this issue Oct 15, 2024 · 0 comments

Comments

@tshaynik
Copy link

tshaynik commented Oct 15, 2024

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?

Relevant post in Bazel Slack

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

No branches or pull requests

1 participant