Skip to content

Commit f79d13d

Browse files
authored
Major windows-bindgen update (#3359)
1 parent 30a574a commit f79d13d

File tree

1,157 files changed

+1054350
-1157987
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,157 files changed

+1054350
-1157987
lines changed

.github/workflows/clippy.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@ jobs:
227227
run: cargo clippy -p test_query_signature
228228
- name: Clippy test_readme
229229
run: cargo clippy -p test_readme
230+
- name: Clippy test_reference
231+
run: cargo clippy -p test_reference
232+
- name: Clippy test_reference_client
233+
run: cargo clippy -p test_reference_client
230234
- name: Clippy test_reference_float
231235
run: cargo clippy -p test_reference_float
232236
- name: Clippy test_registry
@@ -273,6 +277,8 @@ jobs:
273277
run: cargo clippy -p test_window_long
274278
- name: Clippy test_winrt
275279
run: cargo clippy -p test_winrt
280+
- name: Clippy tool_bindgen
281+
run: cargo clippy -p tool_bindgen
276282
- name: Clippy tool_bindings
277283
run: cargo clippy -p tool_bindings
278284
- name: Clippy tool_gnu
@@ -295,8 +301,6 @@ jobs:
295301
run: cargo clippy -p windows-implement
296302
- name: Clippy windows-interface
297303
run: cargo clippy -p windows-interface
298-
- name: Clippy windows-metadata
299-
run: cargo clippy -p windows-metadata
300304
- name: Clippy windows-registry
301305
run: cargo clippy -p windows-registry
302306
- name: Clippy windows-result

.github/workflows/doc.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ jobs:
4545
-p cppwinrt
4646
-p windows-implement
4747
-p windows-interface
48-
-p windows-metadata
4948
-p windows-registry
5049
-p windows-result
5150
-p windows-strings

.github/workflows/gen.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ jobs:
1818
runs-on: ubuntu-latest
1919
strategy:
2020
matrix:
21-
tool: [bindings, yml, license, standalone]
21+
tool: [bindgen, bindings, yml, license, standalone]
2222
steps:
2323
- name: Checkout
2424
uses: actions/checkout@v4
2525
- name: Update toolchain
2626
run: rustup update --no-self-update stable && rustup default stable
2727
- name: Run
28-
run: cargo run -p tool_${{ matrix.tool }}
28+
run: cargo run -p tool_${{ matrix.tool }} --release
2929
- name: Check
3030
shell: bash
3131
run: |

.github/workflows/msrv-windows-bindgen.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
check:
1717
strategy:
1818
matrix:
19-
rust: [1.70.0, stable, nightly]
19+
rust: [1.74.0, stable, nightly]
2020
runs-on:
2121
- windows-latest
2222
- ubuntu-latest

.github/workflows/msrv-windows-core.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
check:
1717
strategy:
1818
matrix:
19-
rust: [1.70.0, stable, nightly]
19+
rust: [1.74.0, stable, nightly]
2020
runs-on:
2121
- windows-latest
2222
- ubuntu-latest

.github/workflows/msrv-windows-metadata.yml

Lines changed: 0 additions & 30 deletions
This file was deleted.

.github/workflows/msrv-windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
check:
1717
strategy:
1818
matrix:
19-
rust: [1.70.0, stable, nightly]
19+
rust: [1.74.0, stable, nightly]
2020
runs-on: windows-latest
2121
steps:
2222
- name: Checkout

.github/workflows/no-default-features.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ jobs:
4545
run: cargo check -p windows-implement --no-default-features
4646
- name: Check windows-interface
4747
run: cargo check -p windows-interface --no-default-features
48-
- name: Check windows-metadata
49-
run: cargo check -p windows-metadata --no-default-features
5048
- name: Check windows-registry
5149
run: cargo check -p windows-registry --no-default-features
5250
- name: Check windows-result

.github/workflows/raw-dylib.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,14 +256,18 @@ jobs:
256256
run: cargo test -p test_query_signature --target ${{ matrix.target }} ${{ matrix.etc }}
257257
- name: Test test_readme
258258
run: cargo test -p test_readme --target ${{ matrix.target }} ${{ matrix.etc }}
259+
- name: Test test_reference
260+
run: cargo test -p test_reference --target ${{ matrix.target }} ${{ matrix.etc }}
261+
- name: Test test_reference_client
262+
run: cargo test -p test_reference_client --target ${{ matrix.target }} ${{ matrix.etc }}
259263
- name: Test test_reference_float
260264
run: cargo test -p test_reference_float --target ${{ matrix.target }} ${{ matrix.etc }}
265+
- name: Clean
266+
run: cargo clean
261267
- name: Test test_registry
262268
run: cargo test -p test_registry --target ${{ matrix.target }} ${{ matrix.etc }}
263269
- name: Test test_registry_default
264270
run: cargo test -p test_registry_default --target ${{ matrix.target }} ${{ matrix.etc }}
265-
- name: Clean
266-
run: cargo clean
267271
- name: Test test_reserved
268272
run: cargo test -p test_reserved --target ${{ matrix.target }} ${{ matrix.etc }}
269273
- name: Test test_resources
@@ -304,6 +308,8 @@ jobs:
304308
run: cargo test -p test_window_long --target ${{ matrix.target }} ${{ matrix.etc }}
305309
- name: Test test_winrt
306310
run: cargo test -p test_winrt --target ${{ matrix.target }} ${{ matrix.etc }}
311+
- name: Test tool_bindgen
312+
run: cargo test -p tool_bindgen --target ${{ matrix.target }} ${{ matrix.etc }}
307313
- name: Test tool_bindings
308314
run: cargo test -p tool_bindings --target ${{ matrix.target }} ${{ matrix.etc }}
309315
- name: Test tool_gnu
@@ -326,8 +332,6 @@ jobs:
326332
run: cargo test -p windows-implement --target ${{ matrix.target }} ${{ matrix.etc }}
327333
- name: Test windows-interface
328334
run: cargo test -p windows-interface --target ${{ matrix.target }} ${{ matrix.etc }}
329-
- name: Test windows-metadata
330-
run: cargo test -p windows-metadata --target ${{ matrix.target }} ${{ matrix.etc }}
331335
- name: Test windows-registry
332336
run: cargo test -p windows-registry --target ${{ matrix.target }} ${{ matrix.etc }}
333337
- name: Test windows-result

.github/workflows/test.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,18 @@ jobs:
253253
run: cargo test -p test_query_signature --target ${{ matrix.target }} ${{ matrix.etc }}
254254
- name: Test test_readme
255255
run: cargo test -p test_readme --target ${{ matrix.target }} ${{ matrix.etc }}
256+
- name: Test test_reference
257+
run: cargo test -p test_reference --target ${{ matrix.target }} ${{ matrix.etc }}
258+
- name: Test test_reference_client
259+
run: cargo test -p test_reference_client --target ${{ matrix.target }} ${{ matrix.etc }}
256260
- name: Test test_reference_float
257261
run: cargo test -p test_reference_float --target ${{ matrix.target }} ${{ matrix.etc }}
262+
- name: Clean
263+
run: cargo clean
258264
- name: Test test_registry
259265
run: cargo test -p test_registry --target ${{ matrix.target }} ${{ matrix.etc }}
260266
- name: Test test_registry_default
261267
run: cargo test -p test_registry_default --target ${{ matrix.target }} ${{ matrix.etc }}
262-
- name: Clean
263-
run: cargo clean
264268
- name: Test test_reserved
265269
run: cargo test -p test_reserved --target ${{ matrix.target }} ${{ matrix.etc }}
266270
- name: Test test_resources
@@ -301,6 +305,8 @@ jobs:
301305
run: cargo test -p test_window_long --target ${{ matrix.target }} ${{ matrix.etc }}
302306
- name: Test test_winrt
303307
run: cargo test -p test_winrt --target ${{ matrix.target }} ${{ matrix.etc }}
308+
- name: Test tool_bindgen
309+
run: cargo test -p tool_bindgen --target ${{ matrix.target }} ${{ matrix.etc }}
304310
- name: Test tool_bindings
305311
run: cargo test -p tool_bindings --target ${{ matrix.target }} ${{ matrix.etc }}
306312
- name: Test tool_gnu
@@ -323,8 +329,6 @@ jobs:
323329
run: cargo test -p windows-implement --target ${{ matrix.target }} ${{ matrix.etc }}
324330
- name: Test windows-interface
325331
run: cargo test -p windows-interface --target ${{ matrix.target }} ${{ matrix.etc }}
326-
- name: Test windows-metadata
327-
run: cargo test -p windows-metadata --target ${{ matrix.target }} ${{ matrix.etc }}
328332
- name: Test windows-registry
329333
run: cargo test -p windows-registry --target ${{ matrix.target }} ${{ matrix.etc }}
330334
- name: Test windows-result

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ members = [
66
"crates/samples/windows/*",
77
"crates/samples/components/*",
88
"crates/targets/*",
9+
"crates/tests/bindgen",
910
"crates/tests/misc/*",
1011
"crates/tests/winrt/*",
1112
"crates/tools/*",
@@ -24,7 +25,6 @@ cppwinrt = { path = "crates/libs/cppwinrt" }
2425
windows = { path = "crates/libs/windows" }
2526
windows-bindgen = { path = "crates/libs/bindgen" }
2627
windows-core = { path = "crates/libs/core" }
27-
windows-metadata = { path = "crates/libs/metadata" }
2828
windows-registry = { path = "crates/libs/registry" }
2929
windows-result = { path = "crates/libs/result" }
3030
windows-strings = { path = "crates/libs/strings" }

crates/libs/bindgen/Cargo.toml

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
[package]
22
name = "windows-bindgen"
33
version = "0.58.0"
4-
authors = ["Microsoft"]
54
edition = "2021"
6-
rust-version = "1.70"
5+
rust-version = "1.74"
76
license = "MIT OR Apache-2.0"
8-
description = "Windows metadata compiler"
7+
description = "Code generator for Windows metadata"
98
repository = "https://github.com/microsoft/windows-rs"
109
readme = "readme.md"
1110

@@ -16,21 +15,5 @@ workspace = true
1615
default-target = "x86_64-pc-windows-msvc"
1716
targets = []
1817

19-
[features]
20-
default = ["metadata"]
21-
metadata = []
22-
2318
[dependencies]
24-
windows-metadata = { path = "../metadata", version = "0.58.0" }
2519
rayon = "1.7"
26-
27-
[dependencies.proc-macro2]
28-
version = "1.0"
29-
features = ["span-locations"]
30-
31-
[dependencies.serde]
32-
version = "1.0"
33-
features = ["derive"]
34-
35-
[dependencies.serde_json]
36-
version = "1.0"

crates/libs/bindgen/readme.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Generate Rust bindings for Windows
1+
## Code generator for Windows metadata
22

33
The [windows-bindgen](https://crates.io/crates/windows-bindgen) crate automatically generates Rust bindings from Windows metadata.
44

@@ -16,23 +16,25 @@ version = "0.52"
1616
version = "0.58"
1717
```
1818

19-
Generates Rust bindings in a build script or test as needed:
19+
Generate Rust bindings in a build script as follows:
2020

21-
```rust,ignore
22-
#[test]
23-
fn bindgen() {
21+
```rust,no_run
22+
fn main() {
2423
let args = [
2524
"--out",
2625
"src/bindings.rs",
27-
"--config",
28-
"flatten",
26+
"--flat",
2927
"--filter",
30-
"Windows.Win32.System.SystemInformation.GetTickCount",
28+
"GetTickCount",
3129
];
3230
33-
windows_bindgen::bindgen(args).unwrap();
31+
windows_bindgen::bindgen(args);
3432
}
33+
```
3534

35+
And then use the bindings as follows:
36+
37+
```rust,ignore
3638
mod bindings;
3739
3840
fn main() {

crates/libs/bindgen/src/args.rs

Lines changed: 0 additions & 43 deletions
This file was deleted.

crates/libs/bindgen/src/derive.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
use super::*;
2+
3+
pub struct Derive(HashMap<TypeName, Vec<String>>);
4+
5+
impl Derive {
6+
pub fn new(reader: &Reader, types: &TypeMap, derive: &[&str]) -> Self {
7+
let mut map = HashMap::new();
8+
9+
for derive in derive {
10+
let Some((name, derive)) = derive.split_once('=') else {
11+
panic!("`--derive` must be `<type name>=Comma,Separated,List");
12+
};
13+
14+
let tn = get_type_name(reader, name);
15+
16+
if !types.contains_key(&tn) {
17+
panic!("type not included: `{name}`");
18+
}
19+
20+
let derive = derive
21+
.split(',')
22+
.filter(|&derive| (!derive.is_empty()))
23+
.map(|derive| derive.to_string())
24+
.collect();
25+
map.insert(tn, derive);
26+
}
27+
28+
Self(map)
29+
}
30+
31+
pub fn get(&self, type_name: TypeName) -> impl Iterator<Item = String> + '_ {
32+
self.0.get(&type_name).into_iter().flatten().cloned()
33+
}
34+
}
35+
36+
fn get_type_name(reader: &Reader, path: &str) -> TypeName {
37+
if let Some((namespace, name)) = path.rsplit_once('.') {
38+
if let Some((namespace, types)) = reader.get_key_value(namespace) {
39+
if let Some((name, _)) = types.get_key_value(name) {
40+
return TypeName(namespace, name);
41+
}
42+
}
43+
} else {
44+
for (namespace, types) in reader.iter() {
45+
if let Some((name, _)) = types.get_key_value(path) {
46+
return TypeName(namespace, name);
47+
}
48+
}
49+
}
50+
51+
panic!("type not found: `{path}`");
52+
}

0 commit comments

Comments
 (0)