-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
build probes confused by cargo always setting TARGET, even for build scripts of host dependencies #11138
Comments
This seems related to #5755, but there it sounds like a feature request to provide more information -- I think cargo is actively providing false information right now by setting that |
Sorry I had a hard time reproducing this issue. Could you tell me which command you ran failed? |
I ran To reproduce, you'll need a proc-macro that has a dependency that has a build script. |
Here's an example project. I would expect the proc macro build script to not have a TARGET env var, since it always is a host build. The real problem isn't the proc macro build script itself, but build scripts in proc macro dependencies -- those can't know that they are actually being built for the host. Though to be fair, I realized the TARGET variable is set to the host architecture even for cross-builds. In fact TARGET is set even for non-cross regular builds. However there are situations where "host and target" have the same architecture but still need to be distinguished, in particular for rustc bootstrapping (where "host" is the downloaded beta toolchain and "target" is the newly built compiler). Usually cargo (maybe by accident) supplies enough information to make that work: target crates are built with This is definitely kind of a hack, but AFAIK cargo provides no alternative way to do this kind of bootstraping. |
I think it would make more sense to add a new env var for this usecase. |
The problem with using a new env var is that then we'll also have to adjust anyhow, autocfg, and many other crates that have logic for "build a test file with rustc to see if we can use some feature". |
Back to the original issue. Did you mean that Here is a repro example. I cannot reproduce. Not sure what I missed. 😞 |
@weihanglo The original issue RalfJung raised was that
|
@jschwe That's a proposal they gave, not the problem they encountered.
I interpret it as: |
What is currently happening is that build scripts will get a |
No. TARGET on anyhow should be unset. That is needed to make the existing logic work, anyway. If TARGET needs to be always set then we need to first provide some other way to convey this information from cargo to the build script (that is #5755) and then we need to change all the crates out there that run a 'probe build' to see if they can use some feature. :/ (anyhow, autocfg, thiserror, eyre -- we'll never be able to identify them all) |
@bjorn3 TARGET would be always set for the 'target' part of the build (which I think is the whole build when |
I'm not sure cargo distinguishes betweeb host and target deps in any way other than need to/need not to pass |
Cargo definitely makes a distinction that it does not expose to build scripts -- even with Maybe the better approach would be to have cargo set an env var like
AFAIK it gets compiled twice then, for two different targets, so which TARGET value does the build script see? This question already arises in current cargo. (I would expect the build script to be run twice.) |
I meant if |
Honestly I don't care what it does then, the cargo consumers that care about this always set That's why I had a parenthetical above, saying if |
Another case that will break if TARGET is unset is when the cc crate is used in the build script of a build script dependency. The cc crate requires the TARGET env var to be set. |
I think I anyway prefer the solution of having cargo supply the rustc invocation, rather than each and every build script having to re-implement the same logic. So closing this in favor of #11244. |
Yeah, just want to say: failing to provide
And so on. (This isn't to say it's not a problem and that things couldn't be improved -- and even several of these cases will behave incorrectly in multi-level build-script situations similar to the one described initially... That said, just I wanted to note that the breakage would be very, very bad if |
Okay, that's fair. But not providing build scripts with crucial information about the crate this is built for is also causing breakage -- just in subtle ways that take hours to debug. Turns out this was already pointed out many years ago, but sadly the issue is still open: #5755. |
I just spent a about an hour debugging a build failure in the rustc workspace that boils down to this issue:
use std::backtracke::Backtrace
.TARGET
env var is set, it runs the build probe with--target
passed to rustc, meaning this is conceptually a target build (this is the right thing to do, it is needed to make build probes work in cross-compilation settings when anyhow is used by the target code)In the case of bootstrap, the target sysroot has the
backtrace
feature stable but the host (beta) sysroot does not. So this means that anyhow enables the backtrace feature and later fails to use the backtrace feature.I think it is a cargo bug that the
TARGET
env var is set for a build script that does not run on the target. Cargo should unset that env var for host build script builds.The text was updated successfully, but these errors were encountered: