From a004a4cb1d4fa1ceada405bd00cb684220f60cf6 Mon Sep 17 00:00:00 2001 From: Melvin Wang Date: Sat, 9 Aug 2025 11:48:14 -0700 Subject: [PATCH 1/9] feat: enhance cargo metadata handling to respect config.toml - Updated `bindgen.rs` to respect `config.toml` overrides by running `cargo_metadata` in the top-level manifest directory. - Added tracing instrumentation for debugging purposes in `get_rust_edition` and `from_env_auto` functions. - Modified `Makefile.toml` to include `customized-config-toml-workspace` as a workspace member. - Created a new `customized-config-toml-workspace` with necessary Cargo files and dependencies. - Implemented a new library crate `lib-crate` that utilizes a patched dependency defined in `config.toml`. - Added a simple `build.rs` to trigger the WDK library build configuration. - Introduced a new path dependency `config-toml-patched-dep` to demonstrate the patching mechanism. --- crates/wdk-build/src/bindgen.rs | 17 +- crates/wdk-build/src/lib.rs | 22 +- tests/Makefile.toml | 1 + .../.cargo/config.toml | 5 + .../Cargo.lock | 758 ++++++++++++++++++ .../Cargo.toml | 3 + .../lib-crate/Cargo.toml | 14 + .../lib-crate/build.rs | 6 + .../lib-crate/src/lib.rs | 5 + .../path-dep/Cargo.toml | 4 + .../path-dep/src/lib.rs | 3 + 11 files changed, 832 insertions(+), 6 deletions(-) create mode 100644 tests/customized-config-toml-workspace/.cargo/config.toml create mode 100644 tests/customized-config-toml-workspace/Cargo.lock create mode 100644 tests/customized-config-toml-workspace/Cargo.toml create mode 100644 tests/customized-config-toml-workspace/lib-crate/Cargo.toml create mode 100644 tests/customized-config-toml-workspace/lib-crate/build.rs create mode 100644 tests/customized-config-toml-workspace/lib-crate/src/lib.rs create mode 100644 tests/customized-config-toml-workspace/path-dep/Cargo.toml create mode 100644 tests/customized-config-toml-workspace/path-dep/src/lib.rs diff --git a/crates/wdk-build/src/bindgen.rs b/crates/wdk-build/src/bindgen.rs index a6b69ea8f..9de3d9b81 100644 --- a/crates/wdk-build/src/bindgen.rs +++ b/crates/wdk-build/src/bindgen.rs @@ -8,8 +8,9 @@ use bindgen::{ Builder, }; use cargo_metadata::MetadataCommand; +use tracing::debug; -use crate::{Config, ConfigError, DriverConfig}; +use crate::{find_top_level_cargo_manifest, Config, ConfigError, DriverConfig}; /// An extension trait that provides a way to create a [`bindgen::Builder`] /// configured for generating bindings to the wdk @@ -242,10 +243,20 @@ fn get_stable_rust_target() -> Result { // Returns `ConfigError::CargoMetadataPackageNotFound` if the `wdk-build` // package is not found, or `ConfigError::UnsupportedRustEdition` if the edition // is not supported. +#[tracing::instrument(level = "debug")] fn get_rust_edition() -> Result { const WDK_BUILD_PACKAGE_NAME: &str = "wdk-build"; - - let wdk_sys_cargo_metadata = MetadataCommand::new().exec()?; + // Run `cargo_metadata` in the same working directory as the top level manifest + // in order to respect `config.toml` overrides + let top_level_cargo_manifest_path = find_top_level_cargo_manifest(); + debug!( + "Top level Cargo manifest path: {:?}", + top_level_cargo_manifest_path + ); + let cwd = top_level_cargo_manifest_path + .parent() + .expect("Cargo manifest should have a valid parent directory"); + let wdk_sys_cargo_metadata = MetadataCommand::new().current_dir(cwd).exec()?; let wdk_sys_package_metadata = wdk_sys_cargo_metadata .packages diff --git a/crates/wdk-build/src/lib.rs b/crates/wdk-build/src/lib.rs index 16f10ffc1..5588e1aa5 100644 --- a/crates/wdk-build/src/lib.rs +++ b/crates/wdk-build/src/lib.rs @@ -15,6 +15,7 @@ use std::{fmt, str::FromStr}; pub use bindgen::BuilderExt; use metadata::TryFromCargoMetadataError; +use tracing::debug; pub mod cargo_make; pub mod metadata; @@ -306,10 +307,25 @@ impl Config { /// # Panics /// /// Panics if the resolved top-level Cargo manifest path is not valid UTF-8 + #[tracing::instrument(level = "debug")] pub fn from_env_auto() -> Result { - let top_level_manifest = find_top_level_cargo_manifest(); + let top_level_cargo_manifest_path = find_top_level_cargo_manifest(); + debug!( + "Top level Cargo manifest path: {:?}", + top_level_cargo_manifest_path + ); + + let cwd = top_level_cargo_manifest_path + .parent() + .expect("Cargo manifest should have a valid parent directory"); + let cargo_metadata = MetadataCommand::new() - .manifest_path(&top_level_manifest) + // Run `cargo_metadata` in the same working directory as the top level manifest in order + // to respect `config.toml` overrides + .current_dir(cwd) + // top-level manifest path must be used in order for metadata from the top-level crates + // to be discovered + .manifest_path(&top_level_cargo_manifest_path) .exec()?; let wdk_metadata = metadata::Wdk::try_from(&cargo_metadata)?; @@ -318,7 +334,7 @@ impl Config { for manifest_path in metadata::iter_manifest_paths(cargo_metadata) .into_iter() .chain(std::iter::once( - top_level_manifest + top_level_cargo_manifest_path .try_into() .expect("Path to Cargo manifests should always be valid UTF8"), )) diff --git a/tests/Makefile.toml b/tests/Makefile.toml index 33fd10ab6..050aa9c69 100644 --- a/tests/Makefile.toml +++ b/tests/Makefile.toml @@ -6,6 +6,7 @@ CARGO_MAKE_CRATE_WORKSPACE_MEMBERS = [ "config-kmdf", "config-umdf", "config-wdm", + "customized-config-toml-workspace", "mixed-package-kmdf-workspace", "umdf-driver-workspace", "wdk-macros-tests", diff --git a/tests/customized-config-toml-workspace/.cargo/config.toml b/tests/customized-config-toml-workspace/.cargo/config.toml new file mode 100644 index 000000000..904409884 --- /dev/null +++ b/tests/customized-config-toml-workspace/.cargo/config.toml @@ -0,0 +1,5 @@ +[patch.crates-io] +# Patch a specific crate name to a local path so only config-aware cargo metadata resolves. +# Without running cargo_metadata from the workspace root (respecting config.toml), +# this dependency will not be found and metadata/build should fail. +config-toml-patched-dep = { path = "path-dep" } diff --git a/tests/customized-config-toml-workspace/Cargo.lock b/tests/customized-config-toml-workspace/Cargo.lock new file mode 100644 index 000000000..c7e63176b --- /dev/null +++ b/tests/customized-config-toml-workspace/Cargo.lock @@ -0,0 +1,758 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "anstream" +version = "0.6.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ae563653d1938f79b1ab1b5e668c87c76a9930414574a6583a7b7e11a8e6192" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd" + +[[package]] +name = "anstyle-parse" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e231f6134f61b71076a3eab506c379d4f36122f2af15a9ff04415ea4c3339e2" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e0633414522a32ffaac8ac6cc8f748e090c5717661fddeea04219e2344f5f2a" +dependencies = [ + "anstyle", + "once_cell_polyfill", + "windows-sys", +] + +[[package]] +name = "anyhow" +version = "1.0.98" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487" + +[[package]] +name = "bindgen" +version = "0.71.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f58bf3d7db68cfbac37cfc485a8d711e87e064c3d0fe0435b92f7a407f9d6b3" +dependencies = [ + "bitflags", + "cexpr", + "clang-sys", + "itertools", + "log", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn", +] + +[[package]] +name = "bitflags" +version = "2.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" + +[[package]] +name = "camino" +version = "1.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d07aa9a93b00c76f71bc35d598bed923f6d4f3a9ca5c24b7737ae1a292841c0" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo-platform" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e35af189006b9c0f00a064685c727031e3ed2d8020f7ba284d78cc2671bd36ea" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo_metadata" +version = "0.19.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd5eb614ed4c27c5d706420e4320fbe3216ab31fa1c33cd8246ac36dae4479ba" +dependencies = [ + "camino", + "cargo-platform", + "semver", + "serde", + "serde_json", + "thiserror", +] + +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + +[[package]] +name = "cfg-if" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268" + +[[package]] +name = "clang-sys" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" +dependencies = [ + "glob", + "libc", + "libloading", +] + +[[package]] +name = "clap" +version = "4.5.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50fd97c9dc2399518aa331917ac6f274280ec5eb34e555dd291899745c48ec6f" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap-cargo" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d546f0e84ff2bfa4da1ce9b54be42285767ba39c688572ca32412a09a73851e5" +dependencies = [ + "anstyle", + "clap", +] + +[[package]] +name = "clap_builder" +version = "4.5.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c35b5830294e1fa0462034af85cc95225a4cb07092c088c55bda3147cfcd8f65" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef4f52386a59ca4c860f7393bcf8abd8dfd91ecccc0f774635ff68e92eeef491" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675" + +[[package]] +name = "colorchoice" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" + +[[package]] +name = "config-toml-patched-dep" +version = "0.0.1" + +[[package]] +name = "either" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" + +[[package]] +name = "glob" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + +[[package]] +name = "itertools" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" + +[[package]] +name = "lib-crate" +version = "0.1.0" +dependencies = [ + "config-toml-patched-dep", + "wdk-build", +] + +[[package]] +name = "libc" +version = "0.2.174" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" + +[[package]] +name = "libloading" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07033963ba89ebaf1584d767badaa2e8fcec21aedea6b8c0346d487d49c28667" +dependencies = [ + "cfg-if", + "windows-targets 0.53.3", +] + +[[package]] +name = "log" +version = "0.4.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" + +[[package]] +name = "memchr" +version = "2.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[package]] +name = "once_cell_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad" + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "pin-project-lite" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" + +[[package]] +name = "prettyplease" +version = "0.2.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff24dfcda44452b9816fff4cd4227e1bb73ff5a2f1bc1105aa92fb8565ce44d2" +dependencies = [ + "proc-macro2", + "syn", +] + +[[package]] +name = "proc-macro2" +version = "1.0.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "regex" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" + +[[package]] +name = "rustc-hash" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" + +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + +[[package]] +name = "ryu" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" + +[[package]] +name = "semver" +version = "1.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56e6fa9c48d24d85fb3de5ad847117517440f6beceb7798af16b4a87d616b8d0" +dependencies = [ + "serde", +] + +[[package]] +name = "serde" +version = "1.0.219" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.219" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.142" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "030fedb782600dcbd6f02d479bf0d817ac3bb40d644745b769d6a96bc3afc5a7" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "syn" +version = "2.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "2.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing" +version = "0.1.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81383ab64e72a7a8b8e13130c49e3dab29def6d0c7d76a03087b3cf71c5c6903" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9d12581f227e93f094d3af2ae690a574abb8a2b9b7a96e7cfe9647b2b617678" +dependencies = [ + "once_cell", +] + +[[package]] +name = "unicode-ident" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "wdk-build" +version = "0.4.0" +dependencies = [ + "anyhow", + "bindgen", + "camino", + "cargo_metadata", + "cfg-if", + "clap", + "clap-cargo", + "paste", + "rustversion", + "semver", + "serde", + "serde_json", + "thiserror", + "tracing", + "windows", +] + +[[package]] +name = "windows" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd04d41d93c4992d421894c18c8b43496aa748dd4c081bac0dc93eb0489272b6" +dependencies = [ + "windows-core", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-core" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-implement" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-link" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets 0.53.3", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm 0.52.6", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.53.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5fe6031c4041849d7c496a8ded650796e7b6ecc19df1a431c1a363342e5dc91" +dependencies = [ + "windows-link", + "windows_aarch64_gnullvm 0.53.0", + "windows_aarch64_msvc 0.53.0", + "windows_i686_gnu 0.53.0", + "windows_i686_gnullvm 0.53.0", + "windows_i686_msvc 0.53.0", + "windows_x86_64_gnu 0.53.0", + "windows_x86_64_gnullvm 0.53.0", + "windows_x86_64_msvc 0.53.0", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnu" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_i686_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" diff --git a/tests/customized-config-toml-workspace/Cargo.toml b/tests/customized-config-toml-workspace/Cargo.toml new file mode 100644 index 000000000..d5eef34e0 --- /dev/null +++ b/tests/customized-config-toml-workspace/Cargo.toml @@ -0,0 +1,3 @@ +[workspace] +members = ["lib-crate"] +resolver = "2" diff --git a/tests/customized-config-toml-workspace/lib-crate/Cargo.toml b/tests/customized-config-toml-workspace/lib-crate/Cargo.toml new file mode 100644 index 000000000..3011ef292 --- /dev/null +++ b/tests/customized-config-toml-workspace/lib-crate/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "lib-crate" +version = "0.1.0" +edition = "2024" + +[dependencies] +# This crate name does not exist on crates.io and must be provided by the config.toml patch table +config-toml-patched-dep = "0.0.1" + +[build-dependencies] +wdk-build = { path = "../../../crates/wdk-build" } + +[package.metadata.wdk.driver-model] +driver-type = "WDM" diff --git a/tests/customized-config-toml-workspace/lib-crate/build.rs b/tests/customized-config-toml-workspace/lib-crate/build.rs new file mode 100644 index 000000000..48e8e4c6a --- /dev/null +++ b/tests/customized-config-toml-workspace/lib-crate/build.rs @@ -0,0 +1,6 @@ +fn main() { + // Exercise wdk-build metadata path respecting by invoking the library. + // We only need to call a function that triggers cargo_metadata under the hood. + wdk_build::configure_wdk_library_build() + .expect("configure_wdk_library_build should run successfully in this test"); +} diff --git a/tests/customized-config-toml-workspace/lib-crate/src/lib.rs b/tests/customized-config-toml-workspace/lib-crate/src/lib.rs new file mode 100644 index 000000000..d9d629aaf --- /dev/null +++ b/tests/customized-config-toml-workspace/lib-crate/src/lib.rs @@ -0,0 +1,5 @@ +use config_toml_patched_dep; + +pub fn foo() { + let _s = config_toml_patched_dep::hello_str(); +} diff --git a/tests/customized-config-toml-workspace/path-dep/Cargo.toml b/tests/customized-config-toml-workspace/path-dep/Cargo.toml new file mode 100644 index 000000000..ea9a713f2 --- /dev/null +++ b/tests/customized-config-toml-workspace/path-dep/Cargo.toml @@ -0,0 +1,4 @@ +[package] +name = "config-toml-patched-dep" +version = "0.0.1" +edition = "2024" diff --git a/tests/customized-config-toml-workspace/path-dep/src/lib.rs b/tests/customized-config-toml-workspace/path-dep/src/lib.rs new file mode 100644 index 000000000..d473b8414 --- /dev/null +++ b/tests/customized-config-toml-workspace/path-dep/src/lib.rs @@ -0,0 +1,3 @@ +pub fn hello_str() -> &'static str { + "hi" +} From 2de6d1a8ea2f65dae2136543d89865b9aa4dbddc Mon Sep 17 00:00:00 2001 From: Melvin Wang Date: Sat, 9 Aug 2025 13:13:13 -0700 Subject: [PATCH 2/9] feat: add build and package steps for tests in GitHub workflows --- .github/workflows/build.yaml | 6 ++++++ .github/workflows/test.yaml | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index a6db1fcb2..df33d33b6 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -92,6 +92,12 @@ jobs: - name: Package Examples (via Cargo Make) run: cargo make --cwd ./examples package-driver-flow +${{ matrix.rust_toolchain }} --locked --profile ${{ matrix.cargo_profile }} --target ${{ matrix.target_triple.name }} + - name: Build Tests (via Cargo Make) + run: cargo make --cwd ./tests build +${{ matrix.rust_toolchain }} --locked --profile ${{ matrix.cargo_profile }} --target ${{ matrix.target_triple.name }} + + - name: Package Tests (via Cargo Make) + run: cargo make --cwd ./tests package-driver-flow +${{ matrix.rust_toolchain }} --locked --profile ${{ matrix.cargo_profile }} --target ${{ matrix.target_triple.name }} + # Run cargo-wdk on examples - name: Install cargo-wdk run: cargo +${{ matrix.rust_toolchain }} install --path=crates/cargo-wdk --profile ${{ matrix.cargo_profile }} --locked --force diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 7c7fe4cde..e6a49dbdb 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -72,5 +72,8 @@ jobs: with: tool: cargo-expand@1.0.85 - - name: Run Cargo Test + - name: Run Cargo Test (workspace) run: cargo +${{ matrix.rust_toolchain }} test --locked --profile ${{ matrix.cargo_profile }} --target ${{ matrix.target_triple }} --all-features + + - name: Run Cargo Test (Top-Level tests Folder via Cargo Make) + run: cargo make --cwd ./tests test +${{ matrix.rust_toolchain }} --locked --profile ${{ matrix.cargo_profile }} --target ${{ matrix.target_triple.name }} From 7b42a9291ae8ddeedc1afef695679dc1cac14d9d Mon Sep 17 00:00:00 2001 From: Melvin Wang Date: Sat, 9 Aug 2025 13:54:37 -0700 Subject: [PATCH 3/9] add installation step for Cargo Make in GitHub Actions workflow --- .github/workflows/test.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index b013dce75..8d7486fc8 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -74,6 +74,11 @@ jobs: with: tool: cargo-expand@1.0.85 + - name: Install Cargo Make + uses: taiki-e/install-action@v2 + with: + tool: cargo-make + - name: Run Cargo Test (workspace) run: cargo +${{ matrix.rust_toolchain }} test --locked --profile ${{ matrix.cargo_profile }} --target ${{ matrix.target_triple.name }} --all-features From 9d1211a7ec7bde3a035661e128cf875c20b0e53c Mon Sep 17 00:00:00 2001 From: Melvin Wang Date: Sat, 9 Aug 2025 20:13:13 -0700 Subject: [PATCH 4/9] fix: remove version specifications from workspace dependencies and correct typo in documentation --- tests/mixed-package-kmdf-workspace/Cargo.toml | 12 ++++++------ tests/wdk-macros-tests/src/lib.rs | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/mixed-package-kmdf-workspace/Cargo.toml b/tests/mixed-package-kmdf-workspace/Cargo.toml index 1f754c367..1f43275e2 100644 --- a/tests/mixed-package-kmdf-workspace/Cargo.toml +++ b/tests/mixed-package-kmdf-workspace/Cargo.toml @@ -9,12 +9,12 @@ kmdf-version-major = 1 target-kmdf-version-minor = 33 [workspace.dependencies] -wdk = { path = "../../crates/wdk", version = "0.3.1" } -wdk-alloc = { path = "../../crates/wdk-alloc", version = "0.3.1" } -wdk-build = { path = "../../crates/wdk-build", version = "0.4.0" } -wdk-macros = { path = "../../crates/wdk-macros", version = "0.4.0" } -wdk-panic = { path = "../../crates/wdk-panic", version = "0.3.1" } -wdk-sys = { path = "../../crates/wdk-sys", version = "0.4.0" } +wdk = { path = "../../crates/wdk" } +wdk-alloc = { path = "../../crates/wdk-alloc" } +wdk-build = { path = "../../crates/wdk-build" } +wdk-macros = { path = "../../crates/wdk-macros" } +wdk-panic = { path = "../../crates/wdk-panic" } +wdk-sys = { path = "../../crates/wdk-sys" } [profile.dev] panic = "abort" diff --git a/tests/wdk-macros-tests/src/lib.rs b/tests/wdk-macros-tests/src/lib.rs index 8d9a46b26..a0946713d 100644 --- a/tests/wdk-macros-tests/src/lib.rs +++ b/tests/wdk-macros-tests/src/lib.rs @@ -41,7 +41,7 @@ pub static TRYBUILD_OUTPUT_FOLDER_PATH: LazyLock = /// reside in the `tests/inputs/macrotest` folder, and may be a path to /// a file relative to the `tests/inputs/macrotest` folder. This macro is /// designed to use one test file per generated test to fully take advantage of -/// parallization of tests in cargo. +/// parallelization of tests in cargo. /// /// Note: Due to limitations in `trybuild`, a successful compilation /// test will include output that looks similar to the following: From 8c2026af0f05350b1326f447674b1ba5b878293b Mon Sep 17 00:00:00 2001 From: Melvin Wang Date: Sun, 10 Aug 2025 13:19:07 -0700 Subject: [PATCH 5/9] feat: enhance cargo metadata handling to respect config.toml in cargo-wdk --- .../cargo-wdk/src/actions/build/build_task.rs | 7 ++- .../src/actions/build/package_task.rs | 18 +++--- crates/cargo-wdk/src/actions/build/tests.rs | 55 +++++++++++-------- crates/cargo-wdk/src/actions/new/mod.rs | 4 +- crates/cargo-wdk/src/cli.rs | 7 ++- crates/cargo-wdk/src/providers/exec.rs | 6 ++ 6 files changed, 60 insertions(+), 37 deletions(-) diff --git a/crates/cargo-wdk/src/actions/build/build_task.rs b/crates/cargo-wdk/src/actions/build/build_task.rs index 7d01a2e21..fdfbd415a 100644 --- a/crates/cargo-wdk/src/actions/build/build_task.rs +++ b/crates/cargo-wdk/src/actions/build/build_task.rs @@ -27,6 +27,7 @@ pub struct BuildTask<'a> { verbosity_level: clap_verbosity_flag::Verbosity, manifest_path: PathBuf, command_exec: &'a CommandExec, + working_dir: &'a Path, } impl<'a> BuildTask<'a> { @@ -70,6 +71,7 @@ impl<'a> BuildTask<'a> { verbosity_level, manifest_path, command_exec, + working_dir, }) } @@ -106,7 +108,10 @@ impl<'a> BuildTask<'a> { .iter() .map(std::string::String::as_str) .collect::>(); - self.command_exec.run("cargo", &args, None)?; + // Run cargo build from the provided working directory so that workspace + // resolution and relative paths behave as expected for the selected package + self.command_exec + .run("cargo", &args, None, Some(self.working_dir))?; debug!("Done"); Ok(()) } diff --git a/crates/cargo-wdk/src/actions/build/package_task.rs b/crates/cargo-wdk/src/actions/build/package_task.rs index 481ecf8f6..d897f7e6f 100644 --- a/crates/cargo-wdk/src/actions/build/package_task.rs +++ b/crates/cargo-wdk/src/actions/build/package_task.rs @@ -38,7 +38,7 @@ pub struct PackageTaskParams<'a> { pub driver_model: DriverConfig, } -/// Suports low level driver packaging operations +/// Supports low level driver packaging operations pub struct PackageTask<'a> { package_name: String, verify_signature: bool, @@ -301,7 +301,7 @@ impl<'a> PackageTask<'a> { if !wdf_version_flags.is_empty() { args.append(&mut wdf_version_flags.iter().map(String::as_str).collect()); } - if let Err(e) = self.command_exec.run("stampinf", &args, None) { + if let Err(e) = self.command_exec.run("stampinf", &args, None, None) { return Err(PackageTaskError::StampinfCommand(e)); } Ok(()) @@ -320,7 +320,7 @@ impl<'a> PackageTask<'a> { "/uselocaltime", ]; - if let Err(e) = self.command_exec.run("inf2cat", &args, None) { + if let Err(e) = self.command_exec.run("inf2cat", &args, None, None) { return Err(PackageTaskError::Inf2CatCommand(e)); } @@ -344,7 +344,7 @@ impl<'a> PackageTask<'a> { debug!("Checking if self signed certificate exists in WDRTestCertStore store."); let args = ["-s", WDR_TEST_CERT_STORE]; - match self.command_exec.run("certmgr.exe", &args, None) { + match self.command_exec.run("certmgr.exe", &args, None, None) { Ok(output) if output.status.success() => String::from_utf8(output.stdout).map_or_else( |e| Err(PackageTaskError::VerifyCertExistsInStoreInvalidCommandOutput(e)), |stdout| Ok(stdout.contains(WDR_LOCAL_TEST_CERT)), @@ -370,7 +370,7 @@ impl<'a> PackageTask<'a> { &format!("CN={WDR_LOCAL_TEST_CERT}"), // FIXME: this should be a parameter &cert_path, ]; - if let Err(e) = self.command_exec.run("makecert", &args, None) { + if let Err(e) = self.command_exec.run("makecert", &args, None, None) { return Err(PackageTaskError::CertGenerationInStoreCommand(e)); } Ok(()) @@ -388,7 +388,7 @@ impl<'a> PackageTask<'a> { WDR_LOCAL_TEST_CERT, &cert_path, ]; - if let Err(e) = self.command_exec.run("certmgr.exe", &args, None) { + if let Err(e) = self.command_exec.run("certmgr.exe", &args, None, None) { return Err(PackageTaskError::CreateCertFileFromStoreCommand(e)); } Ok(()) @@ -430,7 +430,7 @@ impl<'a> PackageTask<'a> { "SHA256", &driver_binary_file_path, ]; - if let Err(e) = self.command_exec.run("signtool", &args, None) { + if let Err(e) = self.command_exec.run("signtool", &args, None, None) { return Err(PackageTaskError::DriverBinarySignCommand(e)); } Ok(()) @@ -448,7 +448,7 @@ impl<'a> PackageTask<'a> { let args = ["verify", "/v", "/pa", &driver_binary_file_path]; // TODO: Differentiate between command exec failure and signature verification // failure - if let Err(e) = self.command_exec.run("signtool", &args, None) { + if let Err(e) = self.command_exec.run("signtool", &args, None, None) { return Err(PackageTaskError::DriverBinarySignVerificationCommand(e)); } Ok(()) @@ -486,7 +486,7 @@ impl<'a> PackageTask<'a> { } args.push(&inf_path); - if let Err(e) = self.command_exec.run("infverif", &args, None) { + if let Err(e) = self.command_exec.run("infverif", &args, None, None) { return Err(PackageTaskError::InfVerificationCommand(e)); } diff --git a/crates/cargo-wdk/src/actions/build/tests.rs b/crates/cargo-wdk/src/actions/build/tests.rs index 184184b45..31491a9fe 100644 --- a/crates/cargo-wdk/src/actions/build/tests.rs +++ b/crates/cargo-wdk/src/actions/build/tests.rs @@ -2429,13 +2429,14 @@ impl TestSetupPackageExpectations for TestBuildAction { .withf( move |command: &str, args: &[&str], - _env_vars: &Option<&HashMap<&str, &str>>| + _env_vars: &Option<&HashMap<&str, &str>>, + _working_dir: &Option<&Path>| -> bool { command == expected_cargo_command && args == expected_cargo_build_args }, ) .once() - .returning(move |_, _, _| Ok(expected_output.clone())); + .returning(move |_, _, _, _| Ok(expected_output.clone())); self } @@ -2720,7 +2721,8 @@ impl TestSetupPackageExpectations for TestBuildAction { .withf( move |command: &str, args: &[&str], - _env_vars: &Option<&HashMap<&str, &str>>| + _env_vars: &Option<&HashMap<&str, &str>>, + _working_dir: &Option<&Path>| -> bool { println!("command: {command}, args: {args:?}"); println!( @@ -2731,7 +2733,7 @@ impl TestSetupPackageExpectations for TestBuildAction { }, ) .once() - .returning(move |_, _, _| match override_output.clone() { + .returning(move |_, _, _, _| match override_output.clone() { Some(output) => match output.status.code() { Some(0) => Ok(Output { status: ExitStatus::from_raw(0), @@ -2786,7 +2788,8 @@ impl TestSetupPackageExpectations for TestBuildAction { .withf( move |command: &str, args: &[&str], - _env_vars: &Option<&HashMap<&str, &str>>| + _env_vars: &Option<&HashMap<&str, &str>>, + _working_dir: &Option<&Path>| -> bool { println!("command: {command}, args: {args:?}"); println!( @@ -2797,7 +2800,7 @@ impl TestSetupPackageExpectations for TestBuildAction { }, ) .once() - .returning(move |_, _, _| match override_output.clone() { + .returning(move |_, _, _, _| match override_output.clone() { Some(output) => match output.status.code() { Some(0) => Ok(Output { status: ExitStatus::from_raw(0), @@ -2825,13 +2828,14 @@ impl TestSetupPackageExpectations for TestBuildAction { .withf( move |command: &str, args: &[&str], - _env_vars: &Option<&HashMap<&str, &str>>| + _env_vars: &Option<&HashMap<&str, &str>>, + _working_dir: &Option<&Path>| -> bool { command == expected_certmgr_command && args == expected_certmgr_args }, ) .once() - .returning(move |_, _, _| match override_output.clone() { + .returning(move |_, _, _, _| match override_output.clone() { Some(output) => match output.status.code() { Some(0) => Ok(Output { status: ExitStatus::from_raw(0), @@ -2875,13 +2879,14 @@ impl TestSetupPackageExpectations for TestBuildAction { .withf( move |command: &str, args: &[&str], - _env_vars: &Option<&HashMap<&str, &str>>| + _env_vars: &Option<&HashMap<&str, &str>>, + _working_dir: &Option<&Path>| -> bool { command == expected_certmgr_command && args == expected_certmgr_args }, ) .once() - .returning(move |_, _, _| match override_output.clone() { + .returning(move |_, _, _, _| match override_output.clone() { Some(output) => match output.status.code() { Some(0) => Ok(Output { status: ExitStatus::from_raw(0), @@ -2923,13 +2928,14 @@ impl TestSetupPackageExpectations for TestBuildAction { .withf( move |command: &str, args: &[&str], - _env_vars: &Option<&HashMap<&str, &str>>| + _env_vars: &Option<&HashMap<&str, &str>>, + _working_dir: &Option<&Path>| -> bool { command == expected_makecert_command && args == expected_makecert_args }, ) .once() - .returning(move |_, _, _| match override_output.clone() { + .returning(move |_, _, _, _| match override_output.clone() { Some(output) => match output.status.code() { Some(0) => Ok(Output { status: ExitStatus::from_raw(0), @@ -2983,13 +2989,14 @@ impl TestSetupPackageExpectations for TestBuildAction { .withf( move |command: &str, args: &[&str], - _env_vars: &Option<&HashMap<&str, &str>>| + _env_vars: &Option<&HashMap<&str, &str>>, + _working_dir: &Option<&Path>| -> bool { command == expected_signtool_command && args == expected_signtool_args }, ) .once() - .returning(move |_, _, _| match override_output.clone() { + .returning(move |_, _, _, _| match override_output.clone() { Some(output) => match output.status.code() { Some(0) => Ok(Output { status: ExitStatus::from_raw(0), @@ -3042,13 +3049,14 @@ impl TestSetupPackageExpectations for TestBuildAction { .withf( move |command: &str, args: &[&str], - _env_vars: &Option<&HashMap<&str, &str>>| + _env_vars: &Option<&HashMap<&str, &str>>, + _working_dir: &Option<&Path>| -> bool { command == expected_signtool_command && args == expected_signtool_args }, ) .once() - .returning(move |_, _, _| match override_output.clone() { + .returning(move |_, _, _, _| match override_output.clone() { Some(output) => match output.status.code() { Some(0) => Ok(Output { status: ExitStatus::from_raw(0), @@ -3094,13 +3102,14 @@ impl TestSetupPackageExpectations for TestBuildAction { .withf( move |command: &str, args: &[&str], - _env_vars: &Option<&HashMap<&str, &str>>| + _env_vars: &Option<&HashMap<&str, &str>>, + _working_dir: &Option<&Path>| -> bool { command == expected_signtool_command && args == expected_signtool_verify_args }, ) .once() - .returning(move |_, _, _| match override_output.clone() { + .returning(move |_, _, _, _| match override_output.clone() { Some(output) => match output.status.code() { Some(0) => Ok(Output { status: ExitStatus::from_raw(0), @@ -3146,13 +3155,14 @@ impl TestSetupPackageExpectations for TestBuildAction { .withf( move |command: &str, args: &[&str], - _env_vars: &Option<&HashMap<&str, &str>>| + _env_vars: &Option<&HashMap<&str, &str>>, + _working_dir: &Option<&Path>| -> bool { command == expected_signtool_command && args == expected_signtool_verify_args }, ) .once() - .returning(move |_, _, _| match override_output.clone() { + .returning(move |_, _, _, _| match override_output.clone() { Some(output) => match output.status.code() { Some(0) => Ok(Output { status: ExitStatus::from_raw(0), @@ -3208,13 +3218,14 @@ impl TestSetupPackageExpectations for TestBuildAction { .withf( move |command: &str, args: &[&str], - _env_vars: &Option<&HashMap<&str, &str>>| + _env_vars: &Option<&HashMap<&str, &str>>, + _working_dir: &Option<&Path>| -> bool { command == expected_infverif_command && args == expected_infverif_args }, ) .once() - .returning(move |_, _, _| match override_output.clone() { + .returning(move |_, _, _, _| match override_output.clone() { Some(output) => match output.status.code() { Some(0) => Ok(Output { status: ExitStatus::from_raw(0), diff --git a/crates/cargo-wdk/src/actions/new/mod.rs b/crates/cargo-wdk/src/actions/new/mod.rs index 7e7451fe9..c5385e59a 100644 --- a/crates/cargo-wdk/src/actions/new/mod.rs +++ b/crates/cargo-wdk/src/actions/new/mod.rs @@ -46,7 +46,7 @@ impl<'a> NewAction<'a> { /// * `cwd` - The current working directory inside which driver project will /// be created. /// * `verbosity_level` - The verbosity level for logging. - /// * `command_exec` - The provider for command exection. + /// * `command_exec` - The provider for command execution. /// * `fs` - The provider for file system operations. /// /// # Returns @@ -121,7 +121,7 @@ impl<'a> NewAction<'a> { if let Some(flag) = trace::get_cargo_verbose_flags(self.verbosity_level) { args.push(flag); } - if let Err(e) = self.command_exec.run("cargo", &args, None) { + if let Err(e) = self.command_exec.run("cargo", &args, None, None) { return Err(NewActionError::CargoNewCommand(e)); } Ok(()) diff --git a/crates/cargo-wdk/src/cli.rs b/crates/cargo-wdk/src/cli.rs index ef5b71759..dcb6b354e 100644 --- a/crates/cargo-wdk/src/cli.rs +++ b/crates/cargo-wdk/src/cli.rs @@ -192,7 +192,7 @@ impl Cli { command_exec: &CommandExec, ) -> Result { command_exec - .run("rustc", &["--print", "host-tuple"], None) + .run("rustc", &["--print", "host-tuple"], None, None) .map_or_else( |e| Err(anyhow::anyhow!("Unable to read rustc host tuple: {e}")), |output| { @@ -306,7 +306,8 @@ mod tests { .withf( move |command: &str, args: &[&str], - _env_vars: &Option<&HashMap<&str, &str>>| + _env_vars: &Option<&HashMap<&str, &str>>, + _working_dir: &Option<&std::path::Path>| -> bool { println!("command: {command}, args: {args:?}"); println!( @@ -317,7 +318,7 @@ mod tests { }, ) .once() - .return_once(|_, _, _| expected_cli_result); + .return_once(|_, _, _, _| expected_cli_result); Cli::detect_default_target_arch_using_rustc(&mock_command_exec) } diff --git a/crates/cargo-wdk/src/providers/exec.rs b/crates/cargo-wdk/src/providers/exec.rs index 8f126beb1..a689adbd7 100644 --- a/crates/cargo-wdk/src/providers/exec.rs +++ b/crates/cargo-wdk/src/providers/exec.rs @@ -14,6 +14,7 @@ use std::{ collections::HashMap, + path::Path, process::{Command, Output, Stdio}, }; @@ -34,6 +35,7 @@ impl CommandExec { command: &'a str, args: &'a [&'a str], env_vars: Option<&'a HashMap<&'a str, &'a str>>, + working_dir: Option<&'a Path>, ) -> Result { debug!("Running: {} {:?}", command, args); @@ -46,6 +48,10 @@ impl CommandExec { } } + if let Some(working_dir) = working_dir { + cmd.current_dir(working_dir); + } + let output = cmd .stdout(Stdio::piped()) .spawn() From e8be4838238070d5ef1ce7d951a7773cba546fcd Mon Sep 17 00:00:00 2001 From: Melvin Wang Date: Sun, 10 Aug 2025 17:23:39 -0700 Subject: [PATCH 6/9] fix: update test flag comment for Windows Server 2022 compatibility in Cargo.toml --- tests/mixed-package-kmdf-workspace/crates/driver/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/mixed-package-kmdf-workspace/crates/driver/Cargo.toml b/tests/mixed-package-kmdf-workspace/crates/driver/Cargo.toml index a6b5f55e5..4dcc73955 100644 --- a/tests/mixed-package-kmdf-workspace/crates/driver/Cargo.toml +++ b/tests/mixed-package-kmdf-workspace/crates/driver/Cargo.toml @@ -9,6 +9,7 @@ publish = false [lib] crate-type = ["cdylib"] +test = false # Windows Server 2022 (used in CI) has issues running driver tests [build-dependencies] wdk-build.workspace = true From faa9cef6cde0a07ea39852accdf0ba219b7dbea1 Mon Sep 17 00:00:00 2001 From: Melvin Wang Date: Sun, 10 Aug 2025 17:27:18 -0700 Subject: [PATCH 7/9] fix: correct comment formatting for test flag in Cargo.toml --- tests/mixed-package-kmdf-workspace/crates/driver/Cargo.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/mixed-package-kmdf-workspace/crates/driver/Cargo.toml b/tests/mixed-package-kmdf-workspace/crates/driver/Cargo.toml index 4dcc73955..d1abe48e2 100644 --- a/tests/mixed-package-kmdf-workspace/crates/driver/Cargo.toml +++ b/tests/mixed-package-kmdf-workspace/crates/driver/Cargo.toml @@ -9,7 +9,8 @@ publish = false [lib] crate-type = ["cdylib"] -test = false # Windows Server 2022 (used in CI) has issues running driver tests +# Windows Server 2022 (used in CI) has issues running driver tests +test = false [build-dependencies] wdk-build.workspace = true From 60fc17a0eb67c3effe7305d9e7e2e097b9f1bb28 Mon Sep 17 00:00:00 2001 From: Melvin Wang Date: Mon, 11 Aug 2025 11:29:38 -0700 Subject: [PATCH 8/9] fix: update dependency syntax in Cargo.toml for consistency --- tests/mixed-package-kmdf-workspace/Cargo.toml | 12 ++++++------ tests/umdf-driver-workspace/Cargo.toml | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/mixed-package-kmdf-workspace/Cargo.toml b/tests/mixed-package-kmdf-workspace/Cargo.toml index 1f43275e2..30682a16f 100644 --- a/tests/mixed-package-kmdf-workspace/Cargo.toml +++ b/tests/mixed-package-kmdf-workspace/Cargo.toml @@ -9,12 +9,12 @@ kmdf-version-major = 1 target-kmdf-version-minor = 33 [workspace.dependencies] -wdk = { path = "../../crates/wdk" } -wdk-alloc = { path = "../../crates/wdk-alloc" } -wdk-build = { path = "../../crates/wdk-build" } -wdk-macros = { path = "../../crates/wdk-macros" } -wdk-panic = { path = "../../crates/wdk-panic" } -wdk-sys = { path = "../../crates/wdk-sys" } +wdk.path = "../../crates/wdk" +wdk-alloc.path = "../../crates/wdk-alloc" +wdk-build.path = "../../crates/wdk-build" +wdk-macros.path = "../../crates/wdk-macros" +wdk-panic.path = "../../crates/wdk-panic" +wdk-sys.path = "../../crates/wdk-sys" [profile.dev] panic = "abort" diff --git a/tests/umdf-driver-workspace/Cargo.toml b/tests/umdf-driver-workspace/Cargo.toml index 2ac08cbbc..c1c3ad239 100644 --- a/tests/umdf-driver-workspace/Cargo.toml +++ b/tests/umdf-driver-workspace/Cargo.toml @@ -9,12 +9,12 @@ umdf-version-major = 2 target-umdf-version-minor = 33 [workspace.dependencies] -wdk = { path = "../../crates/wdk", version = "0.3.1" } -wdk-alloc = { path = "../../crates/wdk-alloc", version = "0.3.1" } -wdk-build = { path = "../../crates/wdk-build", version = "0.4.0" } -wdk-macros = { path = "../../crates/wdk-macros", version = "0.4.0" } -wdk-panic = { path = "../../crates/wdk-panic", version = "0.3.1" } -wdk-sys = { path = "../../crates/wdk-sys", version = "0.4.0" } +wdk.path = "../../crates/wdk" +wdk-alloc.path = "../../crates/wdk-alloc" +wdk-build.path = "../../crates/wdk-build" +wdk-macros.path = "../../crates/wdk-macros" +wdk-panic.path = "../../crates/wdk-panic" +wdk-sys.path = "../../crates/wdk-sys" [profile.dev] lto = true From 627f7fcd06212401f7ae67a78e31b5c8ada4da88 Mon Sep 17 00:00:00 2001 From: Melvin Wang Date: Thu, 11 Sep 2025 23:43:33 -0700 Subject: [PATCH 9/9] Update crates/cargo-wdk/src/actions/build/build_task.rs Signed-off-by: Melvin Wang --- crates/cargo-wdk/src/actions/build/build_task.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/cargo-wdk/src/actions/build/build_task.rs b/crates/cargo-wdk/src/actions/build/build_task.rs index bfb158f8f..7e0b75d7f 100644 --- a/crates/cargo-wdk/src/actions/build/build_task.rs +++ b/crates/cargo-wdk/src/actions/build/build_task.rs @@ -102,8 +102,8 @@ impl<'a> BuildTask<'a> { .iter() .map(std::string::String::as_str) .collect::>(); - // Run cargo build from the provided working directory so that workspace - // resolution and relative paths behave as expected for the selected package + // Run cargo build from the provided working directory so that config.toml + // is respected self.command_exec .run("cargo", &args, None, Some(self.working_dir))?; debug!("Done");