summaryrefslogtreecommitdiffstats
path: root/src/tools/generate-windows-sys
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:42 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:42 +0000
commit837b550238aa671a591ccf282dddeab29cadb206 (patch)
tree914b6b8862bace72bd3245ca184d374b08d8a672 /src/tools/generate-windows-sys
parentAdding debian version 1.70.0+dfsg2-1. (diff)
downloadrustc-837b550238aa671a591ccf282dddeab29cadb206.tar.xz
rustc-837b550238aa671a591ccf282dddeab29cadb206.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/generate-windows-sys')
-rw-r--r--src/tools/generate-windows-sys/Cargo.toml7
-rw-r--r--src/tools/generate-windows-sys/src/main.rs37
2 files changed, 44 insertions, 0 deletions
diff --git a/src/tools/generate-windows-sys/Cargo.toml b/src/tools/generate-windows-sys/Cargo.toml
new file mode 100644
index 000000000..23e88844b
--- /dev/null
+++ b/src/tools/generate-windows-sys/Cargo.toml
@@ -0,0 +1,7 @@
+[package]
+name = "generate-windows-sys"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies.windows-bindgen]
+version = "0.49"
diff --git a/src/tools/generate-windows-sys/src/main.rs b/src/tools/generate-windows-sys/src/main.rs
new file mode 100644
index 000000000..91d981462
--- /dev/null
+++ b/src/tools/generate-windows-sys/src/main.rs
@@ -0,0 +1,37 @@
+use std::fs;
+use std::io::{self, Write};
+use std::path::PathBuf;
+
+/// This is printed to the file before the rest of the contents.
+const PRELUDE: &str = r#"// This file is autogenerated.
+//
+// To add bindings, edit windows_sys.lst then use `./x run generate-windows-sys` to
+// regenerate the bindings.
+//
+// ignore-tidy-filelength
+"#;
+
+fn main() -> io::Result<()> {
+ 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");
+
+ // 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();
+
+ // 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)?;
+ f.write_all(PRELUDE.as_bytes())?;
+ f.write_all(bindings.as_bytes())?;
+
+ Ok(())
+}