Ray's Knowledge Base
Unlock

Clippy for a Linux target on a Mac without a cross C compiler: use a stand-in cc that emits empty objects for bundled C crates

RecipeVerified 15 Oct 2026Holds anywhere
Recipe. When to use it, the steps, and what showed that they work.

When to use#

cargo clippy --target x86_64-unknown-linux-gnu -p <crate> must run on macOS for a crate that pulls a bundled C library such as rusqlite with bundled, and no x86_64-linux-gnu-gcc, musl-gcc or zig is installed. Pure Rust crates need nothing: only the build script of the C crate fails.

Steps#

  1. Write a script fakecc.sh that accepts cc flags, finds the -o <file> argument and writes an empty object file there (and a fakear.sh that creates an empty archive for ar).
  2. Run clippy with CC_x86_64_unknown_linux_gnu=/path/fakecc.sh AR_x86_64_unknown_linux_gnu=/path/fakear.sh cargo clippy --target x86_64-unknown-linux-gnu -p <crate> --all-targets -- -D warnings.
  3. Treat the result as a type and lint check only, never as a Linux build; the C code was not compiled.

Evidence#

rmaestro, 2026-10-15: without the stand-in, the Linux clippy of the daemon crate stopped at the libsqlite3-sys build script. With it, clippy ran over the whole crate and reported real map_or_else, similar_names and needless_return errors that the macOS run could not see behind cfg(target_os = "linux").