-
Notifications
You must be signed in to change notification settings - Fork 110
refactor(cargo-wdk): target architecture handling in BuildAction to respect other forms of target overrides
#494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Removed the TargetArch enum and simplified target architecture handling in the CLI. - Updated the command execution function to accept an optional working directory. - Enhanced error reporting for command failures, including status codes and stderr output. - Cleaned up the `run` method in the `WdkBuild` struct to prepare for future enhancements. - Improved test assertions for driver packaging tasks and added a utility function to determine target folders based on architecture. - Updated the Cargo configuration for the WDM driver test to specify the target architecture explicitly.
BuildAction to respect other forms of target overrides
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the cargo-wdk build command to better respect Cargo's target architecture override mechanisms by removing the TargetArch enum and simplifying architecture handling. Instead of detecting architecture via rustc --print host-tuple, the code now uses cargo rustc -- --print cfg to detect the effective target architecture that Cargo will build for, respecting configuration settings from .cargo/config.toml or environment variables.
- Removed
TargetArchenum and related CLI architecture detection logic - Updated command execution to support optional working directories and enhanced error reporting
- Improved driver packaging task error messages and test utilities
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
crates/cargo-wdk/tests/wdm-driver/.cargo/config.toml |
Added explicit target architecture configuration |
crates/cargo-wdk/tests/build_command_test.rs |
Updated test assertions and added utility for target folder detection |
crates/cargo-wdk/src/providers/wdk_build.rs |
Added placeholder for future WDK build number field |
crates/cargo-wdk/src/providers/mod.rs |
Enhanced command error reporting with status codes and stderr |
crates/cargo-wdk/src/providers/exec.rs |
Added working directory support and improved debug logging |
crates/cargo-wdk/src/cli.rs |
Removed TargetArch enum and simplified build command handling |
crates/cargo-wdk/src/actions/mod.rs |
Removed TargetArch enum definition |
crates/cargo-wdk/src/actions/build/tests.rs |
Updated test cases to use new architecture handling |
crates/cargo-wdk/src/actions/build/package_task.rs |
Changed driver model parameter to reference and minor formatting cleanup |
crates/cargo-wdk/src/actions/build/mod.rs |
Implemented new target architecture detection and package root path construction |
crates/cargo-wdk/src/actions/build/error.rs |
Added new error types for architecture detection |
crates/cargo-wdk/src/actions/build/build_task.rs |
Updated to use simplified architecture handling |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
…ecture and artifact paths for the packaging process - Added tests for building KMDF drivers with explicit target architecture options. - Created a new test fixture for `kmdf-driver-with-target-override` to validate target override scenarios
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 16 out of 17 changed files in this pull request and generated 3 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
…g logic - Added new error variants to `BuildActionError` and `BuildTaskError` for better error reporting. - Enhanced the `build_and_package` function to handle driver binary paths and target architecture more effectively. - Modified tests to reflect changes in the build process and ensure accurate artifact handling. - Renamed `Profile::Dev` to `Profile::Debug` for clarity and consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 17 out of 18 changed files in this pull request and generated 6 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 26 out of 38 changed files in this pull request and generated 3 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 26 out of 38 changed files in this pull request and generated 3 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 26 out of 38 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
crates/cargo-wdk/src/actions/mod.rs:39
- The profile parsing accepts 'debug' but Cargo's standard development profile is called 'dev'. This creates inconsistency with Cargo conventions.
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"debug" => std::result::Result::Ok(Self::Debug),
"release" => std::result::Result::Ok(Self::Release),
_ => Err(format!("'{s}' is not a valid profile")),
}
}
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
remove retry mechanism for cargo clean in integration tests improve comments for `get_target_dir_for_packaging` fn
…ariants are defined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 17 out of 18 changed files in this pull request and generated 8 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| run_cargo_clean(&driver_path); | ||
| let stdout = run_build_cmd(&driver_path); | ||
| #[test] | ||
| fn kmdf_driver_with_target_override_cli_wins() { |
Copilot
AI
Dec 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test kmdf_driver_with_target_override_cli_wins sets both CARGO_BUILD_TARGET env var (to X86_64) and --target-arch CLI arg (to ARM64) to verify that CLI wins. However, the test fixture's .cargo/config.toml also has target = "x86_64-pc-windows-msvc". This means there are actually 3 conflicting target specifications, not 2. The test name and logic should clarify that CLI wins over both env and config.toml.
| fn kmdf_driver_with_target_override_cli_wins() { | |
| /// This test verifies that the CLI `--target-arch` argument takes precedence over both | |
| /// the `CARGO_BUILD_TARGET` environment variable and the `target` specified in `.cargo/config.toml`. | |
| /// All three sources are set to conflicting values: | |
| /// - `.cargo/config.toml` sets target to x86_64-pc-windows-msvc | |
| /// - `CARGO_BUILD_TARGET` env var is set to either x86_64-pc-windows-msvc or aarch64-pc-windows-msvc | |
| /// - CLI `--target-arch` is set to ARM64 | |
| /// The test asserts that the CLI value wins. | |
| fn kmdf_driver_with_target_override_cli_wins_over_env_and_config() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@svasista-ms Do add a comment stating the three competing sources of config. The comment can be brief. Doesn't have to be as big as the one suggested by copilot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 17 out of 18 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let wdk_content_root = std::env::var("NugetPackagesRoot") | ||
| .ok() | ||
| .map(|nuget_package_root| get_nuget_wdk_content_root(target_arch, &nuget_package_root)); | ||
| let env = wdk_content_root | ||
| .as_deref() | ||
| .map(|wdk_content_root| [("WDKContentRoot", Some(wdk_content_root))]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to extract this into a function and use it everywhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @gurry, I moved the NugetPackagesRoot check to the helper function. Renamed the fn to get_wdk_content_root_from_nuget_packages_root. This fn will return None if either of the required environment variables are not set.
@svasista-ms looks like the test coverage of the newly added code has some room for improvement. Please have a look |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 18 out of 19 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "Driver binary's parent directory is missing. Driver binary (.dll) \ | ||
| path: {}", |
Copilot
AI
Dec 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment uses "Driver binary's parent directory is missing" but the parent directory of any file path should always exist. The real issue is that the path is likely a root path or otherwise invalid. Consider updating the error message to be more accurate about the failure condition.
| "Driver binary's parent directory is missing. Driver binary (.dll) \ | |
| path: {}", | |
| "Cannot determine parent directory for driver binary; path may be a \ | |
| root or otherwise invalid. Driver binary (.dll) path: {}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 18 out of 19 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "./tests/wdk-macros-tests/Cargo.toml", | ||
| "./tests/wdk-sys-tests/Cargo.toml", | ||
|
|
||
| // Rust Analyzer is disabled on the following test projects because |
Copilot
AI
Dec 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment at line 25 should have proper sentence capitalization and punctuation. Change "// Rust Analyzer is disabled on the following test projects because" to "// Rust Analyzer is disabled on the following test projects because:"
| // Rust Analyzer is disabled on the following test projects because | |
| // Rust Analyzer is disabled on the following test projects because: |
| /// is found in the output or its parent folder cannot be determined. | ||
| /// - `BuildActionError::NotAbsolute` - If the DLL's parent path could not | ||
| /// be made absolute. | ||
| /// - `BuildActionError::CannotDetermineTargetDir` - If a cargo message | ||
| /// could not be parsed. |
Copilot
AI
Dec 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation at lines 411-416 lists the same error variant CannotDetermineTargetDir twice. The first one should be for "no matching DLL file found" and the second for "cargo message parse errors". Consider consolidating these into a single bullet point or making them distinct, such as:
BuildActionError::CannotDetermineTargetDir- If no matching DLL file is found in the output, its parent folder cannot be determined, or a cargo message could not be parsed.
| /// is found in the output or its parent folder cannot be determined. | |
| /// - `BuildActionError::NotAbsolute` - If the DLL's parent path could not | |
| /// be made absolute. | |
| /// - `BuildActionError::CannotDetermineTargetDir` - If a cargo message | |
| /// could not be parsed. | |
| /// is found in the output, its parent folder cannot be determined, or a | |
| /// cargo message could not be parsed. | |
| /// - `BuildActionError::NotAbsolute` - If the DLL's parent path could not | |
| /// be made absolute. |
| /// Invokes `cargo rustc -- --print cfg` and finds the `target_arch` value | ||
| /// | ||
| /// # Arguments | ||
| /// * `working_dir` -- Working directory from which the command must be |
Copilot
AI
Dec 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The double dash in the comment at line 493 should be a single dash for consistency with standard documentation style. Change "* working_dir -- Working directory" to "* working_dir - Working directory".
| /// * `working_dir` -- Working directory from which the command must be | |
| /// * `working_dir` - Working directory from which the command must be |
This PR includes changes to the
buildcommand to respect other forms of target configuration vis config.toml (build.target) and environment (CARGO_BUILD_TARGET) along with the--targetCLI option.Logical Changes
cargo buildalready supported the above forms of target specification. What we needed was to ensure packaging step uses the same target as build step and uses the correct output location of binaries.In this PR is we now run
cargo build --message-format=json(instead ofcargo build) and extract the output location of binaries from the resulting JSON. To get the target arch we runcargo rustc --printright aftercargo build --message-format=jsonand parse the output for thetarget_archfield. [1] [2] [3].Test Changes
Added
kmdf-driver-with-target-overridetest fixture incargo-wdk/testsand the cases incrates/cargo-wdk/tests/build_command_test.rs[4]CI Workflow Changes
To support the integration test cases that run
cargo wdk buildin a cross-compilation setting when using Nuget-based WDK, two additional environment variables have been added:FullVersionNumber: Denotes the complete version number (including QFE) of the WDK and SDK nuget packages that were downloaded [5]NugetPackagesRoot: The root directory where the nuget packages required to build a driver are downloaded [6]The variables are set in the
install-wdkaction and used inbuild_command_testwhere some form of target override is tested. UsingNugetPackagesRootandFullVersionNumbertheWDKContentRootenv var is set to point to the correct WDK content based on the target architecture.Closes #435
Closes #348