thread 'main' panicked at ../lib.rs:262:9:
task tracing requires Tokio to be built with RUSTFLAGS="--cfg tokio_unstable"!
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Could somebody explain if it possible to optionally set RUSTFLAGS in this way or probably there another good solution exists ?
Thank you for the reply. Unfortunately the ENV variable still not set. Btw, I've found the correct way to check for feature: CFG_FEATURE_* env variable:
Probably this helps. I build the app with the command:
cargo build --no-default-features --features debug, ...rest features
when I add this line to main.rs, this works:
#[cfg(tokio_unstable)]
compile_error!("THE FLAG IS ENABLED");
but when I run the app from ../target/debug it still returns the error:
thread 'main' panicked at ../lib.rs:262:9:
task tracing requires Tokio to be built with RUSTFLAGS="--cfg tokio_unstable"!
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
I tried to build with --verbose parameter and as I can see from output, there a difference between building with RUSTFLAGS="--cfg tokio_unstable" cargo build and without it (but keeping the settings in the build.rs). First approach adds the flag to each crate, but second only to the current.
So, probably there some way to add the flag to each dependency recursively ?
Sorry, my bad, I didn't think this through. Tokio is using tokio_unstable as a conditional compilation flag, rather than a feature, to avoid dependencies being able to opt into the unstable functionality. Only the user can do so during compilation. So it is by design that you can't enable the tokio_unstable feature in your build script for the whole dependency tree. Which makes sense. It would be horrible to debug if some crate were able to randomly set conditional compilation flags for other dependencies, breaking the build process in potentially subtle ways.
cargo::rustc-cfg=KEY[="VALUE"]
[...]
Note that this does not affect Cargo’s dependency resolution. This cannot be used to enable an optional dependency, or enable other Cargo features.