Navigation Menu

Skip to content
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 #126

Closed
jonhoo opened this issue Jul 6, 2021 · 4 comments

Comments

@jonhoo
Copy link

jonhoo commented Jul 6, 2021

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:

cargo new rstest-issue
cd rstest-issue
mkdir .cargo
echo '[build]' >> .cargo/config.toml
echo 'rustflags = ["-Zallow-features="]' >> .cargo/config.toml
echo 'rstest = "0.6"' >> Cargo.toml
rustup override set nightly
cargo check

produces

   Compiling rstest v0.6.4
error[E0725]: the feature `proc_macro_span` is not in the list of allowed features
  --> /Users/jongje/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-1.0.27/src/lib.rs:82:59
   |
82 | #![cfg_attr(any(proc_macro_span, super_unstable), feature(proc_macro_span))]
   |                                                           ^^^^^^^^^^^^^^^

error[E0658]: use of unstable library feature 'proc_macro_span'
   --> /Users/jongje/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-1.0.27/src/wrapper.rs:517:72
    |
517 |             (Span::Compiler(a), Span::Compiler(b)) => Span::Compiler(a.join(b)?),
    |                                                                        ^^^^
    |
    = note: see issue #54725 <https://github.com/rust-lang/rust/issues/54725> for more information
    = help: add `#![feature(proc_macro_span)]` to the crate attributes to enable
...

The proc-macro2 crate specifically tries to handle this by parsing RUSTFLAGS if set, though that currently also runs into issues (dtolnay/proc-macro2#290). The anyhow 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 once proc-macro2 is fixed, cookie will start breaking with the same reproduction steps due to this build.rs:

rstest/build.rs

Lines 7 to 9 in 3e6648a

match version_meta().unwrap().channel {
Channel::Nightly | Channel::Dev => {
println!("cargo:rustc-cfg=use_proc_macro_diagnostic");

You can see that by changing the instructions above to -Zallow-features=proc_macro_span:

$ cargo check
   Compiling rstest v0.6.4
error[E0725]: the feature `proc_macro_diagnostic` is not in the list of allowed features
   --> /Users/jongje/.cargo/registry/src/github.com-1ecc6299db9ec823/rstest-0.6.4/src/lib.rs:213:48
    |
213 | #![cfg_attr(use_proc_macro_diagnostic, feature(proc_macro_diagnostic))]
    |                                                ^^^^^^^^^^^^^^^^^^^^^

See also rwf2/cookie-rs#177.

@la10736
Copy link
Owner

la10736 commented Jul 7, 2021

Thanks very much. I'll update my code to use when it land.

@jonhoo
Copy link
Author

jonhoo commented Jul 7, 2021

Honestly, I'd recommend instead using something like @cuviper's autocfg, which will implement the logic for you, and will be upgraded to use the logic once it lands with no further changes needed on your part :) There's also version_check which doesn't currently implement the logic for "is this specific feature available", but will do so soon.

@jonhoo
Copy link
Author

jonhoo commented Aug 13, 2021

You can now parse CARGO_ENCODED_RUSTFLAGS, which is provided by nightly cargo and will be on the next beta (rust-lang/cargo#9601).

@la10736
Copy link
Owner

la10736 commented Dec 12, 2021

I choose to implement CARGO_ENCODED_RUSTFLAGS parsing because autocfg don't implement the feature probing that I need and the pull request stuck from a while. Also version_check haven't any plan to implement it soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants