Skip to content
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

fix!: prevent linking of wdk libraries in tests that depend on wdk-sys #118

Merged
merged 4 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ jobs:
with:
tool: cargo-expand

# FIXME: wdk-sys layout tests fail, but only on github hosted runner
- name: Run Cargo Test
run: cargo +${{ matrix.rust_toolchain }} test --locked --profile ${{ matrix.cargo_profile }} --target ${{ matrix.target_triple }} --workspace --exclude wdk-sys
run: cargo +${{ matrix.rust_toolchain }} test --locked --profile ${{ matrix.cargo_profile }} --target ${{ matrix.target_triple }}

- name: Run Cargo Test (--features nightly)
if: matrix.rust_toolchain == 'nightly'
run: cargo +${{ matrix.rust_toolchain }} test --locked --profile ${{ matrix.cargo_profile }} --target ${{ matrix.target_triple }} --workspace --exclude wdk-sys --features nightly
run: cargo +${{ matrix.rust_toolchain }} test --locked --profile ${{ matrix.cargo_profile }} --target ${{ matrix.target_triple }} --features nightly
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ To maintain the quality of code, tests and tools are required to pass before con

**_Functional Correctness:_**

* `cargo test --locked --workspace --exclude sample-*`
* To test `nightly` features: `cargo +nightly test --locked --workspace --exclude sample-* --features nightly`
* `cargo test --locked`
* To test `nightly` features: `cargo +nightly test --locked --features nightly`

**_Static Analysis and Linting:_**

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ The crates in this repository are available from [`crates.io`](https://crates.io

```rust
fn main() -> Result<(), wdk_build::ConfigError> {
wdk_build::Config::from_env_auto()?.configure_binary_build();
wdk_build::Config::from_env_auto()?.configure_binary_build()?;
Ok(())
}
```
Expand Down
2 changes: 1 addition & 1 deletion crates/sample-kmdf-driver/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
// License: MIT OR Apache-2.0

fn main() -> Result<(), wdk_build::ConfigError> {
wdk_build::Config::from_env_auto()?.configure_binary_build();
wdk_build::Config::from_env_auto()?.configure_binary_build()?;
Ok(())
}
6 changes: 5 additions & 1 deletion crates/wdk-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,9 @@ impl Config {
///
/// This consists mainly of linker setting configuration. This must be
/// called from a Cargo build script of the binary being built
pub fn configure_binary_build(&self) {
pub fn configure_binary_build(&self) -> Result<(), ConfigError> {
self.configure_library_build()?;

// Linker arguments derived from Microsoft.Link.Common.props in Ni(22H2) WDK
println!("cargo:rustc-cdylib-link-arg=/NXCOMPAT");
println!("cargo:rustc-cdylib-link-arg=/DYNAMICBASE");
Expand Down Expand Up @@ -609,6 +611,8 @@ impl Config {
println!("cargo:rustc-cdylib-link-arg=/SUBSYSTEM:WINDOWS");
}
}

Ok(())
}

/// Serializes this [`Config`] and exports it via the Cargo
Expand Down
1 change: 0 additions & 1 deletion crates/wdk-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,5 @@ fn main() -> anyhow::Result<()> {
generate_wdf(&out_path, config.clone())?;
}

config.configure_library_build()?;
Ok(config.export_config()?)
}
12 changes: 11 additions & 1 deletion crates/wdk-sys/src/test_stubs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! into scope by introducing `wdk-sys` with the `test-stubs` feature in the
//! `dev-dependencies` of the crate's `Cargo.toml`

use crate::{DRIVER_OBJECT, NTSTATUS, PCUNICODE_STRING};
use crate::{DRIVER_OBJECT, NTSTATUS, PCUNICODE_STRING, ULONG, WDFFUNC};

/// Stubbed version of `DriverEntry` Symbol so that test targets will compile
///
Expand All @@ -20,3 +20,13 @@ pub unsafe extern "system" fn driver_entry_stub(
) -> NTSTATUS {
0
}

/// Stubbed version of `WdfFunctions_01033` Symbol so that test targets will
/// compile
#[no_mangle]
pub static mut WdfFunctions_01033: *const WDFFUNC = core::ptr::null();

/// Stubbed version of `WdfFunctionCount` Symbol so that test targets will
/// compile
#[no_mangle]
pub static mut WdfFunctionCount: ULONG = 0;
Loading