Skip to content

cmake: lint the zephyr crate with a clippy_zephyr target - #3

Open
JPHutchins wants to merge 2 commits into
clippy/2-zephyr-lintfrom
clippy/3-clippy-zephyr-target
Open

JPHutchins wants to merge 2 commits into
clippy/2-zephyr-lintfrom
clippy/3-clippy-zephyr-target

Conversation

@JPHutchins

@JPHutchins JPHutchins commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Warning

LLM Disclosure

This post was authored by claude-opus-5-5 on behalf of @JPHutchins. JP asked to bring zephyr-lang-rust under strict clippy rules matching embassy's (default groups, -D warnings), to report deficiencies found along the way, and to open the work as a stacked series of review PRs on the intercreate fork.

Adds a clippy_zephyr CMake target that lints the zephyr crate itself, with the same Zephyr environment and flags as clippy. CI runs it for every sample and platform in the test plan. Before this, a deny-by-default lint (eq_op) planted in zephyr/src/lib.rs went unreported by west build -t clippy. The target is not part of ALL, so a new clippy release cannot break application builds.

The target lints with all features, so the PR first fixes an existing compile error. Async GPIO needs CONFIG_GPIO_ENABLE_DISABLE_INTERRUPT, an EXPERIMENTAL option that nothing declared. Any async-drivers build with CONFIG_GPIO=y but without that option failed with an unresolved import of ZR_GPIO_INT_MODE_DISABLE_ONLY.

Stack, merge in order:

  1. ci: run the build and docs workflows on pull requests to any branch #5: CI on pull requests to any branch
  2. zephyr-build, zephyr-macros: pass clippy -D warnings #1: host crates pass clippy
  3. zephyr: pass the module's clippy flags #2: the zephyr crate passes the module's clippy flags
  4. cmake: lint the zephyr crate with a clippy_zephyr target #3: clippy_zephyr target and CI (this PR)
  5. zephyr: fix unsafe contracts found while documenting unsafe code #4: unsafe-contract fixes
  6. zephyr: device: gpio: implement embedded-hal-async digital::Wait #6: embedded_hal_async::digital::Wait for GpioPin
Commits
Testing
  • west build -t clippy_zephyr passes at this PR's head on native_sim/native/64 with the maximal config, and with only CONFIG_GPIO=y added to hello_world. The second config fails without the gate commit.
  • The CI step runs on this PR through ci: run the build and docs workflows on pull requests to any branch #5, which lets CI trigger on pull requests to any branch.

Review notes

  • Cost: one more cargo clippy run per sample and platform in CI.
  • The module has no rust-toolchain.toml. With -D warnings, new clippy releases can add CI failures. A pin would only cover builds whose working directory is under the module, since cargo looks the file up from the app's directory.
  • Also noticed, not changed: async GPIO could disable with GPIO_INT_DISABLE instead of GPIO_INT_MODE_DISABLE_ONLY, because poll reconfigures the interrupt anyway. That would drop the experimental dependency, but needs hardware testing.

The async GPIO code disables a firing pin with
`ZR_GPIO_INT_MODE_DISABLE_ONLY`, which zephyr-sys defines only under
CONFIG_GPIO_ENABLE_DISABLE_INTERRUPT. That option is EXPERIMENTAL, and
nothing in the module Kconfig or the crate declares the dependency. Any
build with the `async-drivers` feature and CONFIG_GPIO=y but without
the option, such as a blocking-pool app on a board with GPIO enabled,
fails with "unresolved import `zephyr_sys::ZR_GPIO_INT_MODE_DISABLE_ONLY`".

Compile the async GPIO module only when both are set, and fall back to
the existing stub otherwise. Name the requirement next to the
`async-drivers` feature. Selecting an EXPERIMENTAL symbol from the module
Kconfig would force it on every Rust app.

Checked on native_sim/native/64 with only CONFIG_GPIO=y added, running
clippy with all features on the zephyr crate: without this change it
fails with the unresolved import, and with it, it passes.

Assisted-by: Claude:claude-opus-5-5
The `clippy` target lints only the application crate. The zephyr crate
reaches the build as a `[patch.crates-io]` path dependency, not a
workspace member, so cargo compiles it with rustc instead of
clippy-driver and none of the module's lint flags ever apply to it.
A deny-by-default lint (`eq_op`) planted in zephyr/src/lib.rs went
unreported by `west build -t clippy`.

Add `clippy_zephyr`, which runs clippy with the same Zephyr environment
on the zephyr crate's manifest, with all features and the same flags as
`clippy`. It is not part of ALL, so a new clippy release cannot break
application builds. CI runs it next to `clippy` for every sample and
platform in the test plan.

Verified with the zephyr crate passing on native_sim/native/64
(hello_world, a minimal config without RUST_ALLOC and LOG, and a
maximal config with GPIO, I2C, I2C target, flash, LED, LED strip and
the blocking pool), qemu_cortex_m3 and qemu_cortex_m0.

Assisted-by: Claude:claude-opus-5-5
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.

1 participant