feat: add linker directive for VHF lib + move static linker directives from wdk-build to wdk-sys#685
feat: add linker directive for VHF lib + move static linker directives from wdk-build to wdk-sys#685Alan632 wants to merge 18 commits into
Conversation
… directives from wdk-build/src/lib.rs into wdk-sys/build.rs
There was a problem hiding this comment.
Pull request overview
This PR updates how native WDK libraries are linked by moving static rustc-link-lib directives out of wdk-build’s configure_binary_build prints and into wdk-sys’s generated bindings via #[link(...)] attributes. It also adds conditional linker directives for the VHF library when the hid feature is enabled, selecting VhfKm vs VhfUm based on driver model.
Changes:
- Emit base driver-model-specific native library link directives into bindgen output (
ntddk.rs/windows.rs) fromwdk-sys/build.rs. - Add
hid-gated#[link]directives forVhfKm(KMDF/WDM) andVhfUm(UMDF). - Remove the corresponding
cargo::rustc-link-lib=static=*emissions fromwdk-build::Config::configure_binary_build(leaving link-arg prints in place).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| crates/wdk-sys/build.rs | Adds a reusable #[link] directive helper and injects conditional link directives into generated bindings (including VHF for hid). |
| crates/wdk-build/src/lib.rs | Stops emitting static rustc-link-lib lines (now handled by wdk-sys), retaining cdylib link-args and documenting future move. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #685 +/- ##
==========================================
+ Coverage 79.93% 80.61% +0.67%
==========================================
Files 26 26
Lines 5633 5829 +196
Branches 5633 5829 +196
==========================================
+ Hits 4503 4699 +196
Misses 1002 1002
Partials 128 128 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…ts by utilizing ApiSubset similar to the headers
…indows-drivers-rs into vhf_lib_linker_args-v2
…utes out when building non-driver test wdk-sys-tests (wdk-sys-tests does not call configure_binary_build thus no search paths are emitted and ungated link attributes fail the build/test)
…on, library selection, and link directive string creation) -removed raw strings in lieu of types to tightly constrain LinkDirective creation w/o needing assert checks -removed and compacted unneeded functions from original implementation
… attributes to ensure wdk-sys builds correctly when compiled for test - add unit tests - add PartialEq and Eq traits to LinkKind, LinkModifier, and LinkDirective
leon-xd
left a comment
There was a problem hiding this comment.
Great work. Few changes here and there but the overall shape is very solid!
| } | ||
|
|
||
| #[test] | ||
| fn render_static_directive_includes_no_bundle_modifier() { |
| } | ||
|
|
||
| #[test] | ||
| fn base_directives_are_all_static_no_bundle() { |
- add doctest to wdk-sys-tests - add cdylib driver unit test to mixed-package-kmdf-workspace, and update Cargo.toml
…indows-drivers-rs into vhf_lib_linker_args-v2
| //! Like the driver unit test in `tests/mixed-package-kmdf-workspace`, it | ||
| //! references a bindgen generated WDM type (`DRIVER_OBJECT`) via a const | ||
| //! `size_of` — so the doctest actually links `wdk-sys`'s generated bindings | ||
| //! while touching only a type (never a KM function |
| /// [`ApiSubset`] rather than a set like | ||
| /// [`Config::bindgen_header_contents`]. | ||
| /// Each generated bindings file requests only the native libraries | ||
| /// introduced by its own [`ApiSubset`]. This avoids duplicate `#[link]` |
There was a problem hiding this comment.
nit: i think we can delete this entire paragraph, the first sentence is pretty much saying the same thing as the paragraph above and not sure how necessary the second sentence is but i'm fine to keep it if you feel it's necessary
There was a problem hiding this comment.
I can see how it's redundant, removed that paragraph.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (3)
crates/wdk-build/src/lib.rs:2253
- The test name
render_static_directive_includes_no_bundle_modifieris misleading: the assertion expects the rendered attribute to includemodifiers = "-bundle"(i.e., the-bundlemodifier is present to disable bundling). Renaming the test to reflect what it actually checks will make failures easier to interpret.
fn render_static_directive_includes_no_bundle_modifier() {
tests/mixed-package-kmdf-workspace/crates/driver/src/lib.rs:10
- Minor doc-comment grammar/whitespace: the blank doc line has trailing whitespace, and the sentence reads better with a comma after
cargo test.
//!
//! Running `cargo test` the crate is built as a std test harness with
//! `wdk-sys`'s `test-stubs` feature enabled (see dev-dependencies): that
tests/wdk-sys-tests/src/lib.rs:18
- There’s an extra leading space in the doc comment (
//! while ...) and a small hyphenation nit (“bindgen generated” → “bindgen-generated”). Cleaning this up avoids odd rendering in rustdoc.
//! references a bindgen generated WDM type (`DRIVER_OBJECT`) via a const
//! `size_of` — so the doctest actually links `wdk-sys`'s generated bindings
//! while touching only a type (never a KM function
//! binding that `test-stubs` leaves unlinked).
- fix: a doc comment - formatting
| /// Each emitted directive is gated behind | ||
| /// `#[cfg(not(any(test, feature = "test-stubs")))]`, evaluated in the crate | ||
| /// that compiles the generated bindings (`wdk-sys`). The directives are | ||
| /// therefore suppressed when `wdk-sys` is built with its `test-stubs` | ||
| /// feature, or when `wdk-sys` is itself compiled as a test target (e.g. | ||
| /// `cargo test -p wdk-sys`). |
There was a problem hiding this comment.
Please audit all your comments. This is an implementation detail and only one possible use of this function
Summary
Adds conditionally compiled linker directives for the VHF library tied to the "hid" feature.
Moves build script emitted static linker directives (
cargo::rustc-link-lib=static=*) from wdk-build/src/lib.rs into bindgen generated files as conditionally compiled attributes. The Rust source insertion happens in wdk-sys/build.rs while the backend logic and Rust source string build lives in wdk-build/src/lib.rs (closely following the pattern the bindgen generated headers use). This allows conditional compilation of linker directives (and eventually link args) without having to rely on cross crate feature signaling, and guards against issues from version drift (in case multiple versions of wdk-build are used in one project).This PR is a redesign of and supersedes PR!653.
Verification
Verified both kmdf and umdf drivers built with "hid" and Vhf functions linked against VhfKm.lib and VhfUm.lib respectively. Additionally, inspected each driver's linker
.mapfile for evidence of the respective Vhf symbols.Bindgen generated files are also inspected post build for the presence of the link attributes.