Skip to content

Commit

Permalink
update readme and test
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr committed Dec 3, 2024
1 parent b7c2cd5 commit f4a3f4d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 10 deletions.
2 changes: 1 addition & 1 deletion crates/libs/bindgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.58.0"
edition = "2021"
rust-version = "1.74"
license = "MIT OR Apache-2.0"
description = "Windows code generator"
description = "Code generator for Windows metadata"
repository = "https://github.com/microsoft/windows-rs"
readme = "readme.md"

Expand Down
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
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
mod bindings;

fn main() {
Expand Down
3 changes: 3 additions & 0 deletions crates/tests/misc/readme/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ features = [
"Win32_UI_WindowsAndMessaging",
]

[dev-dependencies.windows-bindgen]
workspace = true

[dependencies.windows-targets]
workspace = true

Expand Down
15 changes: 15 additions & 0 deletions crates/tests/misc/readme/src/bindings.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Bindings generated by `windows-bindgen` 0.58.0

#![allow(
non_snake_case,
non_upper_case_globals,
non_camel_case_types,
dead_code,
clippy::all
)]

#[inline]
pub unsafe fn GetTickCount() -> u32 {
windows_targets::link!("kernel32.dll" "system" fn GetTickCount() -> u32);
GetTickCount()
}
1 change: 1 addition & 0 deletions crates/tests/misc/readme/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![doc = include_str!("../../../../libs/bindgen/readme.md")]
#![doc = include_str!("../../../../libs/core/readme.md")]
#![doc = include_str!("../../../../libs/cppwinrt/readme.md")]
#![doc = include_str!("../../../../libs/registry/readme.md")]
Expand Down

0 comments on commit f4a3f4d

Please sign in to comment.