Skip to content

Commit de6622a

Browse files
leon-xdleon-xdCopilot
authored
chore!: bump to Rust 2024 Edition (#430)
Signed-off-by: Leon Durrenberger <[email protected]> Co-authored-by: leon-xd <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent a8da554 commit de6622a

File tree

64 files changed

+708
-243
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+708
-243
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,10 @@ That's it! Thank you for your contribution!
8787
8888
The following tools should be installed as a part of the `windows-drivers-rs` developer workflow:
8989
90-
* `cargo-expand`: `cargo install --locked cargo-expand --version 1.0.85`
9190
* `cargo-audit`: `cargo install --locked cargo-audit`
91+
* `cargo-expand`: `cargo install --locked cargo-expand --version 1.0.85`
9292
* `cargo-machete`: `cargo install --locked cargo-machete`
93+
* `cargo-sort`: `cargo install --locked cargo-sort`
9394
* `taplo-cli`: `cargo install --locked taplo-cli`
9495
* `typos-cli`: `cargo install --locked typos-cli`
9596

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ exclude = [
1515
resolver = "3"
1616

1717
[workspace.package]
18-
edition = "2021"
19-
rust-version = "1.84.0"
18+
edition = "2024"
19+
rust-version = "1.85.0"
2020
repository = "https://github.com/microsoft/windows-drivers-rs"
2121
readme = "README.md"
2222
license = "MIT OR Apache-2.0"

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ The crates in this repository are available from [`crates.io`](https://crates.io
127127
PCUNICODE_STRING,
128128
};
129129

130-
#[export_name = "DriverEntry"] // WDF expects a symbol with the name DriverEntry
130+
// SAFETY: "DriverEntry" is the required symbol name for Windows driver entry points.
131+
// No other function in this compilation unit exports this name, preventing symbol conflicts.
132+
#[unsafe(export_name = "DriverEntry")] // WDF expects a symbol with the name DriverEntry
131133
pub unsafe extern "system" fn driver_entry(
132134
driver: PDRIVER_OBJECT,
133135
registry_path: PCUNICODE_STRING,

crates/cargo-wdk/src/actions/build/build_task.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use tracing::debug;
1414
#[double]
1515
use crate::providers::exec::CommandExec;
1616
use crate::{
17-
actions::{build::error::BuildTaskError, to_target_triple, Profile, TargetArch},
17+
actions::{Profile, TargetArch, build::error::BuildTaskError, to_target_triple},
1818
trace,
1919
};
2020

crates/cargo-wdk/src/actions/build/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ mod package_task;
1313
#[cfg(test)]
1414
mod tests;
1515
use std::{
16-
path::{absolute, Path, PathBuf},
16+
path::{Path, PathBuf, absolute},
1717
result::Result::Ok,
1818
};
1919

@@ -26,7 +26,7 @@ use package_task::{PackageTask, PackageTaskParams};
2626
use tracing::{debug, error as err, info, warn};
2727
use wdk_build::metadata::{TryFromCargoMetadataError, Wdk};
2828

29-
use crate::actions::{to_target_triple, Profile, TargetArch};
29+
use crate::actions::{Profile, TargetArch, to_target_triple};
3030
#[double]
3131
use crate::providers::{exec::CommandExec, fs::Fs, metadata::Metadata, wdk_build::WdkBuild};
3232

crates/cargo-wdk/src/actions/build/tests.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ use cargo_metadata::Metadata as CargoMetadata;
1414
use mockall::predicate::eq;
1515
use mockall_double::double;
1616
use wdk_build::{
17-
metadata::{TryFromCargoMetadataError, Wdk},
1817
CpuArchitecture,
1918
DriverConfig,
19+
metadata::{TryFromCargoMetadataError, Wdk},
2020
};
2121

2222
#[double]
@@ -28,10 +28,10 @@ use crate::providers::{
2828
};
2929
use crate::{
3030
actions::{
31-
build::{BuildAction, BuildActionError, BuildActionParams},
32-
to_target_triple,
3331
Profile,
3432
TargetArch,
33+
build::{BuildAction, BuildActionError, BuildActionParams},
34+
to_target_triple,
3535
},
3636
providers::error::{CommandError, FileError},
3737
};
@@ -139,8 +139,8 @@ pub fn given_a_driver_project_when_target_arch_is_arm64_then_it_builds_successfu
139139
}
140140

141141
#[test]
142-
pub fn given_a_driver_project_when_profile_is_release_and_target_arch_is_arm64_then_it_builds_successfully(
143-
) {
142+
pub fn given_a_driver_project_when_profile_is_release_and_target_arch_is_arm64_then_it_builds_successfully()
143+
{
144144
// Input CLI args
145145
let cwd = PathBuf::from("C:\\tmp");
146146
let profile = Some(Profile::Release);
@@ -781,8 +781,8 @@ pub fn given_a_driver_project_when_infverif_command_execution_fails_then_package
781781
}
782782

783783
#[test]
784-
pub fn given_a_non_driver_project_when_default_values_are_provided_with_no_wdk_metadata_are_provided_then_build_should_be_successful(
785-
) {
784+
pub fn given_a_non_driver_project_when_default_values_are_provided_with_no_wdk_metadata_are_provided_then_build_should_be_successful()
785+
{
786786
// Input CLI args
787787
let cwd = PathBuf::from("C:\\tmp");
788788
let profile = None;
@@ -811,8 +811,8 @@ pub fn given_a_non_driver_project_when_default_values_are_provided_with_no_wdk_m
811811
}
812812

813813
#[test]
814-
pub fn given_a_invalid_driver_project_with_partial_wdk_metadata_when_valid_default_values_are_provided_then_wdk_metadata_parse_should_fail(
815-
) {
814+
pub fn given_a_invalid_driver_project_with_partial_wdk_metadata_when_valid_default_values_are_provided_then_wdk_metadata_parse_should_fail()
815+
{
816816
// Input CLI args
817817
let cwd = PathBuf::from("C:\\tmp\\sample-driver");
818818
let profile = None;
@@ -851,8 +851,8 @@ pub fn given_a_invalid_driver_project_with_partial_wdk_metadata_when_valid_defau
851851
/// Workspace tests
852852
////////////////////////////////////////////////////////////////////////////////
853853
#[test]
854-
pub fn given_a_workspace_with_multiple_driver_and_non_driver_projects_when_default_values_are_provided_then_it_packages_successfully(
855-
) {
854+
pub fn given_a_workspace_with_multiple_driver_and_non_driver_projects_when_default_values_are_provided_then_it_packages_successfully()
855+
{
856856
// Input CLI args
857857
let cwd = PathBuf::from("C:\\tmp");
858858
let profile = None;
@@ -923,8 +923,8 @@ pub fn given_a_workspace_with_multiple_driver_and_non_driver_projects_when_defau
923923
}
924924

925925
#[test]
926-
pub fn given_a_workspace_with_multiple_driver_and_non_driver_projects_when_cwd_is_driver_project_then_it_packages_driver_project_successfully(
927-
) {
926+
pub fn given_a_workspace_with_multiple_driver_and_non_driver_projects_when_cwd_is_driver_project_then_it_packages_driver_project_successfully()
927+
{
928928
// Input CLI args
929929
let workspace_root_dir = PathBuf::from("C:\\tmp");
930930
let cwd = workspace_root_dir.join("sample-kmdf-1");
@@ -1011,8 +1011,8 @@ pub fn given_a_workspace_with_multiple_driver_and_non_driver_projects_when_cwd_i
10111011
}
10121012

10131013
#[test]
1014-
pub fn given_a_workspace_with_multiple_driver_and_non_driver_projects_when_verify_signature_is_false_then_it_skips_verify_tasks(
1015-
) {
1014+
pub fn given_a_workspace_with_multiple_driver_and_non_driver_projects_when_verify_signature_is_false_then_it_skips_verify_tasks()
1015+
{
10161016
// Input CLI args
10171017
let cwd = PathBuf::from("C:\\tmp");
10181018
let profile = None;
@@ -1083,8 +1083,8 @@ pub fn given_a_workspace_with_multiple_driver_and_non_driver_projects_when_verif
10831083
}
10841084

10851085
#[test]
1086-
pub fn given_a_workspace_with_multiple_driver_and_non_driver_projects_when_cwd_is_non_driver_project_then_it_builds_but_skips_packaging(
1087-
) {
1086+
pub fn given_a_workspace_with_multiple_driver_and_non_driver_projects_when_cwd_is_non_driver_project_then_it_builds_but_skips_packaging()
1087+
{
10881088
// Input CLI args
10891089
let workspace_root_dir = PathBuf::from("C:\\tmp");
10901090
let cwd = workspace_root_dir.join("non-driver");
@@ -1147,8 +1147,8 @@ pub fn given_a_workspace_with_multiple_driver_and_non_driver_projects_when_cwd_i
11471147
}
11481148

11491149
#[test]
1150-
pub fn given_a_workspace_with_multiple_distinct_wdk_configurations_at_each_workspace_member_level_when_default_values_are_provided_then_wdk_metadata_parse_should_fail(
1151-
) {
1150+
pub fn given_a_workspace_with_multiple_distinct_wdk_configurations_at_each_workspace_member_level_when_default_values_are_provided_then_wdk_metadata_parse_should_fail()
1151+
{
11521152
// Input CLI args
11531153
let cwd = PathBuf::from("C:\\tmp");
11541154
let profile = None;
@@ -1214,8 +1214,8 @@ pub fn given_a_workspace_with_multiple_distinct_wdk_configurations_at_each_works
12141214
}
12151215

12161216
#[test]
1217-
pub fn given_a_workspace_with_multiple_distinct_wdk_configurations_at_root_and_workspace_member_level_when_default_values_are_provided_then_wdk_metadata_parse_should_fail(
1218-
) {
1217+
pub fn given_a_workspace_with_multiple_distinct_wdk_configurations_at_root_and_workspace_member_level_when_default_values_are_provided_then_wdk_metadata_parse_should_fail()
1218+
{
12191219
// Input CLI args
12201220
let cwd = PathBuf::from("C:\\tmp");
12211221
let profile = None;
@@ -1281,8 +1281,8 @@ pub fn given_a_workspace_with_multiple_distinct_wdk_configurations_at_root_and_w
12811281
}
12821282

12831283
#[test]
1284-
pub fn given_a_workspace_only_with_non_driver_projects_when_cwd_is_workspace_root_then_build_should_be_successful(
1285-
) {
1284+
pub fn given_a_workspace_only_with_non_driver_projects_when_cwd_is_workspace_root_then_build_should_be_successful()
1285+
{
12861286
// Input CLI args
12871287
let cwd = PathBuf::from("C:\\tmp");
12881288
let profile = None;
@@ -1318,8 +1318,8 @@ pub fn given_a_workspace_only_with_non_driver_projects_when_cwd_is_workspace_roo
13181318
}
13191319

13201320
#[test]
1321-
pub fn given_a_workspace_only_with_non_driver_projects_when_cwd_is_workspace_member_then_build_should_be_successful(
1322-
) {
1321+
pub fn given_a_workspace_only_with_non_driver_projects_when_cwd_is_workspace_member_then_build_should_be_successful()
1322+
{
13231323
// Input CLI args
13241324
let workspace_root_dir = PathBuf::from("C:\\tmp");
13251325
let cwd = workspace_root_dir.join("non-driver");
@@ -1727,7 +1727,7 @@ impl TestBuildAction {
17271727
&manifest_path,
17281728
]
17291729
.into_iter()
1730-
.map(std::string::ToString::to_string)
1730+
.map(ToString::to_string)
17311731
.collect();
17321732
if let Some(profile) = self.profile {
17331733
expected_cargo_build_args.push("--profile".to_string());

crates/cargo-wdk/src/actions/new/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::{
1515

1616
use clap_verbosity_flag::Verbosity;
1717
use error::NewActionError;
18-
use include_dir::{include_dir, Dir};
18+
use include_dir::{Dir, include_dir};
1919
use mockall_double::double;
2020
use tracing::{debug, info};
2121

crates/cargo-wdk/src/cli.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ use mockall_double::double;
1212
use wdk_build::CpuArchitecture;
1313

1414
use crate::actions::{
15-
build::{BuildAction, BuildActionParams},
16-
new::NewAction,
1715
DriverType,
16+
KMDF_STR,
1817
Profile,
1918
TargetArch,
20-
KMDF_STR,
2119
UMDF_STR,
2220
WDM_STR,
21+
build::{BuildAction, BuildActionParams},
22+
new::NewAction,
2323
};
2424
#[double]
2525
use crate::providers::{exec::CommandExec, fs::Fs, metadata::Metadata, wdk_build::WdkBuild};

crates/cargo-wdk/src/providers/fs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#![allow(clippy::unused_self)]
1212

1313
use std::{
14-
fs::{copy, create_dir, read_dir, rename, DirEntry, File, FileType, OpenOptions},
14+
fs::{DirEntry, File, FileType, OpenOptions, copy, create_dir, read_dir, rename},
1515
io::{Read, Write},
1616
path::Path,
1717
};

crates/cargo-wdk/src/test_utils.rs

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ where
3939

4040
// Remove the env var if value is None
4141
if let Some(value) = value {
42-
std::env::set_var(key, value);
42+
set_var(key, value);
4343
} else {
44-
std::env::remove_var(key);
44+
remove_var(key);
4545
}
4646
}
4747

@@ -51,13 +51,83 @@ where
5151
for (key, _) in env_vars_key_value_pairs {
5252
original_env_vars.get(key).map_or_else(
5353
|| {
54-
std::env::remove_var(key);
54+
remove_var(key);
5555
},
5656
|value| {
57-
std::env::set_var(key, value);
57+
set_var(key, value);
5858
},
5959
);
6060
}
6161

6262
f_return_value
6363
}
64+
65+
/// Safely sets an environment variable. Will not compile if crate is not
66+
/// targeted for Windows.
67+
///
68+
/// This function provides a safe wrapper around [`std::env::set_var`] that
69+
/// became unsafe in Rust 2024 edition.
70+
///
71+
/// # Panics
72+
///
73+
/// This function may panic if key is empty, contains an ASCII equals sign '='
74+
/// or the NUL character '\0', or when value contains the NUL character.
75+
#[cfg(target_os = "windows")]
76+
pub fn set_var<K, V>(key: K, value: V)
77+
where
78+
K: AsRef<OsStr>,
79+
V: AsRef<OsStr>,
80+
{
81+
// SAFETY: this function is only conditionally compiled for windows targets, and
82+
// env::set_var is always safe for windows targets
83+
unsafe {
84+
std::env::set_var(key, value);
85+
}
86+
}
87+
88+
#[cfg(not(target_os = "windows"))]
89+
pub fn set_var<K, V>(_key: K, _value: V)
90+
where
91+
K: AsRef<OsStr>,
92+
V: AsRef<OsStr>,
93+
{
94+
compile_error!(
95+
"windows-drivers-rs is designed to be run on a Windows host machine in a WDK environment. \
96+
Please build using a Windows target."
97+
);
98+
}
99+
100+
/// Safely removes an environment variable. Will not compile if crate is not
101+
/// targeted for Windows.
102+
///
103+
/// This function provides a safe wrapper around [`std::env::remove_var`] that
104+
/// became unsafe in Rust 2024 edition.
105+
///
106+
/// # Panics
107+
///
108+
/// This function may panic if key is empty, contains an ASCII equals sign '='
109+
/// or the NUL character '\0', or when value contains the NUL character.
110+
#[allow(dead_code)]
111+
#[cfg(target_os = "windows")]
112+
pub fn remove_var<K>(key: K)
113+
where
114+
K: AsRef<OsStr>,
115+
{
116+
// SAFETY: this function is only conditionally compiled for windows targets, and
117+
// env::remove_var is always safe for windows targets
118+
unsafe {
119+
std::env::remove_var(key);
120+
}
121+
}
122+
123+
#[allow(dead_code)]
124+
#[cfg(not(target_os = "windows"))]
125+
pub fn remove_var<K>(_key: K)
126+
where
127+
K: AsRef<OsStr>,
128+
{
129+
compile_error!(
130+
"windows-drivers-rs is designed to be run on a Windows host machine in a WDK environment. \
131+
Please build using a Windows target."
132+
);
133+
}

0 commit comments

Comments
 (0)