-
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
Provide a way for build scripts to invoke rustc the way cargo would #11244
Comments
With issues like rust-lang/rust#114839, I am not even sure any more if merely providing all the right arguments to Maybe there is a way this can be resolved with more flags though, i.e. if the build script instructed rustc to put build-dep information into a particular location and then cargo would pick it up there -- then the |
A solution might be #12432, if there is an API can give you the ability of "build probe". And people might be happy and avoid re-implement argparse for rustc. |
Sounds like options include
I'd like to throw out another one: we focus on |
These will require cooperation with cargo, since currently build scripts just do not have the information required to generate the right rustc invocation. |
How big of a use case is supporting multiple flavors of a nightly feature? To me, that sounds like a relatively small use case. Could you expand your uses for doing that? |
I did not talk about supporting multiple flavors of a nightly feature. I talked about what happens when a nightly feature changes the type of an item. Code written |
For myself, I've grown increasingly frustrated with build probes being used in this way (implicit opt-in to nightly features) to the point that I feel its an anti-pattern. Also been discussing that in dtolnay/anyhow#323. |
I share some of that frustration. But what's even more frustrating is having to deal with build probes that don't work properly.^^ The build probes exist and so these issues show up, e.g. as Miri bugreports or as hard-to-debug failures in rustc bootstrapping when a nightly API changes. Wishing the build probes away won't fix those issues... |
We talked about this in today's cargo meeting. The use cases seem to be focused on build probes. We are not inclined to add features specifically for build probes at this time but would instead encourage use of
While |
The MSRV-aware resolver only helps once you've transitioned to an MSRV high enough to always have that resolver. I suppose if that comes before those other features, then that will indeed add some leeway and allow policy adjustment. |
I'm assuming the standard workflow is that of running |
This doesn't satisfy many of the cases people use build probes for.
This would need a concerted effort by the project to convince the community of this. Right now, the status quo is that we have a lot of bad build probes out there, and they are unlikely to go anywhere. They cause trouble for cross-compilation, Miri, rsutc bootstrap, There is clearly a need for this. We can either satisfy that need, or we don't and then we suffer from the hacks people use when they satisfy their need their own way. This is already a real problem today, and it's only going to get worse. |
Global features sound nice; if/when that happens, maybe we can convince crate authors to gate some of these things behind a global |
@epage I have my own reasons for wanting to disable autodetection of nightly sometimes, so I wrote a small utility to override version-based detection. Let me know if it is useful for you. |
Problem
It is a common pattern in build scripts to run a rustc 'build probe': compile some code with rustc, see if that works, and then enable some
cfg
flags depending on the result. Crates use this to automatically detect if some API they optionally use is available on the current compiler. Examples of this include anhow, thiserror, eyre, and the autocfg crate which abstracts that pattern into a library.However, invoking rustc in the right way is non-trivial. build scripts have to remember to check RUSTC and RUSTC_WRAPPER, to pass on the RUSTFLAGS (using CARGO_ENCODED_RUSTFLAGS where possible so spaces are preserved properly), and to set
--target
based on the TARGET env var. And even then the final rustc invocation is not always the same as what cargo itself uses, causing issues like the one described here: it is impossible to tell, from the information a build script has, whether cargo will pass--target
to rustc or not, and there are some situations (rustc bootstrap and Miri, for instance) where this really matters. As a consequence, the aforementioned crates sometimes break in rustc bootstrap and Miri when they are used as dependency of a proc macro.Proposed Solution
Cargo should just tell the build script how it will invoke rustc. I'm imagining an env var like
CARGO_ENCODED_RUSTC
(name to be bikeshed), which build scripts could use like this:Notes
Does this need an RFC?
The text was updated successfully, but these errors were encountered: