-
Notifications
You must be signed in to change notification settings - Fork 491
Fix "two different versions of crate" compiliation error #294
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
Conversation
Update: basing off of 7cde1e4, I can get my example to compile correctly by removing: In
and
No clue what any of that means, but I'll keep digging |
@@ -354,7 +351,6 @@ rust_library = rule( | |||
_rust_library_attrs.items()), | |||
fragments = ["cpp"], | |||
host_fragments = ["cpp"], | |||
cfg = proc_macro_host_transition, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Obviously just deleting these lines isn't the solution, but it does get the example to compile.
Any news on this one? I just got it as well updating the |
@Sythanis - I didn't make much progress on this, still trying to understand what these two lines actually do. My strategy was to use If you want to help, I think the solution should be something simple - if you check out this branch and run
you can get the rustc invocations bazel is generating and try to figure out what's going wrong. @johnedmonds maybe you have a better idea since you wrote #240 ? |
I tried to reach out to the author of the wasm PR, with no luck. I think if we can somehow figure out the test failures in this branch/why that code is necessary for wasm, we can fix this. I'll spend some more time looking at it this weekend and see if I can make any progress - want to do the same and compare notes? |
Sounds good, though I might not be able to dedicate a ton of time to this
over the weekend, but was planning to on Monday.
…On Sat, Apr 11, 2020 at 08:36 Colin Merkel ***@***.***> wrote:
I tried to reach out to the author of the wasm PR, with no luck.
I think if we can somehow figure out the test failures in this branch/why
that code is necessary for wasm, we can fix this.
I'll spend some more time looking at it this weekend and see if I can make
any progress - want to do the same and compare notes?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#294 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA2K7M7LBHLY5CEBULP2LRDRMCE7VANCNFSM4KZNTCRQ>
.
|
Sorry I missed this. I can try to dig into it a bit this week. If I'm understanding correctly is it that we're just not properly de-duping the dependencies? |
@johnedmonds no problem! Yeah I think that just be the root of it. I don't have a strong grasp on what was done in the wasm PR so any insight would be super valuable. |
I can try to explain the part you've identified in this PR: WASM is basically a separate compiler target but gets represented by a different toolchain (i.e. basically we swap out But some dependencies like I'm not sure why this would cause the library to be linked twice. It's possible bazel somehow thinks the host transition is considered a different architecture than the one you're currently building for. I wonder if a short-term solution is to only introduce the transition if you're transitioning from a I can try to experiment if that fixes this problem. |
Hmm, maybe that could explain it. Worth a shot to try it! Let me know if you get anywhere with it |
Looks like it might be because rust_binary and rust_library have two different cfg types. rust_library has one, while rust_binary is not specified. Adding the same thing to rust_binary appears to solve the issue. |
The "same thing" being:
to rust_binary's rule definition, and
to __rust_binary_attrs |
spoke too soon. I had made _proc_macro_host_transition a pass through by just returning settings. That didn't work, however, making it a pass through, and then adding the same configuration to both rust_library and rust_binary let at least the example compile, so perhaps that's a clue to what's going wrong. |
@dfreese That helps. Bazel transitions can cause a target to be built multiple times (once per build config). So I'm guessing |
So looking at my error messages a little more clearly, it looks like when I just added the cfg = proc_macro_host_transition, and whitelist to rust_binary, that was causing proc_macro_host_transition to fail on not having the "crate_type" attribute for some targets. Changing the check in _proc_macro_host_transition to
seems to work. Would the more appropriate solution be to move the whitelist into _rust_common_attrs from _rust_library_attrs, and add cfg = proc_macro_host_transition to all of the rules? |
I think that makes sense |
The rust_library rule specifies a cfg option. This performs transitions in order to support WASM. Other rules, such as rust_binary, do not have this configuration, which causes Bazel to build and link some libraries into the final binary twice, resulting in compilation errors. This is detailed in pull request bazelbuild#294 and issue bazelbuild#300. The issue was introduced in commit 7cde1e4. This adds the example from @colin353 in PR bazelbuild#294 as an example that would otherwise fail. Fixes bazelbuild#300
The rust_library rule specifies a cfg option. This performs transitions in order to support WASM. Other rules, such as rust_binary, do not have this configuration, which causes Bazel to build and link some libraries into the final binary twice, resulting in compilation errors. This is detailed in pull request #294 and issue #300. The issue was introduced in commit 7cde1e4. This adds the example from @colin353 in PR #294 as an example that would otherwise fail. Fixes #300
This PR doesn't actually fix anything yet, just introduces a failing example so I can debug it. I've been trying to update my personal rust + protobuf + grpc repository to the latest rules_rust, but it won't compile for the same reason as this example.
The bug is: when I have a rust binary which depends on a protobuf library A and another library B (which depends on A), I end up with A linked in twice, and rustc gives this error:
I've binary searched for the commit which introduced the bug, and I can confirm that the example compiles before 7cde1e4 but is broken afterward, i.e. the bug was introduced by #240.
I don't have a great understanding of what could cause this, but I dug into the rustc invocations before and after this PR, and noticed an extra rustc arg
-Ldependency=bazel-out/k8-fastbuild/bin/myproto_proto.proto.rust
in the broken invocation when compared to a working one.I'm going to try to do some debugging on this this weekend, but if anyone has any pointers or ideas, that'd be greatly appreciated.