From c364797bcebacde757aad10ab6b04054856e4a20 Mon Sep 17 00:00:00 2001 From: Melvin Wang Date: Wed, 29 May 2024 14:58:54 -0600 Subject: [PATCH 1/3] refactor: set explicit priority for lint groups set for workspace (#164) --- Cargo.toml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2d943df5..f8f3674a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,10 +39,10 @@ unsafe_op_in_unsafe_fn = "forbid" [workspace.lints.clippy] # Lint Groups -all = "deny" -pedantic = "warn" -nursery = "warn" -cargo = "warn" +all = { level = "deny", priority = -1 } +pedantic = { level = "warn", priority = -1 } +nursery = { level = "warn", priority = -1 } +cargo = { level = "warn", priority = -1 } # Individual Lints multiple_unsafe_ops_per_block = "forbid" undocumented_unsafe_blocks = "forbid" From 793a2706a7f20e4609f416ad941a27124de1b759 Mon Sep 17 00:00:00 2001 From: NateD-MSFT <34494373+NateD-MSFT@users.noreply.github.com> Date: Wed, 29 May 2024 15:59:02 -0500 Subject: [PATCH 2/3] Build perf: Make calls to bindgen run in parallel (#159) --- crates/wdk-build/src/bindgen.rs | 4 +-- crates/wdk-sys/build.rs | 44 ++++++++++++++++++++++++++------- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/crates/wdk-build/src/bindgen.rs b/crates/wdk-build/src/bindgen.rs index 51aae94b..48a5d615 100644 --- a/crates/wdk-build/src/bindgen.rs +++ b/crates/wdk-build/src/bindgen.rs @@ -15,7 +15,7 @@ pub trait BuilderExt { /// /// Implementation may return `wdk_build::ConfigError` if it fails to create /// a builder - fn wdk_default(c_header_files: Vec<&str>, config: Config) -> Result; + fn wdk_default(c_header_files: Vec<&str>, config: &Config) -> Result; } impl BuilderExt for Builder { @@ -26,7 +26,7 @@ impl BuilderExt for Builder { /// /// Will return `wdk_build::ConfigError` if any of the resolved include or /// library paths do not exist - fn wdk_default(c_header_files: Vec<&str>, config: Config) -> Result { + fn wdk_default(c_header_files: Vec<&str>, config: &Config) -> Result { let mut builder = Self::default(); for c_header in c_header_files { diff --git a/crates/wdk-sys/build.rs b/crates/wdk-sys/build.rs index efb569ab..3721bf27 100644 --- a/crates/wdk-sys/build.rs +++ b/crates/wdk-sys/build.rs @@ -6,6 +6,8 @@ use std::{ env, path::{Path, PathBuf}, + sync::Arc, + thread::{self, JoinHandle}, }; use bindgen::CodegenConfig; @@ -21,7 +23,7 @@ use wdk_build::{BuilderExt, Config, ConfigError, DriverConfig, KMDFConfig}; // "2.0", "2.15", "2.17", "2.19", "2.21", "2.23", "2.25", "2.27", "2.31", // "2.33", ]; -fn generate_constants(out_path: &Path, config: Config) -> Result<(), ConfigError> { +fn generate_constants(out_path: &Path, config: &Config) -> Result<(), ConfigError> { Ok( bindgen::Builder::wdk_default(vec!["src/ntddk-input.h", "src/wdf-input.h"], config)? .with_codegen_config(CodegenConfig::VARS) @@ -31,7 +33,7 @@ fn generate_constants(out_path: &Path, config: Config) -> Result<(), ConfigError ) } -fn generate_types(out_path: &Path, config: Config) -> Result<(), ConfigError> { +fn generate_types(out_path: &Path, config: &Config) -> Result<(), ConfigError> { Ok( bindgen::Builder::wdk_default(vec!["src/ntddk-input.h", "src/wdf-input.h"], config)? .with_codegen_config(CodegenConfig::TYPES) @@ -41,7 +43,7 @@ fn generate_types(out_path: &Path, config: Config) -> Result<(), ConfigError> { ) } -fn generate_ntddk(out_path: &Path, config: Config) -> Result<(), ConfigError> { +fn generate_ntddk(out_path: &Path, config: &Config) -> Result<(), ConfigError> { Ok( bindgen::Builder::wdk_default(vec!["src/ntddk-input.h"], config)? .with_codegen_config((CodegenConfig::TYPES | CodegenConfig::VARS).complement()) @@ -51,7 +53,7 @@ fn generate_ntddk(out_path: &Path, config: Config) -> Result<(), ConfigError> { ) } -fn generate_wdf(out_path: &Path, config: Config) -> Result<(), ConfigError> { +fn generate_wdf(out_path: &Path, config: &Config) -> Result<(), ConfigError> { // As of NI WDK, this may generate an empty file due to no non-type and non-var // items in the wdf headers(i.e. functions are all inlined). This step is // intentionally left here in case older WDKs have non-inlined functions or new @@ -67,6 +69,15 @@ fn generate_wdf(out_path: &Path, config: Config) -> Result<(), ConfigError> { ) } +type GenerateFn = fn(&Path, &Config) -> Result<(), ConfigError>; + +const GENERATE_FUNCTIONS: [GenerateFn; 4] = [ + generate_constants, + generate_types, + generate_ntddk, + generate_wdf, +]; + fn main() -> anyhow::Result<()> { let tracing_filter = EnvFilter::default() // Show errors and warnings by default @@ -135,12 +146,27 @@ fn main() -> anyhow::Result<()> { ), ]; + let mut handles = Vec::>>::new(); + let config_arc = Arc::new(config); + for out_path in out_paths { - generate_constants(&out_path, config.clone())?; - generate_types(&out_path, config.clone())?; - generate_ntddk(&out_path, config.clone())?; - generate_wdf(&out_path, config.clone())?; + let path_arc = Arc::new(out_path); + for generate_function in GENERATE_FUNCTIONS { + let temp_path = path_arc.clone(); + let temp_config = config_arc.clone(); + let handle: JoinHandle> = thread::spawn(move || { + generate_function(&temp_path, &temp_config)?; + Ok(()) + }); + handles.push(handle); + } + } + + for handle in handles { + if let Err(e) = handle.join().unwrap() { + return Err(e.into()); + } } - Ok(config.export_config()?) + Ok(config_arc.export_config()?) } From b5fb26f954de48f842639bfe7f3054c7db3a0c95 Mon Sep 17 00:00:00 2001 From: Melvin Wang Date: Thu, 30 May 2024 17:28:47 -0600 Subject: [PATCH 3/3] docs: update readme to call out bugged LLVM 18 versions (#169) Signed-off-by: Melvin Wang --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8f7a6c45..afdef003 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,9 @@ 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 install -i LLVM.LLVM` - * Ensure you select the GUI option to add LLVM to the PATH + * `winget install -i LLVM.LLVM --version 17.0.6 --force` + * Ensure you select the GUI option to add LLVM to the PATH + * LLVM 18 has a bug that causes bindings to fail to generate for ARM64. Continue using LLVM 17 until LLVM 19 comes out with [the fix](https://github.com/llvm/llvm-project/pull/93235). See [this](https://github.com/rust-lang/rust-bindgen/issues/2842) for more details. * To execute post-build tasks (ie. `inf2cat`, `infverif`, etc.), `cargo make` is used * `cargo install --locked cargo-make --no-default-features --features tls-native`