about summary refs log tree commit diff
path: root/src/tools
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-09-28 13:35:36 +0000
committerbors <bors@rust-lang.org>2023-09-28 13:35:36 +0000
commitdd91aba2fdd8e3b6d9248a401bd6eb2f8d445cdf (patch)
tree5e359c96e33e2f0ce88dbd0ab1b38c268ef85183 /src/tools
parentc01d8d238c57f9847e1f1dd5a1d2659b85e2a468 (diff)
parente7908608d9d11a77b3c73eb1aaac47492575efe9 (diff)
downloadrust-dd91aba2fdd8e3b6d9248a401bd6eb2f8d445cdf.tar.gz
rust-dd91aba2fdd8e3b6d9248a401bd6eb2f8d445cdf.zip
Auto merge of #114882 - ChrisDenton:riddle-me, r=dtolnay
Update windows ffi bindings

Bump `windows-bindgen` to version 0.51.1. This brings with it some changes to the generated FFI bindings, but little that affects the code.

One change that does have more of an impact is `SOCKET` being `usize` instead of either `u64` or `u32` (as is used in std's public `SOCKET` type). However, it's now easy enough to abstract over that difference.

Finally I added a few new bindings that are likely to be used in pending PRs, mostly to make sure they're ok with the new metadata.

r? libs
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/generate-windows-sys/Cargo.toml2
-rw-r--r--src/tools/generate-windows-sys/src/main.rs31
2 files changed, 15 insertions, 18 deletions
diff --git a/src/tools/generate-windows-sys/Cargo.toml b/src/tools/generate-windows-sys/Cargo.toml
index 23e88844bd0..9821677a122 100644
--- a/src/tools/generate-windows-sys/Cargo.toml
+++ b/src/tools/generate-windows-sys/Cargo.toml
@@ -4,4 +4,4 @@ version = "0.1.0"
 edition = "2021"
 
 [dependencies.windows-bindgen]
-version = "0.49"
+version = "0.51.1"
diff --git a/src/tools/generate-windows-sys/src/main.rs b/src/tools/generate-windows-sys/src/main.rs
index 91d981462e8..dff2c5e467a 100644
--- a/src/tools/generate-windows-sys/src/main.rs
+++ b/src/tools/generate-windows-sys/src/main.rs
@@ -1,5 +1,7 @@
+use std::env;
+use std::error::Error;
 use std::fs;
-use std::io::{self, Write};
+use std::io::{self, Read, Seek, Write};
 use std::path::PathBuf;
 
 /// This is printed to the file before the rest of the contents.
@@ -11,25 +13,20 @@ const PRELUDE: &str = r#"// This file is autogenerated.
 // ignore-tidy-filelength
 "#;
 
-fn main() -> io::Result<()> {
+fn main() -> Result<(), Box<dyn Error>> {
     let mut path: PathBuf =
-        std::env::args_os().nth(1).expect("a path to the rust repository is required").into();
-    path.push("library/std/src/sys/windows/c/windows_sys.lst");
+        env::args_os().nth(1).expect("a path to the rust repository is required").into();
+    path.push("library/std/src/sys/windows/c");
+    env::set_current_dir(&path)?;
 
-    // Load the list of APIs
-    let buffer = fs::read_to_string(&path)?;
-    let names: Vec<&str> = buffer
-        .lines()
-        .filter_map(|line| {
-            let line = line.trim();
-            if line.is_empty() || line.starts_with("//") { None } else { Some(line) }
-        })
-        .collect();
+    let info = windows_bindgen::bindgen(["--etc", "windows_sys.lst"])?;
+    println!("{info}");
 
-    // Write the bindings to windows-sys.rs
-    let bindings = windows_bindgen::standalone_std(&names);
-    path.set_extension("rs");
-    let mut f = std::fs::File::create(&path)?;
+    // add some gunk to the output file.
+    let mut f = fs::File::options().read(true).write(true).open("windows_sys.rs")?;
+    let mut bindings = String::new();
+    f.read_to_string(&mut bindings)?;
+    f.seek(io::SeekFrom::Start(0))?;
     f.write_all(PRELUDE.as_bytes())?;
     f.write_all(bindings.as_bytes())?;