Rust crates for developing Windows Drivers (WDM, KMDF, UMDF). The workspace only includes the library crates under crates/; examples and tests are excluded from the root workspace because each requires a different WDK configuration (only one WDK config per Cargo build graph is supported).
Crate layering (bottom → top):
wdk-build— Build-time crate. Configures cargo build scripts for WDK binding generation, linker settings, andcargo-maketask generation. Also contains therust-driver-makefile.tomlthat downstream driver packages extend.wdk-sys(no_std) — Raw FFI bindings auto-generated bybindgen, plus hand-written macro re-implementations where bindgen fails. Uses customcfgflags (driver_model__driver_type,driver_model__kmdf_version_major, etc.) set bywdk-buildto conditionally compile for WDM/KMDF/UMDF.wdk-macros— Proc-macro crate consumed only throughwdk-sysre-exports. Versioned in lockstep withwdk-sys(enforced by CIversion-checks.yaml).wdk— Safe idiomatic Rust wrappers aroundwdk-sys. Conditionallyno_stdfor WDM/KMDF; std-capable for UMDF.wdk-alloc— Global allocator (WdkAllocator) for kernel-mode crates needingalloc.wdk-panic— Default panic handlers for WDK binaries.cargo-wdk— Cargo subcommand for building and packaging driver projects.
Key design patterns:
- Conditional compilation via custom
cfgflags (not Cargo features) distinguishes driver types. These flags are emitted bywdk-buildduring the build script phase. wdk-syshas feature flags for optional WDK subsystem bindings:gpio,hid,spb,storage,usb,parallel-ports.- Some crates expose a
nightlyfeature for functionality gated behind unstable Rust features.
Requires an eWDK developer prompt and LLVM 17 on PATH for bindgen.
cargo build --locked --all-features# Full suite
cargo test --locked --all-features
# Single test
cargo test --locked --all-features <test_name>
# Nightly-only tests
cargo +nightly test --locked --features nightlycargo-expand v1.0.85 is required for macrotest/trybuild-based tests. Switching between stable/nightly toolchains requires deleting cached test artifacts under target/*/tests/ to avoid stale trybuild/macrotest caches.
# Clippy (warnings are denied via RUSTFLAGS=-Dwarnings)
cargo clippy --locked --all-features --all-targets -- -D warnings
# Formatting (requires nightly for unstable rustfmt options)
cargo +nightly fmt --all -- --check
# TOML formatting
taplo fmt --check --diff
# Cargo.toml dependency sorting
cargo sort -w -g -n --check
# Spelling
typos
# Security audit
cargo audit --deny warnings
# Unused dependencies
cargo machete --skip-target-dir
# Docs build
cargo doc --locked --all-featurescargo make wdk-pre-commit-flow- Unsafe discipline:
unsafe_op_in_unsafe_fnis forbidden at workspace level. Every unsafe block must have exactly one unsafe operation (multiple_unsafe_ops_per_block = "forbid") and a// SAFETY:comment (undocumented_unsafe_blocks = "forbid"). Unnecessary safety docs are also forbidden. - FFI naming: Bindings in
wdk-sysretain their original C names and style (e.g., PascalCase functions). Safe Rust wrappers inwdkfollow Rust naming conventions (RFC 430). - Formatting:
rustfmtuses nightly-only unstable options (seerustfmt.toml). Import grouping isStdExternalCrate, granularity isCrate. - Lints: Clippy
allis deny,pedantic/nursery/cargoare warn. Most workspace members inherit[lints] workspace = true;wdk-sys,wdk-build,wdk-macros, andcargo-wdkdefine their own[lints]tables instead (Cargo currently does not support both inheriting workspace lints and selectively overriding them per crate). - Edition: 2024, MSRV 1.91.0, resolver v3.
- Static CRT: Enabled globally via
.cargo/config.toml(-C target-feature=+crt-static). - Spelling:
typosis configured in.typos.toml; Windows API identifiers are allowlisted rather than using file-level excludes. - TOML:
taplouses CRLF line endings (seetaplo.toml). - Versioning:
wdk-macrosandwdk-sysmust have identical versions (exact=dependency). This is enforced by theversion-checks.yamlCI workflow.