wgctrl-go icon indicating copy to clipboard operation
wgctrl-go copied to clipboard

FreeBSD 32-bit build support

Open hakansa opened this issue 8 months ago • 3 comments

This PR adds support for building and running wgctrl on 32-bit FreeBSD systems.

On 32-bit FreeBSD, size_t and ulong are 32 bits under the ILP32 model, whereas on 64-bit FreeBSD they are 64 bits under LP64. The Go code was previously using uint64 (8 bytes) for WGDataIO.Size (which the C struct expects to be 4 bytes on ILP32), C.ulong to pass buffer lengths to nvlist_unpack, and C.ulong to pass numeric values to nvlist_add_number (which expects a uint64_t). These mismatches cause build failures on ILP32.

Changes

  1. In client_freebsd.go, update WGDataIO.Size from uint64(sz) to uint32(sz). On ILP32 this writes a 32-bit size, matching the C struct. On LP64, uint32(sz) zero-extends appropriately.
  2. In decode.go, change sz := C.ulong(len(d)) to sz := C.size_t(len(d)) so nvlist_unpack always receives exactly a size_t.
  3. In encode.go, change C.nvlist_add_number(nvl, ckey, C.ulong(value)) to C.nvlist_add_number(nvl, ckey, C.uint64_t(value)), ensuring 64-bit numbers are passed correctly on ILP32 and LP64.

hakansa avatar Apr 17 '25 07:04 hakansa

@hakansa you have a commit, go.mod: bump dependencies, adjust CI builds, that seems to have been added later on. Should this be included in this PR? What's the purpose?

jrife avatar Jul 18 '25 14:07 jrife

@jrife

@hakansa you have a commit, go.mod: bump dependencies, adjust CI builds, that seems to have been added later on. Should this be included in this PR? What's the purpose?

it's part of master: a9ab2273dd1

likely when @hakansa committed the requested changes (e.g. https://github.com/WireGuard/wgctrl-go/pull/155#discussion_r2147418762 wgh.SizeT), rather than amending them to their existing commit or making a new commit, they were amended to an unrelated commit at the HEAD of master. cleaning this up with rebase and push --force is left as an exercise to the reader...

billf avatar Sep 05 '25 23:09 billf

is there anythng that i can do the make this pr merged? We have some customers waiting for 32-bit support 👐

hakansa avatar Sep 08 '25 04:09 hakansa