Skip to content

Commit

Permalink
Simplify how extension code for windows crate works (#3110)
Browse files Browse the repository at this point in the history
  • Loading branch information
sivadeilra authored Jun 18, 2024
1 parent 139ca3c commit d33dcf7
Show file tree
Hide file tree
Showing 45 changed files with 150 additions and 1,818 deletions.
67 changes: 23 additions & 44 deletions crates/libs/bindgen/src/rust/extensions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,55 +1,34 @@
use super::*;

pub fn gen_mod(writer: &Writer, namespace: &str) -> TokenStream {
if namespace == "Windows.Win32.UI.WindowsAndMessaging" {
return include_str!("mod/Win32/UI/WindowsAndMessaging/WindowLong.rs").into();
}

if writer.sys {
return "".into();
/// Helper function for `gen_mod` and `gen_impl`.
///
/// This function generates an `include!(...)` that points into the `src/includes` directory for
/// the `windows` and `windows-sys` crates. This makes it easy to inject code into WinMD namespaces.
#[allow(dead_code)]
fn include_ext(relative_path: &str) -> TokenStream {
quote! {
core::include!(
core::concat!(
core::env!("CARGO_MANIFEST_DIR"),
"/src/includes/",
#relative_path
)
);
}
}

/// Generates extension code for a specific namespace
pub fn gen_mod(_writer: &Writer, namespace: &str) -> TokenStream {
match namespace {
"Windows.Foundation.Numerics" => concat!(
include_str!("mod/Foundation/Numerics/Matrix3x2.rs"),
include_str!("mod/Foundation/Numerics/Matrix4x4.rs"),
include_str!("mod/Foundation/Numerics/Vector2.rs"),
include_str!("mod/Foundation/Numerics/Vector3.rs"),
include_str!("mod/Foundation/Numerics/Vector4.rs"),
),
"Windows.Foundation" => concat!(include_str!("mod/Foundation/TimeSpan.rs"),),
"Windows.Win32.Foundation" => concat!(
include_str!("mod/Win32/Foundation/BOOL.rs"),
include_str!("mod/Win32/Foundation/BOOLEAN.rs"),
include_str!("mod/Win32/Foundation/NTSTATUS.rs"),
include_str!("mod/Win32/Foundation/VARIANT_BOOL.rs"),
include_str!("mod/Win32/Foundation/WIN32_ERROR.rs"),
),
"Windows.Win32.Networking.WinSock" => concat!(
include_str!("mod/Win32/Networking/WinSock/IN_ADDR.rs"),
include_str!("mod/Win32/Networking/WinSock/IN6_ADDR.rs"),
include_str!("mod/Win32/Networking/WinSock/SOCKADDR_IN.rs"),
include_str!("mod/Win32/Networking/WinSock/SOCKADDR_IN6.rs"),
include_str!("mod/Win32/Networking/WinSock/SOCKADDR_INET.rs"),
),
"Windows.Win32.System.Rpc" => include_str!("mod/Win32/System/Rpc/RPC_STATUS.rs"),
"Windows.Win32.System.Com" => include_str!("mod/Win32/System/Com/IDispatch.rs"),
"Windows.Win32.UI.WindowsAndMessaging" => {
include_str!("mod/Win32/UI/WindowsAndMessaging/WindowLong.rs")
include_ext("Win32/UI/WindowsAndMessaging/WindowLong.rs")
}
_ => "",

_ => quote!(),
}
.into()
}

pub fn gen_impl(namespace: &str) -> TokenStream {
match namespace {
"Windows.Foundation.Collections" => concat!(
include_str!("impl/Foundation/Collections/Iterable.rs"),
include_str!("impl/Foundation/Collections/MapView.rs"),
include_str!("impl/Foundation/Collections/VectorView.rs"),
),
_ => "",
}
.into()
/// Generates extension code that is subject to the `implement` feature for a specific namespace
pub fn gen_impl(_namespace: &str) -> TokenStream {
TokenStream::new()
}
Original file line number Diff line number Diff line change
Expand Up @@ -3752,11 +3752,4 @@ pub type SENDASYNCPROC = Option<unsafe extern "system" fn(param0: super::super::
pub type TIMERPROC = Option<unsafe extern "system" fn(param0: super::super::Foundation::HWND, param1: u32, param2: usize, param3: u32)>;
pub type WNDENUMPROC = Option<unsafe extern "system" fn(param0: super::super::Foundation::HWND, param1: super::super::Foundation::LPARAM) -> super::super::Foundation::BOOL>;
pub type WNDPROC = Option<unsafe extern "system" fn(param0: super::super::Foundation::HWND, param1: u32, param2: super::super::Foundation::WPARAM, param3: super::super::Foundation::LPARAM) -> super::super::Foundation::LRESULT>;
#[cfg(target_pointer_width = "32")]
pub use GetWindowLongA as GetWindowLongPtrA;
#[cfg(target_pointer_width = "32")]
pub use GetWindowLongW as GetWindowLongPtrW;
#[cfg(target_pointer_width = "32")]
pub use SetWindowLongA as SetWindowLongPtrA;
#[cfg(target_pointer_width = "32")]
pub use SetWindowLongW as SetWindowLongPtrW;
core::include!(core::concat!(core::env!("CARGO_MANIFEST_DIR"), "/src/includes/", "Win32/UI/WindowsAndMessaging/WindowLong.rs"));
Loading

0 comments on commit d33dcf7

Please sign in to comment.