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

Fix crate deps with condition #1901

Closed
wants to merge 1 commit into from
Closed

Conversation

ibigbug
Copy link
Contributor

@ibigbug ibigbug commented Mar 24, 2023

Fixed #1880

Copy link
Collaborator

@UebelAndre UebelAndre left a comment

Choose a reason for hiding this comment

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

Thanks! Is this something you'd be able to add an integration test for at https://github.com/bazelbuild/rules_rust/tree/0.19.1/examples/crate_universe? I thought the alias example there would have caught an issue like this but it's clearly lacking. Could you update this so we don't have aliases break again in the future?

@ibigbug ibigbug marked this pull request as draft March 24, 2023 17:22
@ibigbug
Copy link
Contributor Author

ibigbug commented Mar 24, 2023

sure I'll add it. but sorry for the confusion I think we still need some polish to this PR #1880 (comment)

@ibigbug
Copy link
Contributor Author

ibigbug commented Mar 31, 2023

@UebelAndre I think I made some progress, and got a new error

DEBUG: /private/var/tmp/_bazel_yuweiba/f3b87d172301024018ed3e9f856c70fc/external/crate_index/defs.bzl:276:10: {"": {}, "cfg(target_os = \"macos\")": {}}
DEBUG: /private/var/tmp/_bazel_yuweiba/f3b87d172301024018ed3e9f856c70fc/external/crate_index/defs.bzl:276:10: {"": {}}
ERROR: /Users/yuweiba/workspace/projects/clash-rs/clash/BUILD.bazel:4:13: //clash:aarch64-apple-darwin is not a valid select() condition for //clash:lib.
To inspect the select(), run: bazel query --output=build //clash:lib.
For more help, see https://docs.bazel.build/be/functions.html#select.

any suggestions where to go next step?

@ibigbug
Copy link
Contributor Author

ibigbug commented Jun 5, 2023

@UebelAndre sorry i wasn't able to make any progress. do you have any suggestions?

for condition, deps in dependencies.items():
crate_deps += selects.with_or({_CONDITIONS[condition]: deps.values()})
Copy link
Contributor

Choose a reason for hiding this comment

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

For deps since it's a list, it could be done a bit simpler with selects.with_or without for-loop

-        crate_deps += selects.with_or({_CONDITIONS[condition]: deps.values()})
+        crate_deps += selects.with_or({tuple(_CONDITIONS[condition]): deps.values()})

@k1nkreet
Copy link
Contributor

k1nkreet commented Jun 15, 2023

@UebelAndre I think I made some progress, and got a new error

DEBUG: /private/var/tmp/_bazel_yuweiba/f3b87d172301024018ed3e9f856c70fc/external/crate_index/defs.bzl:276:10: {"": {}, "cfg(target_os = \"macos\")": {}}
DEBUG: /private/var/tmp/_bazel_yuweiba/f3b87d172301024018ed3e9f856c70fc/external/crate_index/defs.bzl:276:10: {"": {}}
ERROR: /Users/yuweiba/workspace/projects/clash-rs/clash/BUILD.bazel:4:13: //clash:aarch64-apple-darwin is not a valid select() condition for //clash:lib.
To inspect the select(), run: bazel query --output=build //clash:lib.
For more help, see https://docs.bazel.build/be/functions.html#select.

I've got to the same issue with my small research on this topic. It looks like the problem is module_bzl.j2 defining _CONDITIONS value uses triples from context.conditions holding the values which are not transformed with platforms_template. I'm not really familiar with the tool processing those templates to understand whether it's possible to apply platforms_template to triples inside the template specification. The other option could be to provide additional value in context or change the value of context.conditions according to platforms_template. I wonder if @UebelAndre has any thoughts on that

@UebelAndre
Copy link
Collaborator

Hey! So sorry, this one fell off my radar, thanks for the ping.

If you can add a small integration-test/example to this PR I can find some time to context shift to this issue. I think it'd be fine to process more in Rust vs Starlark. The thing I care most about is that issues are easy to identify and to be honest the current implementation fails at that. Simplifying this without changing the interface sounds amazing to me 😄

@k1nkreet
Copy link
Contributor

k1nkreet commented Jun 16, 2023

Since I've spent some time tinkering on cargo-bazel-bin tool to solve the last issue and I've made some progress on it, I took the liberty of opening the new PR where I've added the integration test/example, took the changes from this PR and added fix for this problem

@ibigbug ibigbug closed this Jun 27, 2023
@ibigbug ibigbug deleted the crate-deps branch August 8, 2023 12:10
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.

Cargo.toml with conditions are failing to build
3 participants