Skip to content

feat: add PE resource version + metadata generation#661

Open
Alan632 wants to merge 13 commits into
microsoft:mainfrom
Alan632:driver_file_versioning
Open

feat: add PE resource version + metadata generation#661
Alan632 wants to merge 13 commits into
microsoft:mainfrom
Alan632:driver_file_versioning

Conversation

@Alan632
Copy link
Copy Markdown
Contributor

@Alan632 Alan632 commented May 22, 2026

Summary

Currently driver PE resource metadata and versioning do not get populated (the version in the *.inf does) and makes issue and post-mortem troubleshooting/tracing difficult.

This PR adds the functionality to populate the PE resource metadata automatically.

wdk-build/src/lib.rs

  • Adds a new variant to ConfigError
  • Extends configure_binary_build to initiate *.rc generation, compilation to *.res, and linker directive emission

wdk-build/src/resource_compile.rs

  • Entry point via compile_version_resource called from configure_binary_build
  • Grabs the driver version from the environment variable STAMPINF_VERSION, falling back to CARGO_PKG_VERSION set by Cargo
  • Pulls other PE Property values from Cargo.toml, defaulting to Cargo environment variables if missing
  • Generates an *.rc file and runs rc.exe to compile to a *.res and emits linker directives

wdk-build/src/metadata/mod.rs

  • Changes parsing functions for wdk metadata to allow other sections to coexist in the Cargo.toml (eg. new [package.metadata.wdk.version-resource]), keeps strict serde validation of Wdk/DriverConfig (eg. [package.metadata.wdk.driver-model])
  • Adds additional unit tests

Validation

Local testing with in production driver in the following scenarios: missing version-resource metadata, populated version-resource metadata, and STAMPINF_VERSION set.

Tested with sample drivers kmdf/wdm/umdf.

WDM sample driver with [package.metadata.wdk.version-resource] info filled in:

image

UMDF sample driver without [package.metadata.wdk.version-resource] info:

image

@Alan632 Alan632 self-assigned this May 22, 2026
Copilot AI review requested due to automatic review settings May 22, 2026 23:29
Copy link
Copy Markdown
Contributor

Copilot AI left a 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 adds automatic generation and compilation of Windows PE VERSIONINFO resources for driver binaries built with wdk-build, so that file version and descriptive metadata are embedded directly into the produced .sys / .dll artifacts (not just the .inf).

Changes:

  • Introduces resource_compile module to generate a .rc, compile it via rc.exe to a .res, and emit linker args to embed it into the driver binary.
  • Extends ConfigError and Config::configure_binary_build to run the version-resource compilation step during build script configuration.
  • Updates WDK metadata parsing so [package.metadata.wdk.*] sections (e.g., version-resource) can coexist while still strictly validating the driver-model configuration, plus adds unit tests.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
crates/wdk-build/src/resource_compile.rs New module implementing version/metadata resolution, .rc generation, rc.exe invocation, and link-arg emission, with unit tests.
crates/wdk-build/src/metadata/mod.rs Narrows WDK configuration deserialization to metadata.wdk.driver-model while permitting other metadata.wdk.* sections; adds tests.
crates/wdk-build/src/lib.rs Exposes the new module, adds a ConfigError variant, and invokes resource compilation from configure_binary_build.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/wdk-build/src/resource_compile.rs Outdated
Comment thread crates/wdk-build/src/resource_compile.rs
Comment thread crates/wdk-build/src/resource_compile.rs Dismissed
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 23, 2026

Codecov Report

❌ Patch coverage is 92.14437% with 74 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.37%. Comparing base (a90b267) to head (6790cde).

Files with missing lines Patch % Lines
crates/wdk-build/src/resource_compile.rs 91.68% 46 Missing and 25 partials ⚠️
crates/wdk-build/src/metadata/mod.rs 96.59% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #661      +/-   ##
==========================================
+ Coverage   79.61%   81.37%   +1.76%     
==========================================
  Files          26       27       +1     
  Lines        5544     6466     +922     
  Branches     5544     6466     +922     
==========================================
+ Hits         4414     5262     +848     
- Misses       1001     1048      +47     
- Partials      129      156      +27     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…tness for different dev environment setups
Copilot AI review requested due to automatic review settings May 27, 2026 18:47
Copy link
Copy Markdown
Contributor

Copilot AI left a 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 3 out of 3 changed files in this pull request and generated 4 comments.

Comment thread crates/wdk-build/src/resource_compile.rs
Comment thread crates/wdk-build/src/resource_compile.rs Outdated
Comment thread crates/wdk-build/src/resource_compile.rs Outdated
Comment thread crates/wdk-build/src/resource_compile.rs Outdated
@Alan632 Alan632 marked this pull request as ready for review May 27, 2026 20:13
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Alan632 <aln.noda7@gmail.com>
Copilot AI review requested due to automatic review settings May 27, 2026 20:59
Copy link
Copy Markdown
Contributor

Copilot AI left a 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 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread crates/wdk-build/src/resource_compile.rs Outdated
Comment thread crates/wdk-build/src/resource_compile.rs
Comment thread crates/wdk-build/src/lib.rs Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Alan632 <aln.noda7@gmail.com>
Copilot AI review requested due to automatic review settings May 27, 2026 21:28
Copy link
Copy Markdown
Contributor

Copilot AI left a 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 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread crates/wdk-build/src/lib.rs
Comment thread crates/wdk-build/src/resource_compile.rs
Comment thread crates/wdk-build/src/resource_compile.rs Outdated
Copilot AI review requested due to automatic review settings May 27, 2026 22:38
Copy link
Copy Markdown
Contributor

Copilot AI left a 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 4 out of 4 changed files in this pull request and generated 3 comments.

Comment thread crates/wdk-build/src/resource_compile.rs
Comment thread crates/wdk-build/src/resource_compile.rs
Comment thread crates/wdk-build/src/lib.rs
…ary rerun directive (CI builds are fresh), fix formatting in .typos.toml
Copilot AI review requested due to automatic review settings May 28, 2026 18:18
Copy link
Copy Markdown
Contributor

Copilot AI left a 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 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread crates/wdk-build/src/resource_compile.rs Outdated
Comment thread crates/wdk-build/src/resource_compile.rs Outdated
…ourceCompileError by changing variant to use path aware IoError
Comment thread .typos.toml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants