rust-lang / rust

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

check-cfg does not appear to honor target-spec json #108941

Closed ehuss closed 1 year ago

ehuss commented 1 year ago

--check-cfg=values() doesn't seem to know that custom targets can extend the set of values.

Steps

The following creates a custom spec with a target_os="ericos".

  1. cargo new --lib foo
  2. cd foo
  3. rm src/lib.rs
  4. cat <<EOF > src/lib.rs
    #![no_std]
    
    #[cfg(target_os = "macos")]
    pub fn macos() {}
    
    #[cfg(target_os = "ericos")]
    pub fn eric() {}
    EOF
  5. cat << EOF > custom.json
    {
       "llvm-target": "x86_64-unknown-none-gnu",
       "data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
       "arch": "x86_64",
       "target-endian": "little",
       "target-pointer-width": "64",
       "target-c-int-width": "32",
       "os": "ericos",
       "linker-flavor": "ld.lld",
       "linker": "rust-lld",
       "executables": true
    }
  6. cargo check --target custom.json -Zbuild-std=core -Zcheck-cfg=values

Expected

No warning

Actual

Got the warning:

warning: unexpected `cfg` condition value
 --> src/lib.rs:6:7
  |
6 | #[cfg(target_os = "ericos")]
  |       ^^^^^^^^^^^^^^^^^^^^
  |
  = note: expected values for `target_os` are: aix, android, cuda, dragonfly, emscripten, espidf, freebsd, fuchsia, haiku, hermit, horizon, illumos, ios, l4re, linux, macos, netbsd, none, nto, openbsd, psp, redox, solaris, solid_asp3, tvos, uefi, unknown, vita, vxworks, wasi, watchos, windows, xous
  = note: `#[warn(unexpected_cfgs)]` on by default

warning: unexpected condition value `ericos` for condition name `target_os`
  |
  = help: was set with `--cfg` but isn't in the `--check-cfg` expected values

Meta

rustc 1.69.0-nightly (7281249a1 2023-02-27)
binary: rustc
commit-hash: 7281249a19a9755e9d889ee251ec323629caadab
commit-date: 2023-02-27
host: aarch64-apple-darwin
release: 1.69.0-nightly
LLVM version: 15.0.7

cc @Urgau

Urgau commented 1 year ago

@rustbot claim