### Install cargo-wdk Source: https://github.com/microsoft/windows-drivers-rs/blob/main/crates/cargo-wdk/README.md Install the cargo-wdk tool using cargo. ```pwsh cargo install cargo-wdk ``` -------------------------------- ### Install release-plz Source: https://github.com/microsoft/windows-drivers-rs/blob/main/RELEASE.md Installs the release-plz tool. Ensure you are using the latest version. ```bash cargo install --locked release-plz ``` -------------------------------- ### Install the Sample UMDF Rust Driver Source: https://github.com/microsoft/windows-drivers-rs/blob/main/examples/sample-umdf-driver/README.md Use pnputil to add and install the driver package on the target device. ```bash pnputil.exe /add-driver sample_umdf_driver.inf /install ``` -------------------------------- ### Build Sample WDM Rust Driver Source: https://github.com/microsoft/windows-drivers-rs/blob/main/examples/sample-wdm-driver/README.md Run this command in the project directory to build the driver. Ensure you have the WDK and LLVM installed. ```bash cargo make ``` -------------------------------- ### Install cargo-semver-checks Source: https://github.com/microsoft/windows-drivers-rs/blob/main/RELEASE.md Installs the cargo-semver-checks tool. Ensure you are using the latest version. ```bash cargo install --locked cargo-semver-checks ``` -------------------------------- ### Install taplo-cli Source: https://github.com/microsoft/windows-drivers-rs/blob/main/CONTRIBUTING.md Install the taplo-cli tool for TOML file management, directly from its Git repository. ```shell cargo install --git https://github.com/tamasfe/taplo --rev b673b44d taplo-cli --locked --force ``` -------------------------------- ### Install cargo-expand Source: https://github.com/microsoft/windows-drivers-rs/blob/main/CONTRIBUTING.md Install the cargo-expand tool, used for expanding Rust macros. ```shell cargo install --locked cargo-expand --version 1.0.85 ``` -------------------------------- ### Install Driver using Pnputil Source: https://github.com/microsoft/windows-drivers-rs/blob/main/examples/sample-wdm-driver/README.md Use this command to add and install the driver package on the target machine. The path to the .inf file should be adjusted based on your build output. ```bash pnputil.exe /add-driver sample_wdm_driver.inf /install ``` -------------------------------- ### Install typos-cli Source: https://github.com/microsoft/windows-drivers-rs/blob/main/CONTRIBUTING.md Install the typos-cli tool for spell checking in code. ```shell cargo install --locked typos-cli ``` -------------------------------- ### Install cargo-machete Source: https://github.com/microsoft/windows-drivers-rs/blob/main/CONTRIBUTING.md Install the cargo-machete tool, which helps manage Rust dependencies. ```shell cargo install --locked cargo-machete ``` -------------------------------- ### Install KMDF Driver Source: https://github.com/microsoft/windows-drivers-rs/blob/main/examples/sample-kmdf-driver/README.md Use pnputil to add and install the driver package. This command is run from the driver's package directory. ```bash pnputil.exe /add-driver sample_kmdf_driver.inf /install ``` -------------------------------- ### Install cargo-audit Source: https://github.com/microsoft/windows-drivers-rs/blob/main/CONTRIBUTING.md Install the cargo-audit tool, which helps audit Rust dependencies for security vulnerabilities. ```shell cargo install --locked cargo-audit ``` -------------------------------- ### Enable Driver Package Signature Verification Source: https://github.com/microsoft/windows-drivers-rs/blob/main/README.md Set the `WDK_BUILD_ENABLE_SIGNTOOL_VERIFY` environment variable to `true` to enable signature verification tasks for `.sys` and `.cat` files. This requires the signing certificate to be installed in 'Trusted Root Certification Authorities'. ```bash cargo make --env WDK_BUILD_ENABLE_SIGNTOOL_VERIFY=true ``` -------------------------------- ### Test Nightly Features Source: https://github.com/microsoft/windows-drivers-rs/blob/main/CONTRIBUTING.md Runs tests specifically for features that require a nightly Rust toolchain. Ensure you have the nightly toolchain installed. ```bash cargo +nightly test --locked --features nightly ``` -------------------------------- ### Build and Package Samples Source: https://github.com/microsoft/windows-drivers-rs/blob/main/CONTRIBUTING.md Builds and packages samples within a specific driver crate. Navigate to the crate directory first. ```bash cargo make --cwd .\crates\ ``` -------------------------------- ### Generate and Open Documentation Source: https://github.com/microsoft/windows-drivers-rs/blob/main/CONTRIBUTING.md Compiles and opens the project's documentation in a web browser. Use the --target flag to generate docs for a non-host architecture, but note its incompatibility with proc-macro crates. ```bash cargo doc --locked --all-features --open ``` ```bash cargo doc --locked --all-features --open --target --workspace --exclude wdk-macros ``` -------------------------------- ### Build for Release Source: https://github.com/microsoft/windows-drivers-rs/blob/main/README.md Build the project for a release profile. You can use either `--release` or `--profile release`. ```bash cargo make default --release ``` ```bash cargo make default --profile release ``` -------------------------------- ### Build Driver with Default Options Source: https://github.com/microsoft/windows-drivers-rs/blob/main/crates/cargo-wdk/README.md Use this command to build a driver project with the default build configuration. Ensure you are in the project's root directory. ```pwsh cargo wdk build ``` -------------------------------- ### Configure WDK Binary Build Source: https://github.com/microsoft/windows-drivers-rs/blob/main/README.md Create a `build.rs` file and use `wdk_build::configure_wdk_binary_build()` to configure the build for a WDK binary. This function handles necessary build configurations for Windows drivers. ```rust fn main() -> Result<(), wdk_build::ConfigError> { wdk_build::configure_wdk_binary_build() } ``` -------------------------------- ### Build Driver for ARM64 in Release Profile Source: https://github.com/microsoft/windows-drivers-rs/blob/main/crates/cargo-wdk/README.md Build a driver project targeting `arm64` architecture with the `release` profile. Navigate to the project root before running. ```pwsh cargo wdk build --target-arch arm64 --profile release ``` -------------------------------- ### Build with Specific Features Source: https://github.com/microsoft/windows-drivers-rs/blob/main/README.md Specify features to include during the build process. Replace `` with a comma-separated list of features. ```bash cargo make default --features ``` -------------------------------- ### Display Cargo Make Help Source: https://github.com/microsoft/windows-drivers-rs/blob/main/README.md View the help message for cargo-make to see all supported command-line arguments that can be forwarded to Cargo. ```bash cargo make help ``` -------------------------------- ### Configure Makefile.toml for Driver Build Source: https://github.com/microsoft/windows-drivers-rs/blob/main/README.md Set up `Makefile.toml` to extend the default `target/rust-driver-makefile.toml` and load the Rust driver makefile using `wdk_build::cargo_make::load_rust_driver_makefile()`. ```toml extend = "target/rust-driver-makefile.toml" [config] load_script = ''' #!@rust //! ```cargo //! [dependencies] //! wdk-build = "0.5.1" //! ``` #![allow(unused_doc_comments)] wdk_build::cargo_make::load_rust_driver_makefile()? ''' ``` -------------------------------- ### Create a new KMDF driver project Source: https://github.com/microsoft/windows-drivers-rs/blob/main/crates/cargo-wdk/README.md Use the 'new' command to create a new KMDF driver project in the current directory. ```pwsh cargo wdk new my_driver --kmdf ``` -------------------------------- ### Create a new UMDF driver project in a specific directory Source: https://github.com/microsoft/windows-drivers-rs/blob/main/crates/cargo-wdk/README.md Use the 'new' command to create a new UMDF driver project in a specified sub-directory. ```pwsh cargo wdk new my_projects\my_driver --umdf ``` -------------------------------- ### Build Workspace Project for AMD64 Source: https://github.com/microsoft/windows-drivers-rs/blob/main/crates/cargo-wdk/README.md Build projects within a workspace for the `amd64` target architecture. Execute this command from the workspace root. ```pwsh cargo wdk build --target-arch amd64 ``` -------------------------------- ### Build Documentation with Cargo Source: https://github.com/microsoft/windows-drivers-rs/blob/main/AGENTS.md Generate project documentation using Cargo. This command builds all documentation for the project, including all features. ```shell cargo doc --locked --all-features ``` -------------------------------- ### Create a Software Device for the Driver Source: https://github.com/microsoft/windows-drivers-rs/blob/main/examples/sample-umdf-driver/README.md Use devgen.exe to add a software device with the specified hardware ID for the UMDF driver. ```bash devgen.exe /add /hardwareid "root\SAMPLE_UMDF_HW_ID" ``` -------------------------------- ### Configure DebugView for Kernel Output Source: https://github.com/microsoft/windows-drivers-rs/blob/main/examples/sample-kmdf-driver/README.md Steps to configure DebugView for capturing kernel output. Ensure 'Capture Kernel' and 'Enable Verbose Kernel Output' are enabled. ```text 1. Enable `Capture Kernel` 2. Enable `Enable Verbose Kernel Output` ``` -------------------------------- ### Create New Cargo Driver Project Source: https://github.com/microsoft/windows-drivers-rs/blob/main/README.md Use this command to create a new Rust project with a library crate for your driver. ```pwsh cargo new --lib ``` -------------------------------- ### Build for a Specific Target Source: https://github.com/microsoft/windows-drivers-rs/blob/main/README.md Use this command to build the project for a specific target triple. Replace `` with the desired target. ```bash cargo make default --target ``` -------------------------------- ### Build with a Specific Rust Toolchain Source: https://github.com/microsoft/windows-drivers-rs/blob/main/README.md Use this command to specify a particular Rust toolchain for the build. Replace `` with the desired toolchain name. ```bash cargo make default + ``` -------------------------------- ### Execute Default Cargo Make Task Source: https://github.com/microsoft/windows-drivers-rs/blob/main/README.md Run the default task in `cargo-make`, which typically builds and packages the driver. `cargo make` is a shorthand for `cargo make default`. ```pwsh cargo make default ``` -------------------------------- ### Create Software Device Source: https://github.com/microsoft/windows-drivers-rs/blob/main/examples/sample-kmdf-driver/README.md Use devgen.exe to create a software device for the KMDF driver. This command requires the hardware ID of the driver. ```bash devgen.exe /add /hardwareid "root\SAMPLE_KMDF_HW_ID" ``` -------------------------------- ### Create Release Pull Request Source: https://github.com/microsoft/windows-drivers-rs/blob/main/RELEASE.md Initiates a release pull request using release-plz. Replace with your actual GitHub token. ```bash release-plz release-pr --git-token ``` -------------------------------- ### Build Windows Drivers with Cargo Source: https://github.com/microsoft/windows-drivers-rs/blob/main/AGENTS.md Use this command to build all features of the driver project. Ensure the --locked flag is used for reproducible builds. ```shell cargo build --locked --all-features ``` -------------------------------- ### Configure WinDbg for Kernel Output Source: https://github.com/microsoft/windows-drivers-rs/blob/main/examples/sample-kmdf-driver/README.md Steps to configure an active WinDbg session for kernel output. This involves setting the default mask to capture all output. ```text 1. Attach WinDBG 2. `ed nt!Kd_DEFAULT_Mask 0xFFFFFFFF` ``` -------------------------------- ### Run All Tests Source: https://github.com/microsoft/windows-drivers-rs/blob/main/CONTRIBUTING.md Executes all tests in the workspace, ensuring functional correctness. Includes locked dependencies and all features. ```bash cargo test --locked --all-features ``` -------------------------------- ### Add windows-drivers-rs Dependencies Source: https://github.com/microsoft/windows-drivers-rs/blob/main/README.md Add the necessary windows-drivers-rs crates to your project's dependencies. The `--build` flag is used for `wdk-build` as it's a build-time dependency. ```pwsh cd cargo add --build wdk-build cargo add wdk wdk-sys wdk-alloc wdk-panic ``` -------------------------------- ### Execute Release Source: https://github.com/microsoft/windows-drivers-rs/blob/main/RELEASE.md Executes the release process, publishing crates to crates.io and creating draft releases on GitHub. ```bash release-plz release ``` -------------------------------- ### Build Driver with Signing Disabled Source: https://github.com/microsoft/windows-drivers-rs/blob/main/crates/cargo-wdk/README.md Build a driver project with the signing mode set to `off`. This is useful for development or testing scenarios where signing is not required. Run from the project root. ```pwsh cargo wdk build --sign-mode off ``` -------------------------------- ### Run Pre-commit Flow Source: https://github.com/microsoft/windows-drivers-rs/blob/main/AGENTS.md Execute the pre-commit hook flow using cargo-make. This command runs all necessary checks and formatting before committing code. ```shell cargo make wdk-pre-commit-flow ``` -------------------------------- ### Enable DebugView for Driver Output Source: https://github.com/microsoft/windows-drivers-rs/blob/main/examples/sample-umdf-driver/README.md Configure DebugView to capture global Win32 events and system events for driver output. ```text 1. Enable `Capture Global Win32` 2. Enable `Capture Events` ``` -------------------------------- ### Apply TOML Formatting Source: https://github.com/microsoft/windows-drivers-rs/blob/main/CONTRIBUTING.md Automatically resolves formatting inconsistencies in TOML files and sorts dependencies. ```bash taplo fmt ``` -------------------------------- ### Apply Rust Formatting Source: https://github.com/microsoft/windows-drivers-rs/blob/main/CONTRIBUTING.md Automatically resolves formatting inconsistencies in Rust source files. Uses nightly Rustfmt. ```bash cargo +nightly fmt --all ``` -------------------------------- ### Add Software Device using Devgen Source: https://github.com/microsoft/windows-drivers-rs/blob/main/examples/sample-wdm-driver/README.md This command adds a software device with a specific hardware ID. Ensure `devgen.exe` is in your PATH or specify its full path. ```bash devgen.exe /add /hardwareid "root\SAMPLE_WDM_HW_ID" ``` -------------------------------- ### Configure Crate Type in Cargo.toml Source: https://github.com/microsoft/windows-drivers-rs/blob/main/README.md Set the crate type to `cdylib` in your `Cargo.toml` file. This is required for creating dynamic libraries, which Windows drivers are. ```toml [lib] crate-type = ["cdylib"] ``` -------------------------------- ### Configure DebugView for Kernel Output Source: https://github.com/microsoft/windows-drivers-rs/blob/main/examples/sample-wdm-driver/README.md Enable kernel capture and verbose kernel output in DebugView to see driver prints. This is useful for debugging. ```text Enable Verbose Kernel Output ``` -------------------------------- ### Lint Rust Code with Clippy Source: https://github.com/microsoft/windows-drivers-rs/blob/main/AGENTS.md Run Clippy with all features enabled and deny warnings to enforce code quality standards. This command checks all targets. ```shell cargo clippy --locked --all-features --all-targets -- -D warnings ``` -------------------------------- ### Configure Windbg for Kernel Mode Debugging Source: https://github.com/microsoft/windows-drivers-rs/blob/main/examples/sample-umdf-driver/README.md Set the Kd_DEFAULT_Mask to capture all kernel debugging information. ```text `ed nt!Kd_DEFAULT_Mask 0xFFFFFFFF` ``` -------------------------------- ### UMDF Driver Configuration in Cargo.toml Source: https://github.com/microsoft/windows-drivers-rs/blob/main/README.md Configure the WDK driver metadata for a UMDF driver, specifying the driver type and target UMDF version. ```toml [package.metadata.wdk.driver-model] driver-type = "UMDF" umdf-version-major = 1 target-umdf-version-minor = 33 ``` -------------------------------- ### Enable Static CRT Linkage Source: https://github.com/microsoft/windows-drivers-rs/blob/main/README.md Configure static CRT linkage by adding `-C target-feature=+crt-static` to `rustflags` in `.cargo/config.toml`. This ensures the driver is linked against the static C runtime. ```toml [build] rustflags = ["-C", "target-feature=+crt-static"] ``` -------------------------------- ### Identify Unused Dependencies Source: https://github.com/microsoft/windows-drivers-rs/blob/main/AGENTS.md Use cargo-machete to identify and report unused dependencies in the project. This helps in maintaining a lean dependency graph. ```shell cargo machete --skip-target-dir ``` -------------------------------- ### Configure WinDbg for Kernel Debugging Source: https://github.com/microsoft/windows-drivers-rs/blob/main/examples/sample-wdm-driver/README.md Attach WinDbg to your system and set the kernel debug mask to capture all output. This allows for real-time debugging of the driver. ```text ed nt!Kd_DEFAULT_Mask 0xFFFFFFFF ``` -------------------------------- ### Test Windows Drivers with Cargo Source: https://github.com/microsoft/windows-drivers-rs/blob/main/AGENTS.md Execute the full test suite for the driver project. For specific tests, append the test name. Nightly-only tests require the +nightly toolchain. ```shell cargo test --locked --all-features # Single test cargo test --locked --all-features # Nightly-only tests cargo +nightly test --locked --features nightly ``` -------------------------------- ### Set Panic Strategy for Kernel Mode Crates Source: https://github.com/microsoft/windows-drivers-rs/blob/main/README.md For kernel mode drivers (KMDF, WDM), set the panic strategy to `abort` in both development and release profiles within `Cargo.toml`. This prevents the driver from crashing the entire system on a panic. ```toml [profile.dev] panic = "abort" [profile.release] panic = "abort" ``` -------------------------------- ### Add Kernel Mode Panic Handler Source: https://github.com/microsoft/windows-drivers-rs/blob/main/README.md Include the `wdk_panic` crate as a panic handler for kernel mode drivers. This ensures that panics are handled gracefully within the kernel environment. ```rust #[cfg(not(test))] extern crate wdk_panic; ``` -------------------------------- ### Lint Nightly Features with Clippy Source: https://github.com/microsoft/windows-drivers-rs/blob/main/CONTRIBUTING.md Applies Clippy linting to nightly features, treating warnings as errors. Requires the nightly toolchain. ```bash cargo +nightly clippy --locked --all-features --all-targets --features nightly -- -D warnings ``` -------------------------------- ### Sort Cargo.toml Dependencies Source: https://github.com/microsoft/windows-drivers-rs/blob/main/AGENTS.md Sort dependencies in Cargo.toml files alphabetically and by group. The --check flag ensures no changes are made if sorting is already correct. ```shell cargo sort -w -g -n --check ``` -------------------------------- ### Format TOML Files with Taplo Source: https://github.com/microsoft/windows-drivers-rs/blob/main/AGENTS.md Check TOML file formatting using Taplo. This command ensures consistency in configuration files. ```shell taplo fmt --check --diff ``` -------------------------------- ### Format Rust Code with Rustfmt Source: https://github.com/microsoft/windows-drivers-rs/blob/main/AGENTS.md Check Rust code formatting using nightly Rustfmt. This command ensures code adheres to project formatting standards. ```shell cargo +nightly fmt --all -- --check ``` -------------------------------- ### Define DriverEntry Point Source: https://github.com/microsoft/windows-drivers-rs/blob/main/README.md Implement the `DriverEntry` function in `lib.rs`, which is the required entry point for Windows drivers. The `#[unsafe(export_name = "DriverEntry")]` attribute ensures the correct symbol name is exported. ```rust use wdk_sys::{ PDRIVER_OBJECT, NTSTATUS, PCUNICODE_STRING, }; // SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points. // No other function in this compilation unit exports this name, preventing symbol conflicts. #[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry pub unsafe extern "system" fn driver_entry( driver: PDRIVER_OBJECT, registry_path: PCUNICODE_STRING, ) -> NTSTATUS { 0 } ``` -------------------------------- ### Perform Security Audit with Cargo Audit Source: https://github.com/microsoft/windows-drivers-rs/blob/main/AGENTS.md Run a security audit on project dependencies using cargo-audit. Deny warnings to ensure all security advisories are addressed. ```shell cargo audit --deny warnings ``` -------------------------------- ### Manually Set Version Source: https://github.com/microsoft/windows-drivers-rs/blob/main/RELEASE.md Manually overrides the version determined by release-plz. This updates package versions and changelogs, but may require manual editing of the PR description. ```bash release-plz set-version ``` -------------------------------- ### Rebase and Force Push for PR Updates Source: https://github.com/microsoft/windows-drivers-rs/blob/main/CONTRIBUTING.md Use this command sequence to rebase your local branch onto the main branch and force push the changes to update your pull request. ```shell git rebase master -i git push -f ``` -------------------------------- ### Add Optional Global Allocator for Kernel Mode Source: https://github.com/microsoft/windows-drivers-rs/blob/main/README.md Optionally, add `WdkAllocator` as the global allocator in `lib.rs` for kernel mode drivers. This is required if you intend to use `alloc` modules from the Rust standard library. ```rust #[cfg(not(test))] use wdk_alloc::WdkAllocator; #[cfg(not(test))] #[global_allocator] static GLOBAL_ALLOCATOR: WdkAllocator = WdkAllocator; ``` -------------------------------- ### Check for Typos in Code Source: https://github.com/microsoft/windows-drivers-rs/blob/main/AGENTS.md Use the typos tool to check for spelling errors in the codebase. This helps maintain code quality and prevent typos. ```shell typos ``` -------------------------------- ### Forward Arguments with Cargo Make Source: https://github.com/microsoft/windows-drivers-rs/blob/main/README.md Forward arguments to underlying `cargo` commands by specifying them after the `cargo-make` task name. Omitting the task name for the `default` task does not support argument forwarding. ```pwsh # Example: cargo make -- ``` -------------------------------- ### Dry Run Release Source: https://github.com/microsoft/windows-drivers-rs/blob/main/RELEASE.md Performs a dry run of the release process to verify it will be successful before merging the pull request. ```bash release-plz release --dry-run ``` -------------------------------- ### Mark Kernel Mode Crates as no_std Source: https://github.com/microsoft/windows-drivers-rs/blob/main/README.md For kernel mode drivers, mark the crate as `no_std` in `lib.rs`. This indicates that the crate does not rely on the standard library, which is typical for kernel environments. ```rust #![no_std] ``` -------------------------------- ### Auto-fix Spelling Errors Source: https://github.com/microsoft/windows-drivers-rs/blob/main/CONTRIBUTING.md Automatically corrects spelling errors found by typos-cli locally before committing. ```bash typos --write-changes ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.