nix
nix copied to clipboard
Enable "Checking conditional compilation value at compile time" when it is stable?
trafficstars
This will check invalid conditions, which would be quite useful for us, see the following demo:
#[cfg(target_os = "linxu")] // NOTE this typo!
fn foo_for_linux() { }
fn main() { }
$ cargo +nightly check -Z unstable-options -Z check-cfg
Checking rust v0.1.0 (/home/steve/Documents/workspace/playground/rust)
warning: unexpected `cfg` condition value: `linxu`
--> src/main.rs:1:7
|
1 | #[cfg(target_os = "linxu")]
| ^^^^^^^^^^^^-------
| |
| help: there is a expected value with a similar name: `"linux"`
|
= note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `openbsd`, `psp`, `redox`, `solaris`, `solid_asp3`, `teeos`, `tvos`, `uefi`, `unknown`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg> for more information about checking conditional configuration
= note: `#[warn(unexpected_cfgs)]` on by default
Our aliases defined in build.rs are also invalid, to allow them, we can:
// build.rs
fn main() {
println!("cargo:rustc-check-cfg=cfg(apple_targets)");
println!("cargo:rustc-check-cfg=cfg(bsd)");
println!("cargo:rustc-check-cfg=cfg(linux_android)");
println!("cargo:rustc-check-cfg=cfg(freebsdlike)");
println!("cargo:rustc-check-cfg=cfg(netbsdlike)");
println!("cargo:rustc-check-cfg=cfg(solarish)");
...
}
It is still unstable and only available in nightly, maybe we can enable this check when it is in stable.
Oops, I just noticed this is a duplicate of #1734
Looks like we already had this since Rust nightly 1.80, see this PR: https://github.com/nix-rust/nix/pull/2394
Yeah, I think we should close the issue. it's good enough to have it on nightly.