-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Reuse CrateNum for proc-macro crates even when cross-compiling #86876
Conversation
For the record, the check was originally added in 5f295f2. |
This comment has been minimized.
This comment has been minimized.
6882454
to
9045650
Compare
@@ -598,7 +598,10 @@ impl<'a> CrateLoader<'a> { | |||
// don't want to match a host crate against an equivalent target one | |||
// already loaded. | |||
let root = library.metadata.get_root(); | |||
Ok(Some(if locator.triple == self.sess.opts.target_triple { | |||
// Proc-macro crates are always compiled for the host target, so they should be reused even if we're cross-compiling. |
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.
How does this interact with -Zdual-proc-macro
? It is used by bootstrap to ensure that cross-compilation of rustc works fine. It causes both the host and target version of a proc macro to be registered in the crate metadata allowing either to be used at runtime depending on if rustc runs on the original host or the target.
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.
I'm not sure. How can I test?
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.
The for sure test would be to try cross-compiling rustc and then try to compile a program linking against rustc_driver
using the cross-compiled rustc. Alternatively I think the following would also work:
- compile my_proc_macro for host in dir a
- compile my_proc_macro for target with the same filename in dir b
- compile my_crate for target with the host the host my_proc_macro as
--extern
and botha
andb
as-L
and-Zdual-proc-macros
as argument. (make sure touse my_proc_macro;
otherwise rustc won't actually load it) - try to link against my_crate using a compiler for the target, but the same version of rustc.
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.
I tried unsuccessfully to test this :( https://zulip-archive.rust-lang.org/131828tcompiler/56888HowdoIcrosscompilerustcforadifferenthost.html
I'd be happy with any fix that passes through existing rustc bootstrap CI and new tests from #56935. (I don't know right now what is the proper solution, but it will require a refactoring. I started such refactoring (#56935 (comment)) and continuing it is still in my work queue, but I never get to it due to review queue being overloaded (rust-lang/compiler-team#444).) |
@@ -598,7 +598,10 @@ impl<'a> CrateLoader<'a> { | |||
// don't want to match a host crate against an equivalent target one | |||
// already loaded. | |||
let root = library.metadata.get_root(); | |||
Ok(Some(if locator.triple == self.sess.opts.target_triple { | |||
// Proc-macro crates are always compiled for the host target, so they should be reused even if we're cross-compiling. |
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.
It's better to remove this comment or replace it with something like "we don't know what this condition means".
Right now it may look plausible to an unsuspecting reader, but it doesn't really make sense.
Proc-macros are always compiled for the host, so this should be the same in every way as recompiling the crate. I am not sure why the previous code special-cased the target, since the compiler properly gives an error when trying to load a crate for a different host: ``` error[E0461]: couldn't find crate `dependency` with expected target triple x86_64-unknown-linux-gnu --> /home/joshua/rustc4/src/test/ui/cfg-dependent.rs:8:2 | LL | dependency::is_64(); | ^^^^^^^^^^ | = note: the following crate versions were found: crate `dependency`, target triple i686-unknown-linux-gnu: /home/joshua/rustc4/build/x86_64-unknown-linux-gnu/test/ui/cfg-dependent/auxiliary/libdependency.so ``` I think another possible fix is to remove the check altogether. But I'm not sure, and this fix works, so I'm not making the larger change here.
9045650
to
68b9598
Compare
📌 Commit 68b9598 has been approved by |
☀️ Test successful - checks-actions |
rust-lang/rust#56935 was closed via rust-lang/rust#86876. Suggested-by: bjorn3 <bjorn3_gh@protonmail.com> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Proc-macros are always compiled for the host, so this should be the same
in every way as recompiling the crate.
I am not sure why the previous code special-cased the target, since the
compiler properly gives an error when trying to load a crate for a
different host:
I think another possible fix is to remove the check altogether. But I'm
not sure, and this fix works, so I'm not making the larger change here.
Fixes #56935.
r? @petrochenkov cc @alexcrichton