Skip to content

Commit 5881c58

Browse files
authored
Use the sys crate instead of windows crate to limit windows dependency (#38)
* Use the sys crate instead of windows crate for this sys binding * Fix Win32::Security needed for PSID * Reexport windows_sys * Add comment and fix warning * Fix allow(unused_import)
1 parent 3ed67d3 commit 5881c58

File tree

6 files changed

+19
-15
lines changed

6 files changed

+19
-15
lines changed

wslpluginapi-sys/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct-field-names-as-array = { version = "0.3", features = [
3030
"derive",
3131
], optional = true }
3232

33-
[dependencies.windows]
33+
[dependencies.windows-sys]
3434
version = ">0.32"
3535
features = [
3636
"Win32_Foundation",

wslpluginapi-sys/build/WslPluginApi.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/* automatically generated by rust-bindgen 0.72.0 */
22

3-
use windows::core::*;
4-
use windows::Win32::Foundation::*;
5-
use windows::Win32::Networking::WinSock::SOCKET;
6-
use windows::Win32::Security::*;
3+
use windows_sys::core::*;
4+
use windows_sys::Win32::Foundation::*;
5+
use windows_sys::Win32::Networking::WinSock::SOCKET;
6+
#[allow(unused_imports)]
7+
use windows_sys::Win32::Security::*;
78
#[allow(clippy::upper_case_acronyms)]
89
type LPCWSTR = PCWSTR;
910
#[allow(clippy::upper_case_acronyms)]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
896ecb0b3b7e6467e6f4cda3b00201473ed7b7face1a31081671bc32b9e679d3 metadata.json
2-
b8f7209005250c821184da6a11eefc40a84bfc9d44a34cb9bbd1fc302d62e4b4 WslPluginApi.rs
2+
62b630c8c307ef6321c5ca698a79adaca3b6375575de62ebb2d007e73dfc15cc WslPluginApi.rs

wslpluginapi-sys/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
22
mod bindgen;
33
mod manual;
4+
/// Re-export the [windows_sys] crate for use in higher-level crates
5+
pub extern crate windows_sys;
46
pub use crate::bindgen::*;
57
pub use manual::*;

wslpluginapi-sys/src/manual.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use crate::WSLPluginAPIV1;
2-
use windows::core::HRESULT;
3-
use windows::Win32::Foundation::{SEVERITY_ERROR, S_OK};
4-
use windows::Win32::System::Diagnostics::Debug::{FACILITY_CODE, FACILITY_ITF};
2+
use windows_sys::core::HRESULT;
3+
use windows_sys::Win32::Foundation::{SEVERITY_ERROR, S_OK};
4+
use windows_sys::Win32::System::Diagnostics::Debug::{FACILITY_CODE, FACILITY_ITF};
55

66
#[inline(always)]
77
const fn make_hresult(severity: u32, facility: FACILITY_CODE, code: u32) -> HRESULT {
8-
HRESULT(((severity << 31) | (facility.0 << 16) | code) as i32)
8+
((severity << 31) | (facility << 16) | code) as HRESULT
99
}
1010

1111
pub const WSL_E_PLUGIN_REQUIRES_UPDATE: HRESULT =
@@ -60,7 +60,7 @@ pub const unsafe fn require_version(
6060
mod tests {
6161
use super::*;
6262
use crate::{WSLPluginAPIV1, WSLVersion};
63-
use windows::Win32::Foundation::S_OK;
63+
use windows_sys::Win32::Foundation::S_OK;
6464

6565
#[test]
6666
fn test_version_exact_match() {

xtask/src/header_processing.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ pub(crate) fn process<P: AsRef<Path>>(
5454
target: Option<&str>,
5555
) -> anyhow::Result<bindgen::Bindings> {
5656
let mut builder = bindgen::Builder::default()
57-
.raw_line("use windows::core::*;")
58-
.raw_line("use windows::Win32::Foundation::*;")
59-
.raw_line("use windows::Win32::Security::*;")
60-
.raw_line("use windows::Win32::Networking::WinSock::SOCKET;")
57+
.raw_line("use windows_sys::core::*;")
58+
.raw_line("use windows_sys::Win32::Foundation::*;")
59+
.raw_line("#[allow(unused_imports)]")
60+
.raw_line("use windows_sys::Win32::Security::*;")
61+
.raw_line("use windows_sys::Win32::Networking::WinSock::SOCKET;")
6162
.raw_line("#[allow(clippy::upper_case_acronyms)] type LPCWSTR = PCWSTR;")
6263
.raw_line("#[allow(clippy::upper_case_acronyms)] type LPCSTR = PCSTR;")
6364
.raw_line("#[allow(clippy::upper_case_acronyms)] type DWORD = u32;")

0 commit comments

Comments
 (0)