Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate defaulted foundation feature dependencies #2735

Merged
merged 4 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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