Skip to content

Remove windows-sys dependency and use direct Win32 bindings#7

Merged
caesay merged 1 commit into
masterfrom
claude/remove-windows-sys-dep-hVUTV
May 9, 2026
Merged

Remove windows-sys dependency and use direct Win32 bindings#7
caesay merged 1 commit into
masterfrom
claude/remove-windows-sys-dep-hVUTV

Conversation

@caesay

@caesay caesay commented May 9, 2026

Copy link
Copy Markdown
Member

Summary

This PR eliminates the windows-sys dependency by introducing a custom winapi module that declares only the Win32 types, constants, and functions actually used by this crate. This reduces external dependencies while maintaining full functionality.

Key Changes

  • New src/winapi.rs module: Contains direct Win32/NT bindings with #[repr(C)]-compatible definitions for:

    • Type aliases (HANDLE, HMODULE, BOOL, FARPROC)
    • Win32 constants (privilege flags, process access rights, file flags, etc.)
    • Structures (LUID, TOKEN_ELEVATION, TOKEN_PRIVILEGES, etc.)
    • Function imports from kernel32.dll and advapi32.dll
  • Updated imports across codebase: Replaced all windows-sys imports with crate::winapi equivalents in:

    • src/lib.rs: is_process_elevated() and set_debug_privilege() functions
    • src/handles.rs: Process and file handle operations
    • src/ntapi.rs: NT API wrapper functions
  • Removed windows-sys dependency: Deleted the entire [target.'cfg(windows)'.dependencies] section from Cargo.toml

Implementation Details

  • The custom bindings use standard Rust FFI conventions (extern "system", #[link] attributes)
  • K32-prefixed functions are properly aliased to their kernel32.dll implementations to avoid requiring psapi.lib
  • All type definitions maintain C-compatible memory layout with #[repr(C)]
  • Linting exceptions are configured for Win32 naming conventions (non_snake_case, non_camel_case_types, etc.)

https://claude.ai/code/session_01P8FHocv1oVuMhaZfsCgMpm

Replace the windows-sys crate with a small src/winapi.rs module that
re-declares only the handful of Win32/NT types, constants, and functions
this crate actually calls. This trims the build graph (no
windows-targets/import-libs pulled in transitively), keeps the public
API unchanged, and links directly against kernel32 + advapi32 (using
the K32-prefixed exports in kernel32 so psapi.lib isn't required).

https://claude.ai/code/session_01P8FHocv1oVuMhaZfsCgMpm
@caesay caesay merged commit a65a7c8 into master May 9, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants