Skip to content

Commit

Permalink
Generate defaulted foundation feature dependencies (#2735)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr authored Dec 8, 2023
1 parent 469312b commit 831b99b
Show file tree
Hide file tree
Showing 985 changed files with 59,304 additions and 181,066 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
#[cfg(target_pointer_width = "32")]
#[cfg(feature = "Win32_Foundation")]
pub use GetWindowLongA as GetWindowLongPtrA;
#[cfg(target_pointer_width = "32")]
#[cfg(feature = "Win32_Foundation")]
pub use GetWindowLongW as GetWindowLongPtrW;
#[cfg(target_pointer_width = "32")]
#[cfg(feature = "Win32_Foundation")]
pub use SetWindowLongA as SetWindowLongPtrA;
#[cfg(target_pointer_width = "32")]
#[cfg(feature = "Win32_Foundation")]
pub use SetWindowLongW as SetWindowLongPtrW;
4 changes: 4 additions & 0 deletions crates/libs/bindgen/src/rust/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ fn gen_package(writer: &Writer) -> Result<()> {
let dependency = &feature[..pos];

toml.push_str(&format!("{feature} = [\"{dependency}\"]\n"));
} else if tree.namespace.starts_with("Windows.Win32") || tree.namespace.starts_with("Windows.Wdk") {
toml.push_str(&format!("{feature} = [\"Win32_Foundation\"]\n"));
} else if tree.namespace != "Windows.Foundation" {
toml.push_str(&format!("{feature} = [\"Foundation\"]\n"));
} else {
toml.push_str(&format!("{feature} = []\n"));
}
Expand Down
12 changes: 11 additions & 1 deletion crates/libs/bindgen/src/rust/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ impl Writer {
let mut compact = Vec::<&'static str>::new();
if self.package {
for feature in cfg.types.keys() {
if !feature.is_empty() && !starts_with(namespace, feature) {
if !feature.is_empty() && !starts_with(namespace, feature) && !is_defaulted_foundation_feature(namespace, feature) {
for pos in 0..compact.len() {
if starts_with(feature, unsafe { compact.get_unchecked(pos) }) {
compact.remove(pos);
Expand Down Expand Up @@ -1181,6 +1181,16 @@ fn starts_with(namespace: &str, feature: &str) -> bool {
false
}

fn is_defaulted_foundation_feature(namespace: &str, feature: &str) -> bool {
let is_winrt = !starts_with(namespace, "Windows.Win32") && !starts_with(namespace, "Windows.Wdk");

if !is_winrt && feature == "Windows.Win32.Foundation" {
true
} else {
is_winrt && feature == "Windows.Foundation"
}
}

fn gen_mut_ptrs(pointers: usize) -> TokenStream {
"*mut ".repeat(pointers).into()
}
Expand Down
4 changes: 2 additions & 2 deletions crates/libs/sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ path = "../targets"
default = []
docs = []
# generated features
Wdk = []
Wdk = ["Win32_Foundation"]
Wdk_Devices = ["Wdk"]
Wdk_Devices_HumanInterfaceDevice = ["Wdk_Devices"]
Wdk_Foundation = ["Wdk"]
Expand All @@ -42,7 +42,7 @@ Wdk_System_Registry = ["Wdk_System"]
Wdk_System_SystemInformation = ["Wdk_System"]
Wdk_System_SystemServices = ["Wdk_System"]
Wdk_System_Threading = ["Wdk_System"]
Win32 = []
Win32 = ["Win32_Foundation"]
Win32_Data = ["Win32"]
Win32_Data_HtmlHelp = ["Win32_Data"]
Win32_Data_RightsManagement = ["Win32_Data"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
#[cfg(feature = "Win32_Foundation")]
::windows_targets::link!("vhfum.dll" "system" #[doc = "Required features: `\"Win32_Foundation\"`"] fn VhfAsyncOperationComplete(vhfoperationhandle : *const ::core::ffi::c_void, completionstatus : super::super::super::Win32::Foundation:: NTSTATUS) -> super::super::super::Win32::Foundation:: NTSTATUS);
#[cfg(feature = "Win32_Foundation")]
::windows_targets::link!("vhfum.dll" "system" #[doc = "Required features: `\"Win32_Foundation\"`"] fn VhfCreate(vhfconfig : *const VHF_CONFIG, vhfhandle : *mut *mut ::core::ffi::c_void) -> super::super::super::Win32::Foundation:: NTSTATUS);
#[cfg(feature = "Win32_Foundation")]
::windows_targets::link!("vhfum.dll" "system" #[doc = "Required features: `\"Win32_Foundation\"`"] fn VhfDelete(vhfhandle : *const ::core::ffi::c_void, wait : super::super::super::Win32::Foundation:: BOOLEAN));
#[cfg(feature = "Win32_Foundation")]
::windows_targets::link!("vhfum.dll" "system" #[doc = "Required features: `\"Win32_Foundation\"`"] fn VhfReadReportSubmit(vhfhandle : *const ::core::ffi::c_void, hidtransferpacket : *const HID_XFER_PACKET) -> super::super::super::Win32::Foundation:: NTSTATUS);
#[cfg(feature = "Win32_Foundation")]
::windows_targets::link!("vhfum.dll" "system" #[doc = "Required features: `\"Win32_Foundation\"`"] fn VhfStart(vhfhandle : *const ::core::ffi::c_void) -> super::super::super::Win32::Foundation:: NTSTATUS);
::windows_targets::link!("vhfum.dll" "system" fn VhfAsyncOperationComplete(vhfoperationhandle : *const ::core::ffi::c_void, completionstatus : super::super::super::Win32::Foundation:: NTSTATUS) -> super::super::super::Win32::Foundation:: NTSTATUS);
::windows_targets::link!("vhfum.dll" "system" fn VhfCreate(vhfconfig : *const VHF_CONFIG, vhfhandle : *mut *mut ::core::ffi::c_void) -> super::super::super::Win32::Foundation:: NTSTATUS);
::windows_targets::link!("vhfum.dll" "system" fn VhfDelete(vhfhandle : *const ::core::ffi::c_void, wait : super::super::super::Win32::Foundation:: BOOLEAN));
::windows_targets::link!("vhfum.dll" "system" fn VhfReadReportSubmit(vhfhandle : *const ::core::ffi::c_void, hidtransferpacket : *const HID_XFER_PACKET) -> super::super::super::Win32::Foundation:: NTSTATUS);
::windows_targets::link!("vhfum.dll" "system" fn VhfStart(vhfhandle : *const ::core::ffi::c_void) -> super::super::super::Win32::Foundation:: NTSTATUS);
#[repr(C)]
pub struct HID_XFER_PACKET {
pub reportBuffer: *mut u8,
Expand All @@ -21,8 +16,6 @@ impl ::core::clone::Clone for HID_XFER_PACKET {
}
}
#[repr(C)]
#[doc = "Required features: `\"Win32_Foundation\"`"]
#[cfg(feature = "Win32_Foundation")]
pub struct VHF_CONFIG {
pub Size: u32,
pub VhfClientContext: *mut ::core::ffi::c_void,
Expand All @@ -45,9 +38,7 @@ pub struct VHF_CONFIG {
pub HardwareIDsLength: u16,
pub HardwareIDs: ::windows_sys::core::PWSTR,
}
#[cfg(feature = "Win32_Foundation")]
impl ::core::marker::Copy for VHF_CONFIG {}
#[cfg(feature = "Win32_Foundation")]
impl ::core::clone::Clone for VHF_CONFIG {
fn clone(&self) -> Self {
*self
Expand Down
Loading

0 comments on commit 831b99b

Please sign in to comment.