From 4208234ae22cf969659c5fd15181b7b781ba611f Mon Sep 17 00:00:00 2001 From: Melvin Wang Date: Mon, 8 Apr 2024 10:28:33 -0700 Subject: [PATCH] Fix fork main (#25) * refactor: add lint exceptions for clippy::manual_c_str_literals and clippy::ref_as_ptr (#108) * ci: fix various pipeline breakages (nightly rustfmt bug, new nightly clippy lints, upstream winget dependency issue) (#117) * docs: fix `winget` llvm install command option (#115) Signed-off-by: Nicholas Rishel Co-authored-by: Melvin Wang * fix!: prevent linking of wdk libraries in tests that depend on `wdk-sys` (#118) * refactor: change version bounds for `manual_c_str_literals` and `ref_as_ptr` clippy lints (#127) Signed-off-by: Melvin Wang * Revert "Fix wdk sys ci tests (#23)" This reverts commit 165f26abb36d6dde160465ef2c7576127f0760dc. --------- Signed-off-by: Nicholas Rishel Signed-off-by: Melvin Wang Co-authored-by: Nicholas Rishel --- .github/actions/winget-install/action.yml | 6 ++--- .github/workflows/code-formatting-check.yaml | 6 +++-- .github/workflows/test.yaml | 2 +- CONTRIBUTING.md | 2 +- Makefile.toml | 3 +++ README.md | 4 ++-- crates/wdk-build/rust-driver-makefile.toml | 2 +- crates/wdk-build/src/bindgen.rs | 2 +- crates/wdk-build/src/cargo_make.rs | 2 +- crates/wdk-build/src/lib.rs | 23 +++++++++++++------ crates/wdk-build/src/utils.rs | 2 -- .../wdf_driver_create_wrong_arg_order.rs | 2 +- .../wdf_driver_create_wrong_arg_order.stderr | 4 ++-- .../wdf_driver_create_wrong_arg_order.rs | 2 +- .../wdf_driver_create_wrong_arg_order.stderr | 4 ++-- crates/wdk-sys/src/constants.rs | 3 ++- crates/wdk-sys/src/test_stubs.rs | 2 +- crates/wdk-sys/src/types.rs | 2 +- 18 files changed, 43 insertions(+), 30 deletions(-) diff --git a/.github/actions/winget-install/action.yml b/.github/actions/winget-install/action.yml index 9d50b052..0fc349c0 100644 --- a/.github/actions/winget-install/action.yml +++ b/.github/actions/winget-install/action.yml @@ -28,7 +28,7 @@ runs: shell: pwsh run: | New-Item -Type Directory $env:RUNNER_TEMP/winget-install - Invoke-WebRequest -Headers $AuthenticatedHeaders -Uri https://github.com/microsoft/microsoft-ui-xaml/releases/download/v2.7.3/Microsoft.UI.Xaml.2.7.x64.appx -OutFile $env:RUNNER_TEMP/winget-install/Microsoft.UI.Xaml.2.7.x64.appx + Invoke-WebRequest -Headers $AuthenticatedHeaders -Uri https://github.com/microsoft/microsoft-ui-xaml/releases/download/v2.8.6/Microsoft.UI.Xaml.2.8.x64.appx -OutFile $env:RUNNER_TEMP/winget-install/Microsoft.UI.Xaml.2.8.x64.appx Invoke-WebRequest -Uri https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx -OutFile $env:RUNNER_TEMP/winget-install/Microsoft.VCLibs.x64.14.00.Desktop.appx # Needed per https://github.com/microsoft/winget-cli/blob/21de1607ed5c90174e6bb931406975c18681a5dd/README.md?plain=1#L35C19-L35C19 Invoke-WebRequest -Headers $AuthenticatedHeaders -Uri $env:LatestWingetDownloadUri -OutFile $env:RUNNER_TEMP/winget-install/winget.msixbundle Invoke-WebRequest -Headers $AuthenticatedHeaders -Uri $env:LatestWingetLicenseDownloadUri -OutFile $env:RUNNER_TEMP/winget-install/license.xml @@ -36,12 +36,12 @@ runs: - name: Start Winget Installation shell: pwsh run: | - Add-AppxProvisionedPackage -Online -PackagePath $env:RUNNER_TEMP/winget-install/winget.msixbundle -LicensePath $env:RUNNER_TEMP/winget-install/license.xml -DependencyPackagePath $env:RUNNER_TEMP/winget-install/Microsoft.UI.Xaml.2.7.x64.appx, $env:RUNNER_TEMP/winget-install/Microsoft.VCLibs.x64.14.00.Desktop.appx + Add-AppxProvisionedPackage -Online -PackagePath $env:RUNNER_TEMP/winget-install/winget.msixbundle -LicensePath $env:RUNNER_TEMP/winget-install/license.xml -DependencyPackagePath $env:RUNNER_TEMP/winget-install/Microsoft.UI.Xaml.2.8.x64.appx, $env:RUNNER_TEMP/winget-install/Microsoft.VCLibs.x64.14.00.Desktop.appx - name: Wait for Completion of Winget Installation shell: pwsh run: | - while ((Get-Command * | Select-String winget).ToString() -ne "winget.exe") { + while ((Get-Command * | Select-String winget)?.ToString() -ne "winget.exe") { Start-Sleep -Seconds 1 } Write-Output "Winget Version: $(winget --version)" diff --git a/.github/workflows/code-formatting-check.yaml b/.github/workflows/code-formatting-check.yaml index fe4ff92d..8deb8cd5 100644 --- a/.github/workflows/code-formatting-check.yaml +++ b/.github/workflows/code-formatting-check.yaml @@ -17,12 +17,14 @@ jobs: uses: actions/checkout@v4 - name: Install Rust Toolchain (Nightly) - uses: dtolnay/rust-toolchain@nightly + # Need to temporarily pin nightly used for fmt because of upstream bug: https://github.com/rust-lang/rustfmt/issues/6082, https://github.com/rust-lang/rustfmt/issues/6099 + uses: dtolnay/rust-toolchain@master with: + toolchain: nightly-2024-02-17 components: rustfmt - name: Run Cargo Format - run: cargo +nightly fmt --all -- --check + run: cargo +nightly-2024-02-17 fmt --all -- --check taplo-fmt: name: .toml Formatting Check diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 72b5e9fa..8e9074b4 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -53,7 +53,7 @@ jobs: - name: Install Cargo Expand uses: taiki-e/install-action@v2 with: - tool: cargo-expand + tool: cargo-expand@1.0.80 - name: Run Cargo Test run: cargo +${{ matrix.rust_toolchain }} test --locked --profile ${{ matrix.cargo_profile }} --target ${{ matrix.target_triple }} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a3b8e187..a8eb0812 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -87,7 +87,7 @@ That's it! Thank you for your contribution! The following tools should be installed as a part of the `windows-drivers-rs` developer workflow: -* `cargo-expand`: `cargo install --locked cargo-expand` +* `cargo-expand`: `cargo install --locked cargo-expand --version 1.0.80` * `cargo-audit`: `cargo install --locked cargo-audit` * `cargo-udeps`: `cargo install --locked cargo-udeps` * `taplo-cli`: `cargo install --locked taplo-cli` diff --git a/Makefile.toml b/Makefile.toml index cc063b2e..7fcae1b2 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -42,6 +42,9 @@ success = rm -r ${CARGO_MAKE_CRATE_CUSTOM_TRIPLE_TARGET_DIRECTORY}/tests assert ${success} "Failed to delete tests directory" ''' +[tasks.test] +install_crate = { crate_name = "cargo-expand", version = "1.0.80" } + [tasks.audit] args = ["audit", "--deny", "warnings"] diff --git a/README.md b/README.md index e329644f..8f7a6c45 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ This project was built with support of WDM, KMDF, and UMDF drivers in mind, as w ### Build Requirements * Binding generation via `bindgen` requires `libclang`. The easiest way to acquire this is via `winget` - * `winget -i install LLVM.LLVM` + * `winget install -i LLVM.LLVM` * Ensure you select the GUI option to add LLVM to the PATH * To execute post-build tasks (ie. `inf2cat`, `infverif`, etc.), `cargo make` is used * `cargo install --locked cargo-make --no-default-features --features tls-native` @@ -168,7 +168,7 @@ When executing the default task, just `cargo make` make also works since the `de ### Argument Forwarding -`windows-drivers-rs` extends `cargo make` to forward specific arguements to the underlying `cargo` commands. In order to specify arguments to forward, they must be provided **after explicitly specifying the `cargo-make` task name** (ie. omitting the name for the `default` task is not supported). +`windows-drivers-rs` extends `cargo make` to forward specific arguments to the underlying `cargo` commands. In order to specify arguments to forward, they must be provided **after explicitly specifying the `cargo-make` task name** (ie. omitting the name for the `default` task is not supported). #### Examples diff --git a/crates/wdk-build/rust-driver-makefile.toml b/crates/wdk-build/rust-driver-makefile.toml index 5af9dd98..253f7e26 100644 --- a/crates/wdk-build/rust-driver-makefile.toml +++ b/crates/wdk-build/rust-driver-makefile.toml @@ -1,6 +1,6 @@ # This file can be leveraged to build downstream drivers. See examples at https://github.com/microsoft/Windows-rust-drivers-samples -# FIXME: this flow is based on the signing process of a KMDF PNP driver. There should be different flows availabe for different types of drivers as outlined in https://learn.microsoft.com/en-us/windows-hardware/drivers/install/test-signing-driver-packages +# FIXME: this flow is based on the signing process of a KMDF PNP driver. There should be different flows available for different types of drivers as outlined in https://learn.microsoft.com/en-us/windows-hardware/drivers/install/test-signing-driver-packages [config] min_version = "0.37.8" init_task = "wdk-build-init" diff --git a/crates/wdk-build/src/bindgen.rs b/crates/wdk-build/src/bindgen.rs index ba0c7c3b..51aae94b 100644 --- a/crates/wdk-build/src/bindgen.rs +++ b/crates/wdk-build/src/bindgen.rs @@ -112,7 +112,7 @@ impl BuilderExt for Builder { // -WDeprecated warning .clang_arg("--warn-=no-deprecated-declarations") // Windows SDK & DDK contain unnecessary token pasting (ex. &##_variable: `&` and - // `_variable` are seperate tokens already, and don't need `##` to concatenate them) + // `_variable` are separate tokens already, and don't need `##` to concatenate them) .clang_arg("--warn-=no-invalid-token-paste") .clang_arg("-fms-extensions") .blocklist_item("ExAllocatePoolWithTag") // Deprecated diff --git a/crates/wdk-build/src/cargo_make.rs b/crates/wdk-build/src/cargo_make.rs index 00ab4bd3..c2846d5d 100644 --- a/crates/wdk-build/src/cargo_make.rs +++ b/crates/wdk-build/src/cargo_make.rs @@ -694,7 +694,7 @@ where fn forward_env_var_to_cargo_make>(env_var_name: S) { let env_var_name = env_var_name.as_ref(); - // Since this executes in a child proccess to cargo-make, we need to forward the + // Since this executes in a child process to cargo-make, we need to forward the // values we want to change to duckscript, in order to get it to modify the // parent process (ie. cargo-make) if let Some(env_var_value) = std::env::var_os(env_var_name) { diff --git a/crates/wdk-build/src/lib.rs b/crates/wdk-build/src/lib.rs index fb5e60d8..5d9b2438 100644 --- a/crates/wdk-build/src/lib.rs +++ b/crates/wdk-build/src/lib.rs @@ -5,7 +5,7 @@ //! configure any build that depends on the WDK (Windows Driver Kit). This is //! especially useful for crates that generate FFI bindings to the WDK, //! WDK-dependent libraries, and programs built on top of the WDK (ex. Drivers). -//! This library is built to be able to accomodate different WDK releases, as +//! This library is built to be able to accommodate different WDK releases, as //! well strives to allow for all the configuration the WDK allows. This //! includes being ables to select different WDF versions and different driver //! models (WDM, KMDF, UMDF). @@ -47,8 +47,8 @@ use utils::PathExt; /// Configuration parameters for a build dependent on the WDK #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct Config { - /// Path to root of WDK. Corresponds with WDKContentRoot environment - /// varialbe in eWDK + /// Path to root of WDK. Corresponds with `WDKContentRoot` environment + /// variable in eWDK pub wdk_content_root: PathBuf, /// Build configuration of driver pub driver_config: DriverConfig, @@ -108,7 +108,7 @@ pub struct UMDFConfig { /// Errors that could result from configuring a build via [`wdk-build`] #[derive(Debug, Error)] pub enum ConfigError { - /// Error returned when an std::io operation fails + /// Error returned when an [`std::io`] operation fails #[error(transparent)] IoError(#[from] std::io::Error), @@ -139,7 +139,7 @@ pub enum ConfigError { )] WDKContentRootDetectionError, - /// Error returned when cargo_metadata execution or parsing fails + /// Error returned when `cargo_metadata` execution or parsing fails #[error(transparent)] CargoMetadataError(#[from] cargo_metadata::Error), @@ -198,7 +198,7 @@ pub enum ExportError { /// Error returned when the crate being compiled does not have a `links` /// value in its Cargo.toml #[error( - "Missing `links` value in crate's config.toml. Metadata is unable to propogate to \ + "Missing `links` value in crate's config.toml. Metadata is unable to propagate to \ dependencies without a `links` value" )] MissingLinksValue(#[from] std::env::VarError), @@ -562,9 +562,18 @@ impl Config { /// /// This consists mainly of linker setting configuration. This must be /// called from a Cargo build script of the binary being built + /// + /// # Errors + /// + /// This function will return an error if any of the required paths do not + /// exist. + /// + /// # Panics + /// + /// Panics if the invoked from outside a Cargo build environmen pub fn configure_binary_build(&self) -> Result<(), ConfigError> { self.configure_library_build()?; - + // Linker arguments derived from Microsoft.Link.Common.props in Ni(22H2) WDK println!("cargo:rustc-cdylib-link-arg=/NXCOMPAT"); println!("cargo:rustc-cdylib-link-arg=/DYNAMICBASE"); diff --git a/crates/wdk-build/src/utils.rs b/crates/wdk-build/src/utils.rs index 1ffd6e64..bc9a3150 100644 --- a/crates/wdk-build/src/utils.rs +++ b/crates/wdk-build/src/utils.rs @@ -283,8 +283,6 @@ pub fn detect_cpu_architecture_in_build_script() -> CPUArchitecture { #[cfg(test)] mod tests { - use std::path::PathBuf; - use windows::Win32::UI::Shell::{FOLDERID_ProgramFiles, SHGetKnownFolderPath, KF_FLAG_DEFAULT}; use super::*; diff --git a/crates/wdk-macros/tests/nightly/trybuild/wdf_driver_create_wrong_arg_order.rs b/crates/wdk-macros/tests/nightly/trybuild/wdf_driver_create_wrong_arg_order.rs index 31a876d9..d0fa8b79 100644 --- a/crates/wdk-macros/tests/nightly/trybuild/wdf_driver_create_wrong_arg_order.rs +++ b/crates/wdk-macros/tests/nightly/trybuild/wdf_driver_create_wrong_arg_order.rs @@ -21,7 +21,7 @@ pub extern "system" fn driver_entry( WdfDriverCreate, driver as PDRIVER_OBJECT, registry_path, - // The order of the next two arguements is swapped! + // The order of the next two arguments is swapped! &mut driver_config, WDF_NO_OBJECT_ATTRIBUTES, driver_handle_output, diff --git a/crates/wdk-macros/tests/nightly/trybuild/wdf_driver_create_wrong_arg_order.stderr b/crates/wdk-macros/tests/nightly/trybuild/wdf_driver_create_wrong_arg_order.stderr index ff715137..61f0d458 100644 --- a/crates/wdk-macros/tests/nightly/trybuild/wdf_driver_create_wrong_arg_order.stderr +++ b/crates/wdk-macros/tests/nightly/trybuild/wdf_driver_create_wrong_arg_order.stderr @@ -5,7 +5,7 @@ error[E0308]: arguments to this function are incorrect | | WdfDriverCreate, | | driver as PDRIVER_OBJECT, | | registry_path, - | | // The order of the next two arguements is swapped! + | | // The order of the next two arguments is swapped! | | &mut driver_config, | | ------------------ expected `*mut _WDF_OBJECT_ATTRIBUTES`, found `&mut _WDF_DRIVER_CONFIG` | | WDF_NO_OBJECT_ATTRIBUTES, @@ -21,7 +21,7 @@ help: swap these arguments 29 + WdfDriverCreate, 30 + driver as PDRIVER_OBJECT, 31 + registry_path, -32 + // The order of the next two arguements is swapped! +32 + // The order of the next two arguments is swapped! 33 + &mut driver_config, 34 + WDF_NO_OBJECT_ATTRIBUTES, 35 + driver_handle_output, diff --git a/crates/wdk-macros/tests/non-nightly/trybuild/wdf_driver_create_wrong_arg_order.rs b/crates/wdk-macros/tests/non-nightly/trybuild/wdf_driver_create_wrong_arg_order.rs index e1fbb4db..f66f5d19 100644 --- a/crates/wdk-macros/tests/non-nightly/trybuild/wdf_driver_create_wrong_arg_order.rs +++ b/crates/wdk-macros/tests/non-nightly/trybuild/wdf_driver_create_wrong_arg_order.rs @@ -20,7 +20,7 @@ pub extern "system" fn driver_entry( WdfDriverCreate, driver as PDRIVER_OBJECT, registry_path, - // The order of the next two arguements is swapped! + // The order of the next two arguments is swapped! &mut driver_config, WDF_NO_OBJECT_ATTRIBUTES, driver_handle_output, diff --git a/crates/wdk-macros/tests/non-nightly/trybuild/wdf_driver_create_wrong_arg_order.stderr b/crates/wdk-macros/tests/non-nightly/trybuild/wdf_driver_create_wrong_arg_order.stderr index 89626457..460008af 100644 --- a/crates/wdk-macros/tests/non-nightly/trybuild/wdf_driver_create_wrong_arg_order.stderr +++ b/crates/wdk-macros/tests/non-nightly/trybuild/wdf_driver_create_wrong_arg_order.stderr @@ -5,7 +5,7 @@ error[E0308]: arguments to this function are incorrect | | WdfDriverCreate, | | driver as PDRIVER_OBJECT, | | registry_path, - | | // The order of the next two arguements is swapped! + | | // The order of the next two arguments is swapped! | | &mut driver_config, | | ------------------ expected `*mut _WDF_OBJECT_ATTRIBUTES`, found `&mut _WDF_DRIVER_CONFIG` | | WDF_NO_OBJECT_ATTRIBUTES, @@ -21,7 +21,7 @@ help: swap these arguments 28 + WdfDriverCreate, 29 + driver as PDRIVER_OBJECT, 30 + registry_path, -31 + // The order of the next two arguements is swapped! +31 + // The order of the next two arguments is swapped! 32 + &mut driver_config, 33 + WDF_NO_OBJECT_ATTRIBUTES, 34 + driver_handle_output, diff --git a/crates/wdk-sys/src/constants.rs b/crates/wdk-sys/src/constants.rs index 6bbee5b5..b84668c3 100644 --- a/crates/wdk-sys/src/constants.rs +++ b/crates/wdk-sys/src/constants.rs @@ -8,9 +8,10 @@ use crate::types::{NTSTATUS, POOL_FLAGS, PVOID, PWDF_OBJECT_ATTRIBUTES}; #[allow(non_upper_case_globals)] #[rustversion::attr( any( - all(not(nightly), since(1.79)), + all(not(nightly), since(1.78)), all(nightly, since(2024-02-09)), ), + // required until following issue is resolved: https://github.com/rust-lang/rust-bindgen/issues/2710 allow(clippy::manual_c_str_literals) )] #[allow(clippy::unreadable_literal)] diff --git a/crates/wdk-sys/src/test_stubs.rs b/crates/wdk-sys/src/test_stubs.rs index 035300a5..e7d6fd0d 100644 --- a/crates/wdk-sys/src/test_stubs.rs +++ b/crates/wdk-sys/src/test_stubs.rs @@ -2,7 +2,7 @@ // License: MIT OR Apache-2.0 //! Any library dependency that depends on `wdk-sys` requires these stubs to -//! provide symobols to sucessfully compile and run tests. They can be brought +//! provide symobols to successfully compile and run tests. They can be brought //! into scope by introducing `wdk-sys` with the `test-stubs` feature in the //! `dev-dependencies` of the crate's `Cargo.toml` diff --git a/crates/wdk-sys/src/types.rs b/crates/wdk-sys/src/types.rs index bcc3616b..6f0536e2 100644 --- a/crates/wdk-sys/src/types.rs +++ b/crates/wdk-sys/src/types.rs @@ -40,7 +40,7 @@ )] #[rustversion::attr( any( - all(not(nightly), since(1.79)), + all(not(nightly), since(1.78)), all(nightly, since(2024-02-09)), ), allow(clippy::ref_as_ptr)