Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tools to generate bindings for library crates #3102

Merged
merged 11 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -258,22 +258,18 @@ jobs:
run: cargo clippy -p test_window_long
- name: Clippy test_winrt
run: cargo clippy -p test_winrt
- name: Clippy tool_bindings
run: cargo clippy -p tool_bindings
- name: Clippy tool_gnu
run: cargo clippy -p tool_gnu
- name: Clippy tool_lib
run: cargo clippy -p tool_lib
- name: Clippy tool_license
run: cargo clippy -p tool_license
- name: Clippy tool_metadata
run: cargo clippy -p tool_metadata
- name: Clippy tool_msvc
run: cargo clippy -p tool_msvc
- name: Clippy tool_standalone
run: cargo clippy -p tool_standalone
- name: Clippy tool_sys
run: cargo clippy -p tool_sys
- name: Clippy tool_windows
run: cargo clippy -p tool_windows
- name: Clippy tool_yml
run: cargo clippy -p tool_yml
- name: Clippy windows
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
tool: [windows, sys, yml, license, metadata, standalone]
tool: [bindings, yml, license, standalone]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -286,22 +286,18 @@ 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_bindings
run: cargo test -p tool_bindings --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test tool_gnu
run: cargo test -p tool_gnu --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test tool_lib
run: cargo test -p tool_lib --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test tool_license
run: cargo test -p tool_license --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test tool_metadata
run: cargo test -p tool_metadata --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test tool_msvc
run: cargo test -p tool_msvc --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test tool_standalone
run: cargo test -p tool_standalone --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test tool_sys
run: cargo test -p tool_sys --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test tool_windows
run: cargo test -p tool_windows --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test tool_yml
run: cargo test -p tool_yml --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test windows
Expand Down
8 changes: 0 additions & 8 deletions crates/libs/core/tests/bindings.rs

This file was deleted.

4 changes: 0 additions & 4 deletions crates/libs/registry/tests/bindings.rs

This file was deleted.

4 changes: 0 additions & 4 deletions crates/libs/result/tests/bindings.rs

This file was deleted.

4 changes: 0 additions & 4 deletions crates/libs/version/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,3 @@ targets = []
[dependencies.windows-targets]
version = "0.52.5"
path = "../targets"

[dev-dependencies.windows-bindgen]
version = "0.57.0"
path = "../bindgen"
18 changes: 0 additions & 18 deletions crates/libs/version/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,4 @@ mod test {
assert!(OsVersion::current() >= OsVersion::new(10, 100, 1_000, 10_000));
assert!(!(OsVersion::current() >= OsVersion::new(10, 100, 1_000, 10_001)));
}

#[test]
fn bindgen() {
let args = [
"--out",
"src/bindings.rs",
"--config",
"flatten",
"sys",
"no-bindgen-comment",
"--filter",
"Windows.Wdk.System.SystemServices.RtlGetVersion",
"Windows.Win32.System.SystemInformation.OSVERSIONINFOEXW",
"Windows.Win32.System.SystemServices.VER_NT_WORKSTATION",
];

windows_bindgen::bindgen(args).unwrap();
}
}
8 changes: 8 additions & 0 deletions crates/tools/bindings/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "tool_bindings"
version = "0.0.0"
edition = "2021"
publish = false

[dependencies]
windows-bindgen = { path = "../../libs/bindgen" }
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// These will use `windows-sys` style bindings.

--out src/imp/bindings.rs
--out crates/libs/core/src/imp/bindings.rs
--config flatten sys minimal no-bindgen-comment

--filter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// These will use `windows` style bindings and include COM APIs.

--out src/imp/com_bindings.rs
--out crates/libs/core/src/imp/com_bindings.rs
--config flatten minimal no-bindgen-comment

--filter
Expand Down
19 changes: 19 additions & 0 deletions crates/tools/bindings/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use windows_bindgen::*;

fn main() -> Result<()> {
run("crates/tools/bindings/src/core_com.txt")?;
run("crates/tools/bindings/src/core.txt")?;
run("crates/tools/bindings/src/metadata.txt")?;
run("crates/tools/bindings/src/registry.txt")?;
run("crates/tools/bindings/src/result.txt")?;
run("crates/tools/bindings/src/sys.txt")?;
run("crates/tools/bindings/src/version.txt")?;
run("crates/tools/bindings/src/windows.txt")?;
Ok(())
}

fn run(path: &str) -> Result<()> {
println!("{path}");
bindgen(["--etc", path])?;
Ok(())
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
--in crates/libs/bindgen/default
--out crates/libs/metadata/src/bindings.rs
--config flatten sys minimal no-bindgen-comment

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
--out src/bindings.rs
--out crates/libs/registry/src/bindings.rs
--config flatten sys minimal no-bindgen-comment

--filter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
--out src/bindings.rs
--out crates/libs/result/src/bindings.rs
--config flatten sys minimal vtbl no-bindgen-comment

--filter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
--in crates/libs/bindgen/default
--out crates/libs/sys/src/lib.rs
--config package sys no-bindgen-comment
--config rustfmt-config=max_width=800,newline_style=Unix
Expand Down
7 changes: 7 additions & 0 deletions crates/tools/bindings/src/version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
--out crates/libs/version/src/bindings.rs
--config flatten sys no-bindgen-comment

--filter
Windows.Wdk.System.SystemServices.RtlGetVersion
Windows.Win32.System.SystemInformation.OSVERSIONINFOEXW
Windows.Win32.System.SystemServices.VER_NT_WORKSTATION
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
--in crates/libs/bindgen/default
--out crates/libs/windows/src/lib.rs
--config package no-bindgen-comment
--config prepend:Windows.Win32.Foundation.WIN32_ERROR=#[must_use]
Expand Down
5 changes: 0 additions & 5 deletions crates/tools/metadata/Cargo.toml

This file was deleted.

14 changes: 0 additions & 14 deletions crates/tools/metadata/src/main.rs

This file was deleted.

5 changes: 0 additions & 5 deletions crates/tools/sys/Cargo.toml

This file was deleted.

14 changes: 0 additions & 14 deletions crates/tools/sys/src/main.rs

This file was deleted.

5 changes: 0 additions & 5 deletions crates/tools/windows/Cargo.toml

This file was deleted.

14 changes: 0 additions & 14 deletions crates/tools/windows/src/main.rs

This file was deleted.