Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
88ff017
add _KERNEL_MODE flag to clang parsing
wmmc88 Sep 28, 2023
07f1222
add initial pass of hid apis
wmmc88 Sep 28, 2023
c52b2f3
fix merge conflict
wmmc88 Sep 23, 2024
0915e18
Merge remote-tracking branch 'upstream/main' into hid
wmmc88 Oct 7, 2024
b14bdf3
Merge remote-tracking branch 'upstream/main' into hid
wmmc88 Oct 7, 2024
a1a4bf1
refactor wdk_default to not require header files on disk
wmmc88 Oct 15, 2024
af52971
Merge remote-tracking branch 'upstream/main' into hid
wmmc88 Nov 9, 2024
5a93995
refactor to have a single header for bindgen to process
wmmc88 Jan 10, 2025
951c26f
cargo fmt
wmmc88 Jan 10, 2025
9909386
add missing EOL
wmmc88 Jan 10, 2025
38d4b5f
refactor implementation so that apis are always available to `wdk_bui…
wmmc88 Jan 16, 2025
6b6b080
update workflows to use --all-features flag for Cargo commands
wmmc88 Jan 16, 2025
bf2acfb
Merge remote-tracking branch 'upstream/main' into hid
wmmc88 Jan 16, 2025
e777268
resolve clippy errors
wmmc88 Jan 22, 2025
f4f3a40
enable all-features for local cargo make flow
wmmc88 Jan 22, 2025
1e93870
fix rustdoc lint
wmmc88 Jan 22, 2025
826a4bc
refactor!: rename get_include_paths, get_library_paths, and get_prep…
wmmc88 Jan 22, 2025
5783dbf
Merge remote-tracking branch 'upstream/main' into hid
wmmc88 Jan 22, 2025
8e4e4bb
fix formatting
wmmc88 Jan 22, 2025
c02f27a
fix rustdoc error
wmmc88 Jan 22, 2025
5e50505
remove double inclusion of --all-features when invoking cargo make in CI
wmmc88 Jan 22, 2025
7cf3623
address pr comments
wmmc88 Jan 23, 2025
90a52c2
remove redundant -D warnings
wmmc88 Jan 23, 2025
852532a
fix link
wmmc88 Jan 26, 2025
45a1bbd
Merge remote-tracking branch 'upstream/main' into hid
wmmc88 Jan 29, 2025
7038cd1
fix typo
wmmc88 Jan 29, 2025
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: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
"./tests/umdf-driver-workspace/Cargo.toml",
"./tests/wdk-macros-tests/Cargo.toml",
"./tests/wdk-sys-tests/Cargo.toml",
]
}
],
"rust-analyzer.cargo.features": "all"
}
23 changes: 12 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ wdk-sys = { path = "crates/wdk-sys", version = "0.3.0" }

# External Crates
anyhow = "1.0.86"
bindgen = "0.69.4"
bindgen = "0.69.5"
camino = "1.1.9"
cargo_metadata = "0.18.1"
cc = "1.1.0"
Expand Down
5 changes: 5 additions & 0 deletions crates/wdk-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ windows = { workspace = true, features = [
[dev-dependencies]
windows = { workspace = true, features = ["Win32_UI_Shell"] }

[features]
default = []

hid = []

[lints.rust.unexpected_cfgs]
level = "warn"
check-cfg = ["cfg(wdk_build_unstable)", "cfg(skip_umdf_static_crt_check)"]
Expand Down
18 changes: 3 additions & 15 deletions crates/wdk-build/src/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ pub trait BuilderExt {
///
/// Implementation may return `wdk_build::ConfigError` if it fails to create
/// a builder
fn wdk_default(
c_header_files: Vec<&str>,
config: impl Borrow<Config>,
) -> Result<Builder, ConfigError>;
fn wdk_default(config: impl Borrow<Config>) -> Result<Builder, ConfigError>;
}

#[derive(Debug)]
Expand All @@ -39,19 +36,10 @@ impl BuilderExt for Builder {
///
/// Will return `wdk_build::ConfigError` if any of the resolved include or
/// library paths do not exist
fn wdk_default(
c_header_files: Vec<&str>,
config: impl Borrow<Config>,
) -> Result<Self, ConfigError> {
fn wdk_default(config: impl Borrow<Config>) -> Result<Self, ConfigError> {
let config = config.borrow();

let mut builder = Self::default();

for c_header in c_header_files {
builder = builder.header(c_header);
}

builder = builder
let builder = Self::default()
.use_core() // Can't use std for kernel code
.derive_default(true) // allows for default initializing structs
// CStr types are safer and easier to work with when interacting with string constants
Expand Down
138 changes: 135 additions & 3 deletions crates/wdk-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ impl Config {
Ok(())
}

// TODO: deprecate in favor of include_paths()
/// Return header include paths required to build and link based off of the
/// configuration of `Config`
///
Expand Down Expand Up @@ -411,6 +412,7 @@ impl Config {
Ok(include_paths)
}

// TODO: deprecate in favor of library_paths()
/// Return library include paths required to build and link based off of
/// the configuration of [`Config`].
///
Expand Down Expand Up @@ -498,6 +500,7 @@ impl Config {
Ok(library_paths)
}

// TODO: Deprecate in favor of preprocessor_definitions_iter
/// Return an iterator of strings that represent compiler definitions
/// derived from the `Config`
pub fn get_preprocessor_definitions_iter(
Expand Down Expand Up @@ -541,10 +544,13 @@ impl Config {
.chain(
match self.driver_config {
DriverConfig::Wdm => {
vec![]
vec![
("_KERNEL_MODE", None), // Normally defined by msvc via /kernel flag
]
}
DriverConfig::Kmdf(kmdf_config) => {
let mut kmdf_definitions = vec![
("_KERNEL_MODE", None), // Normally defined by msvc via /kernel flag
("KMDF_VERSION_MAJOR", Some(kmdf_config.kmdf_version_major)),
(
"KMDF_VERSION_MINOR",
Expand Down Expand Up @@ -623,6 +629,134 @@ impl Config {
.map(std::string::ToString::to_string)
}

pub fn base_headers(&self) -> impl Iterator<Item = String> {
match &self.driver_config {
DriverConfig::Wdm | DriverConfig::Kmdf(_) => {
vec!["ntifs.h", "ntddk.h"]
}
DriverConfig::Umdf(_) => {
vec!["windows.h"]
}
}
.into_iter()
.map(std::string::ToString::to_string)
}

pub fn wdf_headers(&self) -> impl Iterator<Item = String> {
["wdf.h"].into_iter().map(std::string::ToString::to_string)
}

#[cfg(feature = "hid")]
pub fn hid_headers(&self) -> impl Iterator<Item = String> {
// HID Headers list from https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/_hid/
{
let mut hid_headers = vec!["hidclass.h", "hidsdi.h", "hidpi.h", "vhf.h"];
if let DriverConfig::Wdm | DriverConfig::Kmdf(_) = self.driver_config {
hid_headers.extend(["hidpddi.h", "hidport.h", "kbdmou.h", "ntdd8042.h"]);
}
if let DriverConfig::Kmdf(_) = self.driver_config {
hid_headers.extend(["HidSpiCx/1.0/hidspicx.h"]);
}
hid_headers
}
.into_iter()
.map(std::string::ToString::to_string)
}

pub fn bindgen_base_header_contents(&self) -> String {
let mut header_contents = self.base_headers().fold(String::new(), |mut acc, header| {
acc.push_str(r#"#include ""#);
acc.push_str(&header);
acc.push_str("\"\n");
acc
});

if let DriverConfig::Wdm | DriverConfig::Kmdf(_) = self.driver_config {
// TODO: Why is there no definition for this struct? Maybe blocklist this struct
// in bindgen.
header_contents.push_str(
r"
typedef union _KGDTENTRY64
{
struct
{
unsigned short LimitLow;
unsigned short BaseLow;
union
{
struct
{
unsigned char BaseMiddle;
unsigned char Flags1;
unsigned char Flags2;
unsigned char BaseHigh;
} Bytes;
struct
{
unsigned long BaseMiddle : 8;
unsigned long Type : 5;
unsigned long Dpl : 2;
unsigned long Present : 1;
unsigned long LimitHigh : 4;
unsigned long System : 1;
unsigned long LongMode : 1;
unsigned long DefaultBig : 1;
unsigned long Granularity : 1;
unsigned long BaseHigh : 8;
} Bits;
};
unsigned long BaseUpper;
unsigned long MustBeZero;
};
unsigned __int64 Alignment;
} KGDTENTRY64, *PKGDTENTRY64;

typedef union _KIDTENTRY64
{
struct
{
unsigned short OffsetLow;
unsigned short Selector;
unsigned short IstIndex : 3;
unsigned short Reserved0 : 5;
unsigned short Type : 5;
unsigned short Dpl : 2;
unsigned short Present : 1;
unsigned short OffsetMiddle;
unsigned long OffsetHigh;
unsigned long Reserved1;
};
unsigned __int64 Alignment;
} KIDTENTRY64, *PKIDTENTRY64;
",
);
}

header_contents
}

pub fn bindgen_wdf_header_contents(&self) -> Option<String> {
if let DriverConfig::Kmdf(_) | DriverConfig::Umdf(_) = self.driver_config {
return Some(self.wdf_headers().fold(String::new(), |mut acc, header| {
acc.push_str(r#"#include ""#);
acc.push_str(&header);
acc.push_str("\"\n");
acc
}));
}
None
}

#[cfg(feature = "hid")]
pub fn bindgen_hid_header_contents(&self) -> String {
self.hid_headers().fold(String::new(), |mut acc, header| {
acc.push_str(r#"#include ""#);
acc.push_str(&header);
acc.push_str("\"\n");
acc
})
}

/// Configure a Cargo build of a library that depends on the WDK. This
/// emits specially formatted prints to Cargo based on this [`Config`].
///
Expand Down Expand Up @@ -839,8 +973,6 @@ impl CpuArchitecture {
}

/// Converts from a cargo-provided [`std::str`] to a [`CpuArchitecture`].
///
/// #
#[must_use]
pub fn try_from_cargo_str<S: AsRef<str>>(cargo_str: S) -> Option<Self> {
// Specifically not using the [`std::convert::TryFrom`] trait to be more
Expand Down
4 changes: 4 additions & 0 deletions crates/wdk-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ anyhow.workspace = true
bindgen.workspace = true
cargo_metadata.workspace = true
cc.workspace = true
cfg-if.workspace = true
lazy_static.workspace = true
serde_json.workspace = true
thiserror.workspace = true
Expand All @@ -35,6 +36,9 @@ wdk-macros.workspace = true

[features]
default = []

hid = ["wdk-build/hid"]

nightly = ["wdk-macros/nightly"]
test-stubs = []

Expand Down
Loading
Loading