Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 0 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,6 @@ The following tools should be installed as a part of the `windows-drivers-rs` de

The crates in this repository are designed to work with `stable` rust. Some of the crates expose a `nightly` feature that adds additional functionality that requires unstable rust features in the `nightly` toolchains.

#### In `test` targets and unit tests
Comment thread
leon-xd marked this conversation as resolved.

`test` targets and unit tests in other targets will automatically enable nightly features when a nightly toolchain is detected. This is done via the `nightly_toolchain` `cfg` value. This allows us to take advantage of unstable features (ex. [`assert_matches`](https://doc.rust-lang.org/std/assert_matches/macro.assert_matches.html)) in tests.

### Build and Test

To **only build** the workspace: `cargo build --locked --all-features`
Expand Down
19 changes: 11 additions & 8 deletions crates/wdk-build/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@
//! that it can conditionally enable unstable features.
Comment thread
Alan632 marked this conversation as resolved.
Outdated

fn main() {
println!("cargo::rustc-check-cfg=cfg(nightly_toolchain)");
setup_nightly_cfgs();
println!("cargo::rustc-check-cfg=cfg(assert_matches_stabilized)");
setup_assert_matches_stabilized_cfg();
}

// Custom attributes cannot be applied to expressions yet, so separate functions are required for nightly/non-nightly: https://github.com/rust-lang/rust/issues/15701
#[rustversion::nightly]
fn setup_nightly_cfgs() {
println!("cargo::rustc-cfg=nightly_toolchain");
// Custom attributes cannot be applied to expressions yet, so separate functions
// are required for `rustversion` conditional compilation: https://github.com/rust-lang/rust/issues/15701
// TODO: Remove the `setup_assert_matches_stabilized_cfg` feature and related
Comment thread
wmmc88 marked this conversation as resolved.
// code once the minimum supported Rust version is 1.95.0 or later.
Comment thread
wmmc88 marked this conversation as resolved.
#[rustversion::since(1.95.0)]
Comment thread
wmmc88 marked this conversation as resolved.
fn setup_assert_matches_stabilized_cfg() {
println!("cargo::rustc-cfg=assert_matches_stabilized");
}

#[rustversion::not(nightly)]
const fn setup_nightly_cfgs() {}
#[rustversion::before(1.95.0)]
const fn setup_assert_matches_stabilized_cfg() {}
Comment thread
wmmc88 marked this conversation as resolved.
19 changes: 9 additions & 10 deletions crates/wdk-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
//! includes being ables to select different WDF versions and different driver
//! models (WDM, KMDF, UMDF).

#![cfg_attr(nightly_toolchain, feature(assert_matches))]
use std::{
Comment thread
Alan632 marked this conversation as resolved.
env,
fmt,
Expand Down Expand Up @@ -1547,7 +1546,7 @@ pub fn detect_wdk_build_number() -> Result<u32, ConfigError> {

#[cfg(test)]
mod tests {
#[cfg(nightly_toolchain)]
#[cfg(assert_matches_stabilized)]
use std::assert_matches;
Comment thread
wmmc88 marked this conversation as resolved.
use std::{collections::HashMap, ffi::OsStr, sync::Mutex};

Expand Down Expand Up @@ -1824,7 +1823,7 @@ mod tests {
fn default_config() {
let config = with_env(&[("CARGO_CFG_TARGET_ARCH", Some("x86_64"))], Config::new);

#[cfg(nightly_toolchain)]
#[cfg(assert_matches_stabilized)]
assert_matches!(config.driver_config, DriverConfig::Wdm);
assert_eq!(config.cpu_architecture, CpuArchitecture::Amd64);
}
Expand All @@ -1836,7 +1835,7 @@ mod tests {
..Config::default()
});

#[cfg(nightly_toolchain)]
#[cfg(assert_matches_stabilized)]
assert_matches!(config.driver_config, DriverConfig::Wdm);
assert_eq!(config.cpu_architecture, CpuArchitecture::Amd64);
}
Expand All @@ -1848,7 +1847,7 @@ mod tests {
..Config::default()
});

#[cfg(nightly_toolchain)]
#[cfg(assert_matches_stabilized)]
assert_matches!(
config.driver_config,
DriverConfig::Kmdf(KmdfConfig {
Expand All @@ -1871,7 +1870,7 @@ mod tests {
..Config::default()
});

#[cfg(nightly_toolchain)]
#[cfg(assert_matches_stabilized)]
assert_matches!(
config.driver_config,
DriverConfig::Kmdf(KmdfConfig {
Expand All @@ -1890,7 +1889,7 @@ mod tests {
..Config::default()
});

#[cfg(nightly_toolchain)]
#[cfg(assert_matches_stabilized)]
assert_matches!(
config.driver_config,
DriverConfig::Umdf(UmdfConfig {
Expand All @@ -1913,7 +1912,7 @@ mod tests {
..Config::default()
});

#[cfg(nightly_toolchain)]
#[cfg(assert_matches_stabilized)]
assert_matches!(
config.driver_config,
DriverConfig::Umdf(UmdfConfig {
Expand Down Expand Up @@ -2082,7 +2081,7 @@ mod tests {
Config::validate_and_add_folder_path(&mut include_paths, non_existent_path);

assert!(result.is_err());
#[cfg(nightly_toolchain)]
#[cfg(assert_matches_stabilized)]
assert_matches!(
result.unwrap_err(),
ConfigError::DirectoryNotFound { directory } if directory == non_existent_path.to_string_lossy()
Expand All @@ -2100,7 +2099,7 @@ mod tests {
let result = Config::validate_and_add_folder_path(&mut include_paths, file.path());

assert!(result.is_err());
#[cfg(nightly_toolchain)]
#[cfg(assert_matches_stabilized)]
assert_matches!(
result.unwrap_err(),
ConfigError::DirectoryNotFound { directory } if directory == file.path().to_string_lossy()
Expand Down
Loading