-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
New rustc nightly suggests adding a build.rs
to use conditional compilation
#124800
Comments
Yes there is a list of well-known cfgs, for example #124742. |
Fuzzing is the biggest ecosystem-wide one, but we also use cfg flags to land code that isn't complete yet and we don't want to enable but which requires a long series of steps and we don't want to try to land it all in one go, so we need the ability to add our own in Cargo.toml. I can't imagine this is a super uncommon use? |
I fairly frequently use So I would also like a way to whitelist cfg flags. Cargo.toml would be great. For now I am disabling the lint entirely with |
It wouldn't be unnecessary, it would be used.
Adding a
The rule of thumb that was agreed in the stabilization of
Yes in a |
Sorry, but "add additional code that runs at build-time that users have to audit separately just to disable a compile-time warning" is really offensive stance. Indeed, some folks have legitimate uses for build.rs, and within parts of the Rust ecosystem build.rs is a totally accepted practice, but that definitely isn't universal and for those building security-conscious software build.rs is an orange flag that requires extra auditing and care, and is absolutely not something that is universally acceptable without consideration. More broadly, I also work on some projects that are optionally being built directly with |
imo this sounds like a case for
The original RFC proposed a I've created the following Pre-RFC that would create something for Cargo but don't have the time to drive it to completion and no one else has picked it up https://internals.rust-lang.org/t/pre-rfc-mutually-excusive-global-features/19618 |
There's a few issues with this - first of all just calling something "unstable-" doesn't mean no one can enable it, and it means a transitive dependency somewhere having a bug will mean my crate will suddenly generate completely bogus results. More generally, this isn't an "unstable" feature but rather a "you should never, ever, ever, ever enable this feature unless you're fuzzing, don't touch this". However, more broadly, we rely on transitive fuzzing features in some cases, and the standard, ecosystem-wide
Then maybe the warnings should be off by default until we make progress here? Or, at a minimum, the suggested fix should be to turn off the warnings, rather than add a
Yep, that's exactly why we use them - they're "transparent" to cargo which makes them incredibly useful for things like fuzzing and in-progress code. Suddenly throwing tons of warnings at users for what seems like a perfectly reasonable use of a language feature seems like quite a regression (but of course I understand the utility of these warnings - we have existing python scripts that parse our code and detect undefined cfg flags :) ). |
Not the fuzzing component. cfgs like |
If this is true then why is Cargo giving flags to rustc that complain about them? As Matt is saying, (one) purpose of using cfg flags is to bypass Cargo and its opinions. |
I refuse to believe that T-compiler, no matter what was proposed or read, really intended for dropping large swathes of needless lints on crates.io. The implications of this seem like an accident, much like #121708 was an accident. It is my opinion that the lint is actually quite useful when it detects things like this: #[cfg(target_os = "widnosw")] or things like this: #[cfg(linux)] It is not impossible someone would want to use But I don't think "this only bothers maintainers"... since when are those people with lots of time on their hands and happy to spend it on squashing trivial lints?... justifies the current implementation. It is particularly sad to me because I noticed that the large swathes of false positives almost completely drown out cases where a more cautious implementation would catch something. I only caught the snippets of signal it actually sent to backtrace-rs because I paid very close attention... and I still ended up only throwing in those two actual fixes and simply adding this to the Cargo.toml: [lints]
unexpected_cfgs = "allow" As to whatever ideas the Cargo team has regarding future work done in this area: those sound good! I think I've expressed tentative support for one of them, the global features thing, and it cuts fairly close to Job Reasons, so I might even be able to start working on it out of paid time. But they also seem like a good reason for the lint to be more restrained than firing according to its current brutalistically simple logic, since the preferred implementation depends on work that hasn't been done yet. |
Also, I should note, that it was always my impression that this was primarily intended to catch this, or I might have said something sooner: #[cfg(target_os = "widnosw")] This is an expansive set of linting decisions that have all been landed as one blob. Deciding to lint on |
I can understand being surprised by this and then having to clean it up out of cycle from your other work can be frustrating. In seeing these cases though, I wonder how much we need to keep in mind how representative our own experience might be for others. This feature is only on nightly so far which includes a certain level of sampling bias for those who are regularly running nightly in a way to notice this. Looking over the crater run results
How much overlap these have is unclear. iiuc the rest are either single digit project counts, look like bugs, or were marked as well known. My own personal anecdote for this is that I ran this on a good sampling of the packages I help maintain when the Call for Testing was made and only had bugs left after getting
The stabilization report was included the crater run analysis. Now, internalizing those numbers and weighing the impact isn't always straightforward. This is also a weird one because T-compiler was approving a generic mechanism that is controlled by the caller. In this case, Cargo is the main caller and T-cargo approved enabling it for everyone unconditionally. |
Speaking of Call for Testing, @workingjubilee as someone who maintains a project with a lot of cfgs, is there a reason you didn't participate? I wonder if there is some way we could change how Call for Testing is done to improve engagement. This is timely as I need to write up the Call for Testing for MSRV-aware resolver. Some other potential elements in this thread that might be worth exploring include
|
uhh the call for testing? I absolutely did not hear about them, or didn't notice it. yes I realize I may seem (or actually am??) Very Plugged In, what with following links like a hyperactive animated sprocket, I still did not hear about it. |
Irrespective of how common this is, I'm not sure its sensible. In the above discussion it was highlighted that |
This is an example of a Call for Testing. It used to be lower in the template but got moved up at Urgau's request out of concern that the first round of Call for Testing was too buried, so it was moved and we did a second Call for Testing. |
I don't really read TWiR because I don't need more interesting Rust projects to nerdsnipe myself with. |
Ah I wish I had looked at this at the time. The crater run analysis makes the classic mistake of only looking at regressions. Fortunately in this case it doesn't matter that much.
This analysis you're doing here does not follow from the way the crater run data was summarized. The lists from that Python script are truncated to the top 50, but by the number of errors, not by affected projects. My much-less-pretty analysis is this:
The list of cfgs with at least 10 affected crates is this:
|
Just to centralize discussion, this was also an issue for tokio. hyper and windows-rs. A workaround has been suggested by dtolnay. |
Thanks for doing that! Yes, I had forgotten to look closely at the constraints of the data I was looking at. |
Are there other ways we could be communicating out for Call for Testings that would help? |
Well... so, for the TWiR posting, when you mentioned it, I did check it out. But the first time I interacted with the process "Try to find the testing steps" I actually somehow clicked on the link that goes to the RFC. That was the first unnecessary opportunity for me to fail to find the testing steps. The content of the RFC is mostly meaningless to me because it was heavily revised in its journey to implementation. Even if I could have easily found it, it might, in general, have been best if the "call for testing" test steps had not been a stray comment near the end of a long RFC thread. The standard of discourse tolerated in RFC threads is... low, even by my standards. So I find myself increasing averse to even clicking on them. I also think the issue I have with the places the testing steps was mentioned is the same problem. It's... indirection. Yeah, programmers are comfy with a lot of indirection, usually, but a human has to deref it in this case, not a compiler, so you can expect a high dropoff for every step. 50% would be optimistic. 80%? 90%? So my first recommendation would be to make it as easy as possible to see the exact testing steps. They should probably get their own page, or at least be at the top of one. For example, their own GitHub issue or an Inside Rust blog post? That would be appropriate. |
Perhaps simple flags could be whitelisted in |
I believe this doesn't work if you have path dependencies because |
Discussed last week during T-compiler triage meeting (on Zulip). Relevant comment, for the record:
By reading the other comments that were added later, I think there are other user-facing considerations about how to enable this flag (but IIUC this is out of scope for us) |
We talked about this in this weeks Cargo team meeting. We decided to go forward with the |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
rust-lang/cargo#13913 has been reviewed and is now waiting on sign off from the rest of the Cargo team. |
…ease Update `unexpected_cfgs` lint for Cargo new `check-cfg` config This PR updates the diagnostics output of the `unexpected_cfgs` lint for Cargo new `check-cfg` config. It's a simple and cost-less alternative to the build-script `cargo::rustc-check-cfg` instruction. ```toml [lints.rust] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(foo, values("bar"))'] } ``` This PR also adds a Cargo specific section regarding check-cfg and Cargo inside rustc's book (motivation is described inside the file, but mainly check-cfg is a rustc feature not a Cargo one, Cargo only enabled the feature, it does not own it; T-cargo even considers the `check-cfg` lint config to be an implementation detail). This PR also updates the links to refer to that sub-page when using Cargo from rustc. As well as updating the lint doc to refer to the check-cfg docs. ~**Not to be merged before rust-lang/cargo#13913 reaches master!**~ (EDIT: merged in rust-lang#125237) `@rustbot` label +F-check-cfg r? `@fmease` *(feel free to roll)* Fixes rust-lang#124800 cc `@epage` `@weihanglo`
…ease Update `unexpected_cfgs` lint for Cargo new `check-cfg` config This PR updates the diagnostics output of the `unexpected_cfgs` lint for Cargo new `check-cfg` config. It's a simple and cost-less alternative to the build-script `cargo::rustc-check-cfg` instruction. ```toml [lints.rust] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(foo, values("bar"))'] } ``` This PR also adds a Cargo specific section regarding check-cfg and Cargo inside rustc's book (motivation is described inside the file, but mainly check-cfg is a rustc feature not a Cargo one, Cargo only enabled the feature, it does not own it; T-cargo even considers the `check-cfg` lint config to be an implementation detail). This PR also updates the links to refer to that sub-page when using Cargo from rustc. As well as updating the lint doc to refer to the check-cfg docs. ~**Not to be merged before rust-lang/cargo#13913 reaches master!**~ (EDIT: merged in rust-lang#125237) ``@rustbot`` label +F-check-cfg r? ``@fmease`` *(feel free to roll)* Fixes rust-lang#124800 cc ``@epage`` ``@weihanglo``
As of 3 nightly version ago (starting with [lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(foo, values("bar"))'] } (the diagnostic output has already been updated to suggest the Expecting |
Is the intent to stabilise the config asap or to delay using check-cfg? |
Thanks very much @Urgau! This results in a warning about unused manifest keys for old versions of cargo, but that is much less noisy than the original lint. I tested this across 4 or 5 of my crates and it worked perfectly. In fact, it found an actual typo :). |
The lint config is insta-stabilized.
We are silencing that warning in Beta in rust-lang/cargo#13925 so the window of people having the extra noise will be reduced. |
Update `unexpected_cfgs` lint for Cargo new `check-cfg` config This PR updates the diagnostics output of the `unexpected_cfgs` lint for Cargo new `check-cfg` config. It's a simple and cost-less alternative to the build-script `cargo::rustc-check-cfg` instruction. ```toml [lints.rust] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(foo, values("bar"))'] } ``` This PR also adds a Cargo specific section regarding check-cfg and Cargo inside rustc's book (motivation is described inside the file, but mainly check-cfg is a rustc feature not a Cargo one, Cargo only enabled the feature, it does not own it; T-cargo even considers the `check-cfg` lint config to be an implementation detail). This PR also updates the links to refer to that sub-page when using Cargo from rustc. As well as updating the lint doc to refer to the check-cfg docs. ~**Not to be merged before rust-lang/cargo#13913 reaches master!**~ (EDIT: merged in rust-lang/rust#125237) `@rustbot` label +F-check-cfg r? `@fmease` *(feel free to roll)* Fixes rust-lang/rust#124800 cc `@epage` `@weihanglo`
30a4825 bump nightly-version (Andrew Poelstra) 5ad7c24 cargo: whitelist all cfgs used in this repo (Andrew Poelstra) 814786b crypto: enable and fix accidentally disabled unit test (Andrew Poelstra) Pull request description: rust-lang/rust#124800 has been fixed and we can update our nightly version by whitelisting all cfgs that are used. There was one place where we had an old `cfg(feature = "no-std")` despite having removed the feature. By removing that cfg check we re-enabled a previously disabled test. ACKs for top commit: tcharding: ACK 30a4825 Tree-SHA512: d25bed819091db74b9d47cb2c23caa3ceb0d7be323b37831326e2ec1608cb1577d41aad2e1cdf59d66df69397537bc3e17a3c2872935d5a4f46f4dc55b5e613c
Update `unexpected_cfgs` lint for Cargo new `check-cfg` config This PR updates the diagnostics output of the `unexpected_cfgs` lint for Cargo new `check-cfg` config. It's a simple and cost-less alternative to the build-script `cargo::rustc-check-cfg` instruction. ```toml [lints.rust] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(foo, values("bar"))'] } ``` This PR also adds a Cargo specific section regarding check-cfg and Cargo inside rustc's book (motivation is described inside the file, but mainly check-cfg is a rustc feature not a Cargo one, Cargo only enabled the feature, it does not own it; T-cargo even considers the `check-cfg` lint config to be an implementation detail). This PR also updates the links to refer to that sub-page when using Cargo from rustc. As well as updating the lint doc to refer to the check-cfg docs. ~**Not to be merged before rust-lang/cargo#13913 reaches master!**~ (EDIT: merged in rust-lang/rust#125237) `@rustbot` label +F-check-cfg r? `@fmease` *(feel free to roll)* Fixes rust-lang/rust#124800 cc `@epage` `@weihanglo`
As we did in rust-bitcoin/rust-bitcoin#2785. rust-lang/rust#124800 has been fixed and we can update our nightly version by whitelisting all cfgs that are used.
Update `unexpected_cfgs` lint for Cargo new `check-cfg` config This PR updates the diagnostics output of the `unexpected_cfgs` lint for Cargo new `check-cfg` config. It's a simple and cost-less alternative to the build-script `cargo::rustc-check-cfg` instruction. ```toml [lints.rust] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(foo, values("bar"))'] } ``` This PR also adds a Cargo specific section regarding check-cfg and Cargo inside rustc's book (motivation is described inside the file, but mainly check-cfg is a rustc feature not a Cargo one, Cargo only enabled the feature, it does not own it; T-cargo even considers the `check-cfg` lint config to be an implementation detail). This PR also updates the links to refer to that sub-page when using Cargo from rustc. As well as updating the lint doc to refer to the check-cfg docs. ~**Not to be merged before rust-lang/cargo#13913 reaches master!**~ (EDIT: merged in rust-lang/rust#125237) `@rustbot` label +F-check-cfg r? `@fmease` *(feel free to roll)* Fixes rust-lang/rust#124800 cc `@epage` `@weihanglo`
We use conditional compilation in a lot of places (eg the
fuzzing
cfg flag is standard to conditionally compile when fuzzing in the rust-fuzz ecosystem) and have a hard rule against unnecessarybuild.rs
s (as running build-time code is a red flag when auditing a crate and requires special care). Latest rustc nightly now generates a huge pile of warnings encouraging us to add abuild.rs
to make them go away, which isn't really acceptable. It seems this is encouraging bad practice to respond to a common practice - is there some way to just listfuzzing
and some other super common flags and allow those?The text was updated successfully, but these errors were encountered: