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

Issue with check-cfg and bin targets #131376

Closed
Urgau opened this issue Oct 7, 2024 · 2 comments
Closed

Issue with check-cfg and bin targets #131376

Urgau opened this issue Oct 7, 2024 · 2 comments
Labels
C-discussion Category: Discussion or questions that doesn't represent real issues. F-check-cfg --check-cfg S-needs-repro Status: This issue has no reproduction and needs a reproduction to make progress.

Comments

@Urgau
Copy link
Member

Urgau commented Oct 7, 2024

Yeah, I'm using Rust 1.81.0, within my ./.cargo/config.toml, I have:

[build]
# MUST put `rustflags` NOT `RUSTFLAGS`
rustflags=["--cfg", "MAINNET"]

Then I have a very simple ./src/main.rs:

fn main() {
    #[cfg(MAINNET)]
    println!(
        "Hello, world! from `bins` and from `MAINNET`",
    );

    #[cfg(TESTNET)]
    println!(
        "Hello, world! from `bins` and from `TESTNET`",
    );
}

These are the warnings I get from cargo check:

warning: unexpected `cfg` condition name: `MAINNET`
 --> crates/bins/simulate_txn/src/main.rs:2:11
  |
2 |     #[cfg(MAINNET)]
  |           ^^^^^^^
  |
  = help: expected names are: `clippy`, `debug_assertions`, `doc`, `docsrs`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `rustfmt`, `sanitize`, `sanitizer_cfi_generalize_pointers`, `sanitizer_cfi_normalize_integers`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `ub_checks`, `unix`, and `windows`
  = help: consider using a Cargo feature instead
  = help: or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:
           [lints.rust]
           unexpected_cfgs = { level = "warn", check-cfg = ['cfg(MAINNET)'] }
  = help: or consider adding `println!("cargo::rustc-check-cfg=cfg(MAINNET)");` to the top of the `build.rs`
  = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration
  = note: `#[warn(unexpected_cfgs)]` on by default

warning: unexpected `cfg` condition name: `TESTNET`
 --> crates/bins/simulate_txn/src/main.rs:7:11
  |
7 |     #[cfg(TESTNET)]
  |           ^^^^^^^
  |
  = help: consider using a Cargo feature instead
  = help: or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:
           [lints.rust]
           unexpected_cfgs = { level = "warn", check-cfg = ['cfg(TESTNET)'] }
  = help: or consider adding `println!("cargo::rustc-check-cfg=cfg(TESTNET)");` to the top of the `build.rs`
  = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration

I tried adding the suggested fixes to ./build.rs:

fn main() {
    println!("cargo::rustc-check-cfg=cfg(TESTNET)");
    println!("cargo::rustc-check-cfg=cfg(MAINNET)");
}

It does not work at all.

Originally posted by @jymchng in #125368

@Urgau Urgau added C-discussion Category: Discussion or questions that doesn't represent real issues. F-check-cfg --check-cfg labels Oct 7, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 7, 2024
@Urgau Urgau removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 7, 2024
@Urgau
Copy link
Member Author

Urgau commented Oct 7, 2024

@jymchng I'm unable to reproduce the issue.

Creating a new repo with cargo new --bin "bug" and adding the content in src/main.rs and build.rs works as expected.

I see that the warning actually prints crates/bins/simulate_txn/src/main.rs, are you in a workspace? Do you have a special [[bin]] in your Cargo.toml?

It would be great if you could share a reproducible steps (a repo would be great, but instructions works too).

Btw, please avoid hijacking a old (and closed) issue, create a new one please.

@Urgau
Copy link
Member Author

Urgau commented Oct 14, 2024

@jymchng Are you able to give us more details about your issue?

@Urgau Urgau added the S-needs-repro Status: This issue has no reproduction and needs a reproduction to make progress. label Oct 15, 2024
@Urgau Urgau closed this as not planned Won't fix, can't repro, duplicate, stale Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-discussion Category: Discussion or questions that doesn't represent real issues. F-check-cfg --check-cfg S-needs-repro Status: This issue has no reproduction and needs a reproduction to make progress.
Projects
None yet
Development

No branches or pull requests

2 participants