-
Notifications
You must be signed in to change notification settings - Fork 2
/
bindgen.ps1
48 lines (41 loc) · 1.48 KB
/
bindgen.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Description: Generate Rust bindings for Wintun using bindgen
# Usage: Run this script from the root of the wintun-bindings crate
bindgen `
--allowlist-function "Wintun.*" `
--allowlist-type "WINTUN_.*" `
--allowlist-var "WINTUN_.*" `
--blocklist-type "_GUID" `
--blocklist-type "BOOL" `
--blocklist-type "BYTE" `
--blocklist-type "DWORD" `
--blocklist-type "DWORD64" `
--blocklist-type "GUID" `
--blocklist-type "HANDLE" `
--blocklist-type "LPCWSTR" `
--blocklist-type "NET_LUID" `
--blocklist-type "WCHAR" `
--blocklist-type "wchar_t" `
--opaque-type "NET_LUID" `
--dynamic-loading wintun `
--dynamic-link-require-all wintun/include/wintun_functions.h > src/wintun_raw.rs `
-- --target=i686-pc-windows-msvc
# Insert prelude to generated file
$prelude = @'
#![allow(non_snake_case, non_camel_case_types)]
#![cfg(target_os = "windows")]
use windows_sys::core::GUID;
use windows_sys::core::PCWSTR as LPCWSTR;
use windows_sys::Win32::Foundation::BOOL;
use windows_sys::Win32::Foundation::HANDLE;
use windows_sys::Win32::NetworkManagement::Ndis::NET_LUID_LH as NET_LUID;
pub type DWORD = core::ffi::c_ulong;
pub type BYTE = core::ffi::c_uchar;
pub type DWORD64 = core::ffi::c_ulonglong;
'@
# Write prelude to a tmp file
$tmpFile = "src/wintun_raw.rs.tmp"
$prelude | Out-File -FilePath $tmpFile -Encoding utf8
# Append generated file to tmp file
Get-Content src/wintun_raw.rs | Add-Content -Path $tmpFile
# Replace generated file with tmp file
Move-Item -Path $tmpFile -Destination src/wintun_raw.rs -Force