mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
It would be convenient if we did not need to use cgo to compile for FreeBSD for common architectures, allowing builds to be generated in Linux CI flows. The sysctl interface uses offsets which can vary by build architecture, so doing this in the general case without cgo is not realistic. But we can front-load the C work to get the offsets for a given architecture, then use encoding/binary at run-time. While doing this, I saw that the existing FreeBSD code was mis-calculating `%cpu` by converting the `fixpt_t` scaled int straight to a double without dividing by the scaling factor, so we also fix for all other architectures by introducing a division by `FSCALE`. The offsets-emitting code is in `freebsd.txt`, with the filename chosen to keep the Go toolchain from picking it up and trying to compile. The result is unsafe-free cgo-free builds for FreeBSD/amd64.