From f69ba3d2f6958e6fa2048d0492452c6424549711 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Wed, 26 Jun 2024 12:41:28 -0500 Subject: [PATCH] Remove "std" writer from `windows-bindgen` (#3130) --- crates/libs/bindgen/src/rust/functions.rs | 2 +- crates/libs/bindgen/src/rust/mod.rs | 3 +-- crates/libs/bindgen/src/rust/writer.rs | 2 -- crates/tests/standalone/src/b_std.rs | 26 +++++------------------ crates/tools/standalone/src/main.rs | 6 +----- 5 files changed, 8 insertions(+), 31 deletions(-) diff --git a/crates/libs/bindgen/src/rust/functions.rs b/crates/libs/bindgen/src/rust/functions.rs index 1cd841c4c6..5d36295f96 100644 --- a/crates/libs/bindgen/src/rust/functions.rs +++ b/crates/libs/bindgen/src/rust/functions.rs @@ -248,7 +248,7 @@ fn gen_link(writer: &Writer, namespace: &str, signature: &metadata::Signature) - quote! {} }; - if writer.std || !namespace.starts_with("Windows.") { + if !namespace.starts_with("Windows.") { let library = library.trim_end_matches(".dll"); quote! { diff --git a/crates/libs/bindgen/src/rust/mod.rs b/crates/libs/bindgen/src/rust/mod.rs index 6e6116bb56..04d44f43ae 100644 --- a/crates/libs/bindgen/src/rust/mod.rs +++ b/crates/libs/bindgen/src/rust/mod.rs @@ -31,8 +31,7 @@ pub fn from_reader( let mut writer = Writer::new(reader, output); writer.package = config.remove("package").is_some(); writer.flatten = config.remove("flatten").is_some(); - writer.std = config.remove("std").is_some(); - writer.sys = writer.std || config.remove("sys").is_some(); + writer.sys = config.remove("sys").is_some(); writer.implement = config.remove("implement").is_some(); writer.minimal = config.remove("minimal").is_some(); writer.no_inner_attributes = config.remove("no-inner-attributes").is_some(); diff --git a/crates/libs/bindgen/src/rust/writer.rs b/crates/libs/bindgen/src/rust/writer.rs index c37778cd97..80fdd47924 100644 --- a/crates/libs/bindgen/src/rust/writer.rs +++ b/crates/libs/bindgen/src/rust/writer.rs @@ -13,7 +13,6 @@ pub struct Writer { // // Maybe this macro is the embedable version of the IDL format?! like a more intelligient // version of the existing interface macro... - pub std: bool, // tweaks for internal std library support pub sys: bool, // writer sys-style bindings pub flatten: bool, // strips out namespaces - implies !package pub package: bool, // default is single file with no cfg - implies !flatten @@ -33,7 +32,6 @@ impl Writer { output: output.to_string(), namespace: "", implement: false, - std: false, sys: false, flatten: false, package: false, diff --git a/crates/tests/standalone/src/b_std.rs b/crates/tests/standalone/src/b_std.rs index 2e2a55ace9..c390635b1a 100644 --- a/crates/tests/standalone/src/b_std.rs +++ b/crates/tests/standalone/src/b_std.rs @@ -5,27 +5,11 @@ dead_code, clippy::all )] -#[link(name = "advapi32")] -extern "system" { - #[link_name = "SystemFunction036"] - pub fn RtlGenRandom(randombuffer: *mut core::ffi::c_void, randombufferlength: u32) -> BOOLEAN; -} -#[link(name = "kernel32")] -extern "system" { - pub fn CloseHandle(hobject: HANDLE) -> BOOL; -} -#[link(name = "kernel32")] -extern "system" { - pub fn GetLastError() -> WIN32_ERROR; -} -#[link(name = "user32")] -extern "cdecl" { - pub fn wsprintfA(param0: PSTR, param1: PCSTR, ...) -> i32; -} -#[link(name = "ws2_32")] -extern "system" { - pub fn socket(af: i32, r#type: WINSOCK_SOCKET_TYPE, protocol: i32) -> SOCKET; -} +windows_targets::link!("advapi32.dll" "system" "SystemFunction036" fn RtlGenRandom(randombuffer : *mut core::ffi::c_void, randombufferlength : u32) -> BOOLEAN); +windows_targets::link!("kernel32.dll" "system" fn CloseHandle(hobject : HANDLE) -> BOOL); +windows_targets::link!("kernel32.dll" "system" fn GetLastError() -> WIN32_ERROR); +windows_targets::link!("user32.dll" "cdecl" fn wsprintfA(param0 : PSTR, param1 : PCSTR, ...) -> i32); +windows_targets::link!("ws2_32.dll" "system" fn socket(af : i32, r#type : WINSOCK_SOCKET_TYPE, protocol : i32) -> SOCKET); pub type BCRYPT_ALG_HANDLE = *mut core::ffi::c_void; pub type BOOL = i32; pub type BOOLEAN = u8; diff --git a/crates/tools/standalone/src/main.rs b/crates/tools/standalone/src/main.rs index 7c131342b6..5873865a6c 100644 --- a/crates/tools/standalone/src/main.rs +++ b/crates/tools/standalone/src/main.rs @@ -107,7 +107,7 @@ fn main() { ], ); - write_std( + write_sys( &src.join("b_std.rs"), &[ "Windows.Win32.Foundation.CloseHandle", @@ -223,10 +223,6 @@ fn write_win(output: &Path, filter: &[&str]) { riddle(output, filter, &["flatten", "minimal"]); } -fn write_std(output: &Path, filter: &[&str]) { - riddle(output, filter, &["flatten", "std", "minimal"]); -} - fn write_no_inner_attr(output: &Path, filter: &[&str]) { riddle( output,