-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Start using serde_derive in a couple places in the compiler. #56447
Conversation
r? @estebank (rust_highfive has picked a reviewer for you, use r? to override) |
@bors try to check a dist build (though I don't expect it to be different) |
Start using serde_derive in a couple places in the compiler. Note that this doesn't actually use `serde` for anything currently - I have a different branch where I started that, but I thought I'd extract this proof of concept out, to deal with build system issues. The second commit is needed to fix this error in `rustc_codegen_llvm` and `rustdoc`: ``` error[E0463]: can't find crate for `serde_derive` which `rustc` depends on ``` This problem arises because we use different Cargo build dirs for codegen backends and `rustdoc` from the main `rustc` Cargo build dir, and without the second commit in this PR, the host `deps` (including `serde_derive`) weren't copied over to the common sysroot (shared between all builds). *Quite surprisingly*, everything else seems to "just work"! This is in part because of pre-existing logic in `rustbuild` to only use `stage0` for build scripts when building libstd itself, which *happens to* be what we need to make proc macros work in all stages 🎉 cc @alexcrichton @Mark-Simulacrum @Zoxc @nikomatsakis
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
☀️ Test successful - status-travis |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Looks like the last failure is caused by Also, in general, I feel like we should distinguish between "crates you can use from the sysroot" and "dependencies of sysroot crates", similar to how Cargo uses |
Hm I think I'm a bit lost here, how does this patch work? Shouldn't procedural macros always be compiled by the compiler that build the standard library in that stage? (aka not always the stage0 compiler). I think though that with our shim it's always using the stage0 compiler? Also.. how does this work without your patches on nightly for decoupling proc_macro/rustc? |
@alexcrichton So the helpfully-preexisting behavior I allude in the PR description is here: Lines 959 to 983 in c8ae2de
That's almost literally the exact same logic I mentioned I was considering implementing on Discord, except someone already did it! Build scripts can always use stage0/bin/rustc so they don't need it, but it still applies.
As for What should happen at Note that using proc macros in the compiler has always worked, but only at This might be accidentally right in rustbuild, again, because the locally-built libraries of To be really honest, I wasn't expecting this to work either without more tweaks. But someone from the past was too clever in rustbuild and stumbled upon what we need for proc macros! |
Ok this is starting to make a bit more sense I think, we'll always compile procedural macros against the stage0 What I still don't think I understand though is how this works at all in stage0 right now. Currently our stage0 compiler does the old procedural macro system. This PR, however, compiles As a side note as well, does this mean that we can never change the ABI of procedural macros? If procedural macros are always compiled against the stage0 version, how do we change the signatures? |
// If this was output in the `deps` dir then this is a precise file | ||
// name (hash included) so we start tracking it. | ||
if filename.starts_with(&target_deps_dir) { | ||
if filename.starts_with(&host_root_dir) || filename.starts_with(&target_deps_dir) { |
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.
Can you expand a bit on what's going on here? This feels like it shouldn't be necessary...
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 PR description tries to explain this. It's needed for the compiler to be able to find the (host-only) proc macro dependencies of e.g. librustc
, from across a Cargo build (i.e. from codegen backends).
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.
Hm ok, I ask because I don't think that this is right. This I think is definitely not what we want when cross-compiling because it's mixing architectures of libraries in one directory. For non-cross-compiling situations this'll copy too much for things like build scripts and/or intermediate proc-macro dependencies.
Could we perhaps whitelist an explicit copy of serde_derive if necessary? Or something like that?
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 would be nice if cargo would tell us if artifacts are proc macros, but I think a whitelist will suffice here
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.
Mixing architectures isn't a problem for rustc
, and a whitelist feels hackier IMO.
I still like the idea of making the same -Ldependency=
distinction Cargo makes, in the sysroot, as well (from #56447 (comment)).
In fact, we can even copy the host deps to rustlib/$host/deps
instead of rustlib/$target/deps
, and have the compiler look in the right place.
I should also mention I was able to work around this by adding a serde_derive
dependency to librustc_codegen_llvm
, but I feel like this also doesn't scale (and it builds serde_derive
more than once).
I guess I'd accept the whitelisting if someone else implemented it, just to unblock @Zoxc.
☔ The latest upstream changes (presumably #56578) made this pull request unmergeable. Please resolve the merge conflicts. |
ping from triage @eddyb you need to rebase this |
Ping from triage @eddyb: What is the status of this PR? |
ping from triage @eddyb Unfortunately we haven't heard from you on this in a while, so I'm closing the PR to keep things tidy. Don't worry though, if you'll have time again in the future please reopen this PR, we'll be happy to review it again! |
Note that this doesn't actually use
serde
for anything currently - I have a different branch where I started that, but I thought I'd extract this proof of concept out, to deal with build system issues.The second commit is needed to fix this error in
rustc_codegen_llvm
andrustdoc
:This problem arises because we use different Cargo build dirs for codegen backends and
rustdoc
from the mainrustc
Cargo build dir, and without the second commit in this PR, the hostdeps
(includingserde_derive
) weren't copied over to the common sysroot (shared between all builds).Quite surprisingly, everything else seems to "just work"!
This is in part because of pre-existing logic in
rustbuild
to only usestage0
for build scripts when building libstd itself, which happens to be what we need to make proc macros work in all stages 🎉cc @alexcrichton @Mark-Simulacrum @Zoxc @nikomatsakis