Skip to content

Commit ac30013

Browse files
committed
Automatically sort windows_sys bindings
1 parent 68b8e94 commit ac30013

File tree

3 files changed

+32
-24
lines changed

3 files changed

+32
-24
lines changed

library/std/src/sys/windows/c/bindings.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
--out windows_sys.rs
22
--config flatten std
33
--filter
4-
// tidy-alphabetical-start
54
!Windows.Win32.Foundation.INVALID_HANDLE_VALUE
65
Windows.Wdk.Storage.FileSystem.FILE_COMPLETE_IF_OPLOCKED
76
Windows.Wdk.Storage.FileSystem.FILE_CONTAINS_EXTENDED_CREATE_INFORMATION
@@ -2592,4 +2591,3 @@ Windows.Win32.System.Threading.WakeAllConditionVariable
25922591
Windows.Win32.System.Threading.WakeConditionVariable
25932592
Windows.Win32.System.WindowsProgramming.PROGRESS_CONTINUE
25942593
Windows.Win32.UI.Shell.GetUserProfileDirectoryW
2595-
// tidy-alphabetical-end

library/std/src/sys/windows/c/windows_sys.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
// This file is autogenerated.
2-
//
3-
// To add bindings, edit windows_sys.lst then use `./x run generate-windows-sys` to
4-
// regenerate the bindings.
5-
//
6-
// ignore-tidy-filelength
71
// Bindings generated by `windows-bindgen` 0.52.0
82

93
#![allow(non_snake_case, non_upper_case_globals, non_camel_case_types, dead_code, clippy::all)]
@@ -4351,3 +4345,4 @@ impl ::core::clone::Clone for XSAVE_FORMAT {
43514345
*self
43524346
}
43534347
}
4348+
// ignore-tidy-filelength
+31-16
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,49 @@
11
use std::env;
22
use std::error::Error;
33
use std::fs;
4-
use std::io::{self, Read, Seek, Write};
4+
use std::io::{Read, Seek, SeekFrom, Write};
55
use std::path::PathBuf;
66

7-
/// This is printed to the file before the rest of the contents.
8-
const PRELUDE: &str = r#"// This file is autogenerated.
9-
//
10-
// To add bindings, edit windows_sys.lst then use `./x run generate-windows-sys` to
11-
// regenerate the bindings.
12-
//
13-
// ignore-tidy-filelength
14-
"#;
15-
167
fn main() -> Result<(), Box<dyn Error>> {
178
let mut path: PathBuf =
189
env::args_os().nth(1).expect("a path to the rust repository is required").into();
1910
path.push("library/std/src/sys/windows/c");
2011
env::set_current_dir(&path)?;
2112

22-
let info = windows_bindgen::bindgen(["--etc", "windows_sys.lst"])?;
13+
sort_bindings("bindings.txt")?;
14+
15+
let info = windows_bindgen::bindgen(["--etc", "bindings.txt"])?;
2316
println!("{info}");
2417

25-
// add some gunk to the output file.
26-
let mut f = fs::File::options().read(true).write(true).open("windows_sys.rs")?;
18+
let mut f = std::fs::File::options().append(true).open("windows_sys.rs")?;
19+
writeln!(&mut f, "// ignore-tidy-filelength")?;
20+
21+
Ok(())
22+
}
23+
24+
fn sort_bindings(file_name: &str) -> Result<(), Box<dyn Error>> {
25+
let mut f = fs::File::options().read(true).write(true).open(file_name)?;
2726
let mut bindings = String::new();
2827
f.read_to_string(&mut bindings)?;
29-
f.seek(io::SeekFrom::Start(0))?;
30-
f.write_all(PRELUDE.as_bytes())?;
31-
f.write_all(bindings.as_bytes())?;
28+
f.set_len(0)?;
29+
f.seek(SeekFrom::Start(0))?;
3230

31+
let mut lines = bindings.split_inclusive('\n');
32+
for line in &mut lines {
33+
f.write(line.as_bytes())?;
34+
if line.contains("--filter") {
35+
break;
36+
}
37+
}
38+
let mut bindings = Vec::new();
39+
for line in &mut lines {
40+
if !line.trim().is_empty() {
41+
bindings.push(line);
42+
}
43+
}
44+
bindings.sort_by(|a, b| a.to_lowercase().cmp(&b.to_lowercase()));
45+
for line in bindings {
46+
f.write(line.as_bytes())?;
47+
}
3348
Ok(())
3449
}

0 commit comments

Comments
 (0)