-
-
Notifications
You must be signed in to change notification settings - Fork 119
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
Nightly detection does not take into account whether features can actually be used #177
Comments
This can also be seen if you adjust the above to $ cargo check
...
error[E0725]: the feature `doc_cfg` is not in the list of allowed features
--> /Users/jongje/.cargo/registry/src/github.com-1ecc6299db9ec823/cookie-0.15.0/src/lib.rs:77:30
|
77 | #![cfg_attr(nightly, feature(doc_cfg))]
| ^^^^^^^ |
So this occurs when a crate 1) uses a build of This seems...totally weird to me, to the same effect as the In any case, I don't generally like the idea of probing. Really, there's obviously something very broken here with crates needing to figure out if/when they can do things. Probing for a feature doesn't mean that that feature works the way you expect it to. Feature implementations can change, for example, or the implementation can be broken in one nightly and working in another. We're just trading one set of edge-cases for another. For this particular issue, we can simply gate enabling the feature on |
The use-case for this is when consumers want to test a particular feature that's been vetted and risk-assessed, but don't want to opt into all unstable features more broadly. There's a bunch more discussion over in this internals thread. In my case, I am constrained to using stable Rust from an operational risk perspective, but also specifically need the Restricting the use of this feature only to doc helps, but only marginally. It will still prevent users in such environments (which likely means most large-scale commercial code-bases) from generating documentation for I agree with you that there's a bad smell coming from the need for crates to "sniff" for nightly features in their build scripts, but arguably that's just a side-effect of trying to use an unstable feature, which is, inherently, unstable. In my opinion at least, it's up to the build scripts that add such sniffing to do the best they can to make the sniffing as accurate as they can, rather than just blanket checking for "nightly". That's the cost of trying to depend on unstable features. You're right that in practice you can't truly probe for "the feature works exactly the way I need", but there's a far stretch from that to throwing up our collective hands and saying we're not even going to try. A compile probe is much better than just checking for nightly, and much less likely to enable the feature when it cannot be, and I think it's a meaningful improvement. |
You can generate documentation for
This might be the case for library dependents, but not for binary dependents.
Why doesn't this same logic apply to your environment, and doubly so? Your environment is using a flag,
In a vacuum, I agree. But doing this means that we literally have to compile a program before we even begin to build the library. Every crate that transitively depends on |
I'd like to start by saying that this is definitely a thorny issue in the Rust ecosystem with not a lot of great options available to either party. And that's part of what we're running into here.
That is true for anyone with free choice of what toolchain configuration they're using. In many larger organizations that want (for good reasons I would argue) strict control over what toolchains and unstable features are used, that will not be the case. And while the user may have an escape hatch to force a particular toolchain, that would mean working around the toolchain they are "stuck" with. Organizational uses are not the only place where this comes up though — you could also imagine projects that have to pin a nightly for unrelated reasons, and also get tripped up on this nightly check not being able to realize that their nightly can't support the feature in question.
I think
It adds a cost, that's definitely true. Though given that the crate isn't recompiled for each dependent, the cost is somewhat mitigated. The fact that
We disagree here — the upside is that developers who a) are forced to use particular toolchain configurations; or b) must use nightly and want to restrict their reliance on unstable with |
I think this is a fair compromise. Thanks for suggesting it. I'll be implementing it soon. Edit: Oh, I see, this isn't actually possible until rust-lang/cargo#9601 lands. Well alright. This really seems like whack-a-mole now when the correct solution to this (and all other version query related problems) is for |
Heh, yeah, it really is. A long dependency chain brought me here 😅 And I actually had the same though as you — it'd be really nice if there was a
❤️ |
rust-lang/cargo#9601 has now landed, and the new environment variable |
FWIW https://github.com/cuviper/autocfg provides basically that. It doesn't seem to support probing for feature flags, but that should be easy to add? EDIT: Ah looks like cuviper/autocfg#35 has been sitting around form a while... |
Currently, the build script just checks whether the user is using nightly, but that doesn't work when the user's configuration, other flags, or the rustc wrapper, prevent the use of the relevant features:
produces
The
proc-macro2
crate specifically tries to handle this by parsingRUSTFLAGS
if set, though that currently also runs into issues (dtolnay/proc-macro2#290). Theanyhow
crate uses a "compile probe", which is very robust, but currently suffers from lack of information from Cargo (dtolnay/anyhow#156). But once rust-lang/cargo#9601 lands, we'll have access to the necessary configuration information to check for feature support using either of those two approaches.I filed this here (in addition to
proc-macro2
) because onceproc-macro2
is fixed, cookie will start breaking with the same reproduction steps due to thisbuild.rs
:https://github.com/SergioBenitez/cookie-rs/blob/434721e1f9fdf9bdb6ec6d760918e1c7390c9a93/build.rs#L2-L3
The text was updated successfully, but these errors were encountered: