-
Notifications
You must be signed in to change notification settings - Fork 440
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
crate_universe
does not consolidate configurations that match the same set of platforms.
#1417
Comments
What rev of This seems to be caused by |
0.6.0. How recently did you make the change you mentioned? |
Bazelize canister_sandbox ~~This is blocked on bazelbuild/rules_rust#1417 temporary workaround, see diff See merge request dfinity-lab/public/ic!5726
Sorry for the delay here. This issue comes from the unique configurations not being consolidated when there aren't unique platforms (represented by Bazel) to match them (code here). This creates conflicting select cases and you get the error you see. I think the fix is probably just to write a wrapper for diff --git a/BUILD.rustix-0.33.7.bazel b/BUILD.rustix-0.33.7.bazel
index 9c8ddade..fd6c0260 100644
--- a/BUILD.rustix-0.33.7.bazel
+++ b/BUILD.rustix-0.33.7.bazel
@@ -21,7 +21,7 @@ load(
)
# buildifier: disable=bzl-visibility
-load("@rules_rust//crate_universe/private:selects.bzl", "select_with_or")
+load("@rules_rust//crate_universe/private:selects.bzl", "consolidate", "select_with_or")
package(default_visibility = ["//visibility:public"])
@@ -33,7 +33,7 @@ package(default_visibility = ["//visibility:public"])
rust_library(
name = "rustix",
deps = [
- ] + select_with_or({
+ ] + select_with_or(consolidate({
# cfg(all(not(rustix_use_libc), not(miri), target_os = "linux", any(target_arch = "x86", all(target_arch = "x86_64", not(target_pointer_width = "32")), target_arch = "arm", target_arch = "aarch64", target_arch = "powerpc64", target_arch = "riscv64", target_arch = "mips", target_arch = "mips64")))
(
"@rules_rust//rust/platform:aarch64-unknown-linux-gnu",
@@ -112,7 +112,7 @@ rust_library(
"@crate_index__io-lifetimes-0.5.3//:io_lifetimes",
"@crate_index__rustix-0.33.7//:build_script_build",
],
- }),
+ })),
proc_macro_deps = [
] + select_with_or({
"//conditions:default": [ Does that sound reasonable (wondering @illicitonion's thoughts too)? And is that something you'd (@pikajude) have bandwidth to work on? I'd be more than happy to review and collaborate on in a PR 😄 |
crates_repository
generates invalid BUILD.bazel for a crate with complicated dependenciescrate_universe
does not consolidate configurations that match the same set of platforms.
I'm not sure I don't have strong thoughts on whether it makes sense to do this consolidation on the rust side or the starlark side, other than that in general rust is more expressive which can be useful :) |
I just patched this in cargo-raze in Rust. I'm not sure my implementation is as brief as it could be (although, in raze, it's generic over features too). But, fwiw, I ended up having to do a list of pairs with some set operations at the end. |
I just encountered this issue too, I can make an attempt at a PR @UebelAndre |
I would gladly review it! Thanks @nathanosdev! |
@nathanosdev - if you haven't had a chance to work on this, I can attempt a PR for this in the next few days. |
@wmatthews-google That would be awesome. If you change your mind or something else gets in the way, let me know and I can pick it back up again. |
Ok... I've got a draft PR out that works for everything I've thrown at it thus far (other than an issue with platforms and |
I think this is now fixed? |
Closing this out until someone says otherwise 😄 |
Context: see #1734. This PR converts all of `crate_build_file.j2`, `partials/crate/*.j2` and `partials/starlark/*.j2` to serde_starlark. ### Remarks - I kept the output of `bazel run //crate_universe/3rdparty:crates_vendor` out of this PR to keep GitHub's code review interface usable. You can find the output generated code in 44c264a. - I tried to keep the conversion 1-to-1 to the largest extent possible. As an example, build_script.j2 duplicated most of the content of common_attrs.j2 even though it probably could have used that template via include, and I have mirrored the same here by not using `#[serde(flatten)] common: CommonAttrs` inside of `CargoBuildScript`. There is probably plenty of opportunity for cleaning up things in followup PRs. - I came across several bugs in the existing code. Again, I mostly stayed away from these to keep the PR bounded in scope. For example the fact that `rustc_flags` is stored as a BTreeSet\<String\> is not correct; compiler flags are ordered and sorting them is not correct. For example `-C debuginfo=2`... https://github.com/bazelbuild/rules_rust/blob/532e60ff0ee3ac318333b3ae05392c220b17ce28/crate_universe/src/context/crate_context.rs#L178 - One bug that I fixed because in the new implementation it was easier to fix than to not fix, is that all existing uses of selectable_list.j2 and selectable_dict.j2 were broken because they all had the same failure mode as #1417. The generated code using `selects.with_or` could end up generating a map with duplicate keys if multiple distinct Cargo cfg expressions mapped to the same subset of supported platform triples. My implementation follows the same approach as #1647, but that PR only applied it to `deps` and `aliases`, not e.g. `rustc_env` and everything else. - Anecdotally the new implementation has strong "if it compiles, it works" property. I mostly typed out the implementation of this PR top to bottom without running `crates_vendor`, and as soon as the whole thing was written and the compiler was okay with it, it was generating the output I wanted. I have not done much work in the templates in the past but I do not imagine they have this property. ### Remaining work - `select_with_or` in private/selects.bzl is no longer used by the code generator's output. I had to keep it in this PR because all the generated BUILD files still include calls to it. It can be deleted after all those are regenerated. - One of the tera templates still uses the old serialization of `SelectList` so the starlark serialization for it isn't a normal `Serialize` impl but instead an associated function. This causes there to be a bunch of `serialize_with = "SelectList::serialize_starlark"` attributes needed. This can be cleaned up after the last tera template is converted. - ~~A lot of the contents of `crate::context` can be cleaned up after they're no longer used by tera. Tera needs those data structures to be serializable, whereas with serde_starlark we're not serializing anything from `crate::context`, only from `crate::utils::starlark`. For now I've just added a bunch of `serde(skip)` attributes in `crate::context` on all the parts tera is no longer using.~~ *Edit: apparently we still need to serialize all the fields in `Context` so that they end up in cargo-bazel-lock.json.* - There are 2 remaining tera templates after this PR, module_bzl.j2 and vendor_module.j2.
Here's the Cargo.toml for rustix-0.33.7: https://docs.rs/crate/rustix/0.33.7/source/Cargo.toml
The resulting generated file: https://gist.github.com/pikajude/4c6eec44aba219e58f5803a7efecf10b
The condition
# cfg(all(windows, not(target_vendor = "uwp")))
duplicates the condition# cfg(windows)
. See lines 53 and 97. This results in the error:This is not a duplicate of #1236 as we aren't using
supported_platform_triples
in our workspace file.The text was updated successfully, but these errors were encountered: