jet/damon

Generate windows syscalls using `go generate`

justenwalker opened this issue · 0 comments

Use go generate tool to generate windows syscalls instead of writing them out manually.
This will help with maintainability

//go:generate go run golang.org/x/sys/windows/mkwinsyscall -output zsyscall_windows.go syscall_windows.go

Suggestion from #18 (comment) by @zx2c4 with details and examples

By the way, there's an easier way of dealing with all this using //sys. Check it out:

In this file (or in any file, really), I define a bunch of calls like this one:

https://github.com/WireGuard/wireguard-windows/blob/3f40da2044fd468ed05f3902608e62382b81ec9c/tunnel/firewall/syscall_windows.go#L14-L15

And then in this file, I have a go generate directive:

https://github.com/WireGuard/wireguard-windows/blob/3f40da2044fd468ed05f3902608e62382b81ec9c/tunnel/firewall/mksyscall.go#L8

Which winds up creating a file containing the fuction, like:

https://github.com/WireGuard/wireguard-windows/blob/3f40da2044fd468ed05f3902608e62382b81ec9c/tunnel/firewall/zsyscall_windows.go#L39-L52

https://github.com/WireGuard/wireguard-windows/blob/3f40da2044fd468ed05f3902608e62382b81ec9c/tunnel/firewall/zsyscall_windows.go#L90-L100