rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.2k stars 12.56k forks source link

Add option to disable checking conditional compilation at compile time in `std` #99901

Closed tsoutsman closed 2 years ago

tsoutsman commented 2 years ago

Hi, I've forked the Rust compiler to add a new target operating system. However, I ran into issues with the work being done for #82450.

My builds were failing with the following error:

error: unexpected `cfg` condition value
  --> library/std/src/sys/mod.rs:40:21
   |
40 |     } else if #[cfg(target_os = "theseus")] {
   |                     ^^^^^^^^^
   |
   = note: `-D unexpected-cfgs` implied by `-D warnings`
   = note: expected values for `target_os` are: android, cuda, dragonfly, emscripten, espidf, freebsd, fuchsia, haiku, hermit, horizon, illumos, ios, l4re, linux, macos, netbsd, none, openbsd, psp, redox, solaris, solid_asp3, tvos, uefi, unknown, vxworks, wasi, watchos, windows, xous

even when using a custom target spec with os: "theseus". To circumvent the issue I removed the checks, but this isn't an ideal fix. I'm not sure what the best solution is, but it should be mentioned on the Adding a new target page in the rustc dev guide.

gimbling-away commented 2 years ago

I don't think that is valid Rust? You might be confusing it with the cfg! macro. =)

tsoutsman commented 2 years ago

I don't think that is valid Rust? You might be confusing it with the cfg! macro. =)

Sorry for the bad example, the code is from the cfg_if! macro here. I think the issue is still valid.

mati865 commented 2 years ago

You can probably workaround it by guarding it with bootstrap cfg.

Urgau commented 2 years ago

@tsoutsman Sorry, for the trouble you had. The reason why you have the error is because the stage0 compiler is based on the beta compiler who doesn't (yet) know about your (new) target. The way to fix it is by adding an exception for your target to the EXTRA_CHECK_CFGS list: https://github.com/rust-lang/rust/blob/2f847b81a0d8633f200f2c2269c1c43fe9e7def3/src/bootstrap/lib.rs#L205-L209

I would suggest doing something like this:

- Some(&["asmjs", "spirv", "nvptx", "nvptx64", "le32", "xtensa"]),
+ // #[cfg(bootstrap)] theseus -- This is just to make just that new exception is removed when the stage0 compiler is bumped
+ Some(&["asmjs", "spirv", "nvptx", "nvptx64", "le32", "xtensa", "theseus"]),