Skip to content

Commit 793b224

Browse files
committed
Switch to windows-bindgen
1 parent 60309d2 commit 793b224

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ windows = { version = "^0.52", features = ["Win32_Foundation", "Win32_System_Sys
3131
[dev-dependencies]
3232
version-sync = "0.9"
3333

34+
[target.'cfg(target_os = "windows")'.dev-dependencies]
35+
windows-bindgen = { version = "0.61" }
36+
similar-asserts = { version = "1.6.1" }
37+
3438
[package.metadata.docs.rs]
3539
features = ["set"]
3640
rustdoc-args = ["--cfg", "docsrs"]

src/windows/bindings.rs

Whitespace-only changes.
File renamed without changes.

tests/codegen.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#![cfg(windows)]
2+
3+
use std::fs;
4+
use windows_bindgen::bindgen;
5+
6+
#[test]
7+
fn gen_bindings() {
8+
let output = "src/windows/bindings.rs";
9+
let existing = fs::read_to_string(output).unwrap();
10+
11+
bindgen(["--no-deps", "--etc", ARGS]);
12+
13+
// Check the output is the same as before.
14+
// Depending on the git configuration the file may have been checked out with `\r\n` newlines or
15+
// with `\n`. Compare line-by-line to ignore this difference.
16+
let mut new = fs::read_to_string(output).unwrap();
17+
if existing.contains("\r\n") && !new.contains("\r\n") {
18+
new = new.replace("\n", "\r\n");
19+
} else if !existing.contains("\r\n") && new.contains("\r\n") {
20+
new = new.replace("\r\n", "\n");
21+
}
22+
23+
similar_asserts::assert_eq!(existing, new);
24+
if !new.lines().eq(existing.lines()) {
25+
panic!("generated file `{}` is changed.", output);
26+
}
27+
}
28+
29+
const ARGS: &str = r#"--out src/windows/bindings.rs
30+
--flat --sys --no-comment
31+
--filter
32+
ComputerNamePhysicalDnsHostname
33+
GetComputerNameExW"#;

0 commit comments

Comments
 (0)