diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 287e49bec..88db2c839 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 - -`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` diff --git a/crates/wdk-build/build.rs b/crates/wdk-build/build.rs index e1d30e72c..ab3815055 100644 --- a/crates/wdk-build/build.rs +++ b/crates/wdk-build/build.rs @@ -1,21 +1,24 @@ // Copyright (c) Microsoft Corporation // License: MIT OR Apache-2.0 -//! Build script for the `wdk-build` crate +//! Build script for the `wdk-build` crate. //! -//! This provides a `nightly_toolchain` feature to the `wdk-build` crate, so -//! that it can conditionally enable unstable features. +//! This provides a temporary fix for using `assert_matches!` in specific Rust +//! versions in the `wdk-build` crate. 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 +// code once the minimum supported Rust version is 1.95.0 or later. +#[rustversion::since(1.95.0)] +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() {} diff --git a/crates/wdk-build/src/lib.rs b/crates/wdk-build/src/lib.rs index 63444b6ef..e6314fa93 100644 --- a/crates/wdk-build/src/lib.rs +++ b/crates/wdk-build/src/lib.rs @@ -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::{ env, fmt, @@ -1547,7 +1546,7 @@ pub fn detect_wdk_build_number() -> Result { #[cfg(test)] mod tests { - #[cfg(nightly_toolchain)] + #[cfg(assert_matches_stabilized)] use std::assert_matches; use std::{collections::HashMap, ffi::OsStr, sync::Mutex}; @@ -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); } @@ -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); } @@ -1848,7 +1847,7 @@ mod tests { ..Config::default() }); - #[cfg(nightly_toolchain)] + #[cfg(assert_matches_stabilized)] assert_matches!( config.driver_config, DriverConfig::Kmdf(KmdfConfig { @@ -1871,7 +1870,7 @@ mod tests { ..Config::default() }); - #[cfg(nightly_toolchain)] + #[cfg(assert_matches_stabilized)] assert_matches!( config.driver_config, DriverConfig::Kmdf(KmdfConfig { @@ -1890,7 +1889,7 @@ mod tests { ..Config::default() }); - #[cfg(nightly_toolchain)] + #[cfg(assert_matches_stabilized)] assert_matches!( config.driver_config, DriverConfig::Umdf(UmdfConfig { @@ -1913,7 +1912,7 @@ mod tests { ..Config::default() }); - #[cfg(nightly_toolchain)] + #[cfg(assert_matches_stabilized)] assert_matches!( config.driver_config, DriverConfig::Umdf(UmdfConfig { @@ -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() @@ -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()