-
Notifications
You must be signed in to change notification settings - Fork 13.3k
/
Copy pathmain.rs
37 lines (32 loc) · 1.11 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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(())
}