about summary refs log tree commit diff
path: root/src/tools/generate-windows-sys
diff options
context:
space:
mode:
authorChris Denton <chris@chrisdenton.dev>2023-08-16 09:18:34 +0100
committerChris Denton <chris@chrisdenton.dev>2023-08-28 20:12:00 +0100
commitd9c85daa51bb131696a62a9653debf8ab8d1de07 (patch)
tree88bbc21a106e58f64262b961786494d470620496 /src/tools/generate-windows-sys
parent9f48a8544799c65a597302886d5143456fcb340f (diff)
downloadrust-d9c85daa51bb131696a62a9653debf8ab8d1de07.tar.gz
rust-d9c85daa51bb131696a62a9653debf8ab8d1de07.zip
Update windows ffi bindings
Diffstat (limited to 'src/tools/generate-windows-sys')
-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())?;