Open andreeaflorescu opened 1 year ago
I suspect this is a Cargo bug. Cargo is not propagating that -Zallow-features=
in the CARGO_ENCODED_RUSTFLAGS seen by the build script.
I tested this by creating a 2-line .cargo/config.toml as you showed, and a build script containing:
// build.rs
fn main() {
std::process::Command::new("env").status().unwrap();
std::process::exit(1);
}
The output of env
printed by cargo build
shows that CARGO_ENCODED_RUSTFLAGS is empty. I believe it should contain -Zallow-features=
. The whole point of Cargo providing CARGO_ENCODED_RUSTFLAGS to build scripts is so that the build script can make rustc invocations using the same flags that Cargo would use for its own rustc invocations.
Indeed, it looks like the flag is not passed when using [unstable]
, but it is passed when using:
[build]
rustflags = ["-Zallow-features="]
I am not very sure if I should open an issue in cargo though, as it might be expected based on this 🤷♀️ https://github.com/rust-lang/cargo/issues/12437#issuecomment-1677584903.
Out of curiosity, what is the reasoning for always enabling proc_macro_span
? Considering it's unstable, my expectation would be for it to be enabled only by using a non-default feature, and not the other way around.
I belive I'm having the same issue. Recently when trying to build any crate on nightly, I'm always getting errors from proc-macro2. Eg:
error[E0635]: unknown feature `proc_macro_span_shrink`
--> /Users/ari/.cargo/registry/src/index.crates.io-6f17d22bba15001f/proc-macro2-1.0.47/src/lib.rs:92:30
|
92 | feature(proc_macro_span, proc_macro_span_shrink)
This forces me to use stable as I don't know how to fix this.
@tqwewe You are required to also update the crate to the latest version, so,
cargo update -p proc-macro2 --precise 1.0.81
as proc-macro2 enables nightly features implicitly to save you the inconvenience of having to think about and enable a feature on your own. This also means that each version of this software is neither forward nor backward compatible if anything changes even slightly about versioning or build flags or etc.
From the documentation of
proc_macro_span
I was understanding that if you don't allow unstable features in your nightly build, then the build of the crate should still work: "Enabled when building with nightly, unless-Z allow-feature
in RUSTFLAGS disallows unstable features."I am using the following configuration in my
.cargo/config.toml
:And the following rust nightly:
nightly-2023-09-25
.When building a dummy crate that just has proc-macro2 as a dependency, the following happens:
The
--cfg proc_macro_span
was added even though we also pass the-Zallow-features=
flag. Is this the expected behavior?I would like to be able to build proc-macro2 with nightly without having to enable the unstable feature. Is this possible?