Skip to content

ci: register cargo-clippy cfg to silence objc 0.2.7 macro warnings#231

Closed
paravozz wants to merge 1 commit intoRustAudio:masterfrom
paravozz:fix/ci-unexpected-cfgs
Closed

ci: register cargo-clippy cfg to silence objc 0.2.7 macro warnings#231
paravozz wants to merge 1 commit intoRustAudio:masterfrom
paravozz:fix/ci-unexpected-cfgs

Conversation

@paravozz
Copy link
Copy Markdown

@paravozz paravozz commented Apr 24, 2026

Summary

The objc 0.2.7 crate's msg_send! / class! / sel_impl! macros emit #[cfg(feature = "cargo-clippy")] in their expansion. Because macros expand at the call site, the cfg lands in baseview's own compilation unit, where cargo's default --cap-lints=allow for registry dependencies does not apply. CI's RUSTFLAGS=-D warnings then promotes the resulting unexpected_cfgs lint to a hard error: 100+ identical errors per msg_send! site, breaking the macOS job.

Fix

Three lines in a new build.rs registering the cfg as expected:

fn main() {
    println!("cargo:rustc-check-cfg=cfg(feature, values(\"cargo-clippy\"))");
}

This tells rustc that feature = "cargo-clippy" is a valid cfg expectation in baseview's own translation unit, so the lint stops firing during baseview's compilation. Dependencies are unaffected.

Why this works (macro-expansion specifics)

Trace from a failing build, slightly trimmed:

Compiling objc v0.2.7 ... --cap-lints allow -D warnings
Compiling cocoa v0.24.1 ... --cap-lints allow -D warnings
Compiling baseview ... -D warnings
error: unexpected `cfg` condition value: `cargo-clippy`
    = note: this error originates in the macro `sel_impl` which comes from
      the expansion of the macro `msg_send` (in Nightly builds, run with
      -Z macro-backtrace for more info)

The error fires while compiling baseview, not objc. Cargo's --cap-lints=allow flag only applies to the dep's own translation unit; macros that the dep exports drag the offending cfg into the consumer's compilation, where --cap-lints doesn't help. cargo:rustc-check-cfg from baseview's build.rs registers the expected cfg specifically in baseview's lint pass, which is exactly where the warning lands.

Verified locally

On macOS 15 (Apple Silicon), stable Rust:

Command Without build.rs With build.rs
RUSTFLAGS="-D warnings" cargo build --workspace --all-targets 118 errors, fails exit 0
RUSTFLAGS="-D warnings" cargo build --workspace --all-targets --all-features fails exit 0
RUSTFLAGS="-D warnings" cargo test --workspace --all-targets --all-features --no-run fails exit 0
RUSTDOCFLAGS="-D warnings" cargo doc --examples --all-features --no-deps fails exit 0

Mirrors the failing CI workflow exactly.

Relation to the longer-term fixes

Pure CI unblock; does not address the root cause. The proper fixes (publish objc 0.2.8 with #SSheldon/rust-objc#125's merged fix, or migrate baseview to objc2) remain orthogonal to this PR and can be pursued on their own timelines. This is just to keep the macOS job green in the meantime so other PRs (e.g. #228) can merge.

The `objc` 0.2.7 crate emits `#[cfg(feature = "cargo-clippy")]`
inside the body of its `msg_send!` / `class!` / `sel_impl!`
macros. Because macros expand at the call site, the cfg lands in
baseview's own compilation unit (and any consumer's), where
`cargo`'s default `--cap-lints=allow` for registry dependencies
does not apply. CI's `RUSTFLAGS=-D warnings` then promotes the
resulting `unexpected_cfgs` lint to a hard error, breaking macOS
builds with 100+ identical errors per `msg_send!` site.

Register the cfg as expected via `cargo:rustc-check-cfg` from a
new `build.rs` so rustc no longer flags it during baseview's
lint pass. Verified locally: with the build script in place,
`RUSTFLAGS=-D warnings cargo build --workspace --all-targets
--all-features` (and the equivalent test / doc invocations) all
exit 0 on macOS; without it, the same commands fail with the
upstream errors.

Refs RustAudio#229.
@paravozz
Copy link
Copy Markdown
Author

Superseded by #232, which fixes the same lint failure at the source (full migration to objc2) instead of masking it via build.rs. #232 also folds in fixes for several latent @encode and NSException traps that this workaround alone wouldn't address. Happy to close this in favor of #232 once you've had a chance to look at it.

@micahrj
Copy link
Copy Markdown
Member

micahrj commented Apr 25, 2026

This is kind of a strange approach to fixing this. I would rather just silence the warning (#233).

@micahrj micahrj closed this Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants