Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ehuss opened this issue Mar 9, 2023 · 1 comment · Fixed by #108949
Closed

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

ehuss opened this issue Mar 9, 2023 · 1 comment · Fixed by #108949
Assignees
Labels
A-target-specs Area: Compile-target specifications C-bug Category: This is a bug. F-check-cfg --check-cfg

Comments

@ehuss
Copy link
Contributor

ehuss commented Mar 9, 2023

--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

@ehuss ehuss added C-bug Category: This is a bug. F-check-cfg --check-cfg labels Mar 9, 2023
@Urgau
Copy link
Member

Urgau commented Mar 9, 2023

@rustbot claim

@workingjubilee workingjubilee added the A-target-specs Area: Compile-target specifications label Mar 11, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 11, 2023
…-obk

Honor current target when checking conditional compilation values

This is fixed by simply using the currently registered target in the current session. We need to use it because of target json that are not by design included in the rustc list of targets.

Fixes rust-lang#108941
@bors bors closed this as completed in d4754ed Mar 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-target-specs Area: Compile-target specifications C-bug Category: This is a bug. F-check-cfg --check-cfg
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants