Skip to content

Commit

Permalink
Major windows-bindgen update (#3359)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr authored Dec 9, 2024
1 parent 30a574a commit f79d13d
Show file tree
Hide file tree
Showing 1,157 changed files with 1,054,350 additions and 1,157,987 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ jobs:
run: cargo clippy -p test_query_signature
- name: Clippy test_readme
run: cargo clippy -p test_readme
- name: Clippy test_reference
run: cargo clippy -p test_reference
- name: Clippy test_reference_client
run: cargo clippy -p test_reference_client
- name: Clippy test_reference_float
run: cargo clippy -p test_reference_float
- name: Clippy test_registry
Expand Down Expand Up @@ -273,6 +277,8 @@ jobs:
run: cargo clippy -p test_window_long
- name: Clippy test_winrt
run: cargo clippy -p test_winrt
- name: Clippy tool_bindgen
run: cargo clippy -p tool_bindgen
- name: Clippy tool_bindings
run: cargo clippy -p tool_bindings
- name: Clippy tool_gnu
Expand All @@ -295,8 +301,6 @@ jobs:
run: cargo clippy -p windows-implement
- name: Clippy windows-interface
run: cargo clippy -p windows-interface
- name: Clippy windows-metadata
run: cargo clippy -p windows-metadata
- name: Clippy windows-registry
run: cargo clippy -p windows-registry
- name: Clippy windows-result
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ jobs:
-p cppwinrt
-p windows-implement
-p windows-interface
-p windows-metadata
-p windows-registry
-p windows-result
-p windows-strings
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/gen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
tool: [bindings, yml, license, standalone]
tool: [bindgen, bindings, yml, license, standalone]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Update toolchain
run: rustup update --no-self-update stable && rustup default stable
- name: Run
run: cargo run -p tool_${{ matrix.tool }}
run: cargo run -p tool_${{ matrix.tool }} --release
- name: Check
shell: bash
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/msrv-windows-bindgen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
check:
strategy:
matrix:
rust: [1.70.0, stable, nightly]
rust: [1.74.0, stable, nightly]
runs-on:
- windows-latest
- ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/msrv-windows-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
check:
strategy:
matrix:
rust: [1.70.0, stable, nightly]
rust: [1.74.0, stable, nightly]
runs-on:
- windows-latest
- ubuntu-latest
Expand Down
30 changes: 0 additions & 30 deletions .github/workflows/msrv-windows-metadata.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/msrv-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
check:
strategy:
matrix:
rust: [1.70.0, stable, nightly]
rust: [1.74.0, stable, nightly]
runs-on: windows-latest
steps:
- name: Checkout
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/no-default-features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ jobs:
run: cargo check -p windows-implement --no-default-features
- name: Check windows-interface
run: cargo check -p windows-interface --no-default-features
- name: Check windows-metadata
run: cargo check -p windows-metadata --no-default-features
- name: Check windows-registry
run: cargo check -p windows-registry --no-default-features
- name: Check windows-result
Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/raw-dylib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,18 @@ jobs:
run: cargo test -p test_query_signature --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_readme
run: cargo test -p test_readme --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_reference
run: cargo test -p test_reference --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_reference_client
run: cargo test -p test_reference_client --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_reference_float
run: cargo test -p test_reference_float --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Clean
run: cargo clean
- name: Test test_registry
run: cargo test -p test_registry --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_registry_default
run: cargo test -p test_registry_default --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Clean
run: cargo clean
- name: Test test_reserved
run: cargo test -p test_reserved --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_resources
Expand Down Expand Up @@ -304,6 +308,8 @@ jobs:
run: cargo test -p test_window_long --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_winrt
run: cargo test -p test_winrt --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test tool_bindgen
run: cargo test -p tool_bindgen --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test tool_bindings
run: cargo test -p tool_bindings --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test tool_gnu
Expand All @@ -326,8 +332,6 @@ jobs:
run: cargo test -p windows-implement --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test windows-interface
run: cargo test -p windows-interface --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test windows-metadata
run: cargo test -p windows-metadata --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test windows-registry
run: cargo test -p windows-registry --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test windows-result
Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,18 @@ jobs:
run: cargo test -p test_query_signature --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_readme
run: cargo test -p test_readme --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_reference
run: cargo test -p test_reference --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_reference_client
run: cargo test -p test_reference_client --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_reference_float
run: cargo test -p test_reference_float --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Clean
run: cargo clean
- name: Test test_registry
run: cargo test -p test_registry --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_registry_default
run: cargo test -p test_registry_default --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Clean
run: cargo clean
- name: Test test_reserved
run: cargo test -p test_reserved --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_resources
Expand Down Expand Up @@ -301,6 +305,8 @@ jobs:
run: cargo test -p test_window_long --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_winrt
run: cargo test -p test_winrt --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test tool_bindgen
run: cargo test -p tool_bindgen --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test tool_bindings
run: cargo test -p tool_bindings --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test tool_gnu
Expand All @@ -323,8 +329,6 @@ jobs:
run: cargo test -p windows-implement --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test windows-interface
run: cargo test -p windows-interface --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test windows-metadata
run: cargo test -p windows-metadata --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test windows-registry
run: cargo test -p windows-registry --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test windows-result
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ members = [
"crates/samples/windows/*",
"crates/samples/components/*",
"crates/targets/*",
"crates/tests/bindgen",
"crates/tests/misc/*",
"crates/tests/winrt/*",
"crates/tools/*",
Expand All @@ -24,7 +25,6 @@ cppwinrt = { path = "crates/libs/cppwinrt" }
windows = { path = "crates/libs/windows" }
windows-bindgen = { path = "crates/libs/bindgen" }
windows-core = { path = "crates/libs/core" }
windows-metadata = { path = "crates/libs/metadata" }
windows-registry = { path = "crates/libs/registry" }
windows-result = { path = "crates/libs/result" }
windows-strings = { path = "crates/libs/strings" }
Expand Down
21 changes: 2 additions & 19 deletions crates/libs/bindgen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
[package]
name = "windows-bindgen"
version = "0.58.0"
authors = ["Microsoft"]
edition = "2021"
rust-version = "1.70"
rust-version = "1.74"
license = "MIT OR Apache-2.0"
description = "Windows metadata compiler"
description = "Code generator for Windows metadata"
repository = "https://github.com/microsoft/windows-rs"
readme = "readme.md"

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

[features]
default = ["metadata"]
metadata = []

[dependencies]
windows-metadata = { path = "../metadata", version = "0.58.0" }
rayon = "1.7"

[dependencies.proc-macro2]
version = "1.0"
features = ["span-locations"]

[dependencies.serde]
version = "1.0"
features = ["derive"]

[dependencies.serde_json]
version = "1.0"
20 changes: 11 additions & 9 deletions crates/libs/bindgen/readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Generate Rust bindings for Windows
## Code generator for Windows metadata

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

Expand All @@ -16,23 +16,25 @@ version = "0.52"
version = "0.58"
```

Generates Rust bindings in a build script or test as needed:
Generate Rust bindings in a build script as follows:

```rust,ignore
#[test]
fn bindgen() {
```rust,no_run
fn main() {
let args = [
"--out",
"src/bindings.rs",
"--config",
"flatten",
"--flat",
"--filter",
"Windows.Win32.System.SystemInformation.GetTickCount",
"GetTickCount",
];
windows_bindgen::bindgen(args).unwrap();
windows_bindgen::bindgen(args);
}
```

And then use the bindings as follows:

```rust,ignore
mod bindings;
fn main() {
Expand Down
43 changes: 0 additions & 43 deletions crates/libs/bindgen/src/args.rs

This file was deleted.

52 changes: 52 additions & 0 deletions crates/libs/bindgen/src/derive.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use super::*;

pub struct Derive(HashMap<TypeName, Vec<String>>);

impl Derive {
pub fn new(reader: &Reader, types: &TypeMap, derive: &[&str]) -> Self {
let mut map = HashMap::new();

for derive in derive {
let Some((name, derive)) = derive.split_once('=') else {
panic!("`--derive` must be `<type name>=Comma,Separated,List");
};

let tn = get_type_name(reader, name);

if !types.contains_key(&tn) {
panic!("type not included: `{name}`");
}

let derive = derive
.split(',')
.filter(|&derive| (!derive.is_empty()))
.map(|derive| derive.to_string())
.collect();
map.insert(tn, derive);
}

Self(map)
}

pub fn get(&self, type_name: TypeName) -> impl Iterator<Item = String> + '_ {
self.0.get(&type_name).into_iter().flatten().cloned()
}
}

fn get_type_name(reader: &Reader, path: &str) -> TypeName {
if let Some((namespace, name)) = path.rsplit_once('.') {
if let Some((namespace, types)) = reader.get_key_value(namespace) {
if let Some((name, _)) = types.get_key_value(name) {
return TypeName(namespace, name);
}
}
} else {
for (namespace, types) in reader.iter() {
if let Some((name, _)) = types.get_key_value(path) {
return TypeName(namespace, name);
}
}
}

panic!("type not found: `{path}`");
}
Loading

0 comments on commit f79d13d

Please sign in to comment.