Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report that cgo is required for building for FreeBSD #148

Open
iron-udjin opened this issue Dec 19, 2024 · 7 comments
Open

Report that cgo is required for building for FreeBSD #148

iron-udjin opened this issue Dec 19, 2024 · 7 comments

Comments

@iron-udjin
Copy link

iron-udjin commented Dec 19, 2024

# golang.zx2c4.com/wireguard/wgctrl
/root/go/pkg/mod/golang.zx2c4.com/wireguard/[email protected]/os_freebsd.go:18:27: undefined: wgfreebsd.New
gmake: *** [Makefile:78: build] Error 1

OS: FreeBSD 14.2-RELEASE
Wireguard kernel module if_wg.ko is loaded.

@mdlayher
Copy link
Member

I only have a Linux machine, but do you have cgo disabled by chance? What happens with:

CGO_ENABLED=1 GOOS=freebsd go build ./...

@iron-udjin
Copy link
Author

I'm trying to build https://github.com/h44z/wg-portal

# gmake build
cp scripts/wg-portal.service dist
CGO_ENABLED=0 go build -o dist/wg-portal \
 -ldflags "-w -s -extldflags \"-static\" -X 'github.com/h44z/wg-portal/internal/server.Version=-'" \
 -tags netgo \
 cmd/wg-portal/main.go
# github.com/h44z/wg-portal/internal/lowlevel
internal/lowlevel/netlink.go:57:50: undefined: netlink.FAMILY_V4
internal/lowlevel/netlink.go:62:50: undefined: netlink.FAMILY_V6
internal/lowlevel/netlink.go:99:17: undefined: netlink.RuleAdd
internal/lowlevel/netlink.go:103:17: undefined: netlink.RuleDel
internal/lowlevel/netlink.go:107:17: undefined: netlink.RuleList
# golang.zx2c4.com/wireguard/wgctrl
/root/go/pkg/mod/golang.zx2c4.com/wireguard/[email protected]/os_freebsd.go:18:27: undefined: wgfreebsd.New
gmake: *** [Makefile:78: build] Error 1

@mdlayher
Copy link
Member

cgo being disabled is the problem. The FreeBSD implementation has a hard dependency on cgo at the moment:

package wgfreebsd

// #include <stdlib.h>
// #include <netinet/in.h>
import "C"

// ...

// New creates a new Client and returns whether or not the ioctl interface
// is available.
func New() (*Client, bool, error) {

I can at least try to come up with a shim here that shows a useful compilation error like wgfreebsd.CgoRequiredForFreeBSD not defined.

@iron-udjin
Copy link
Author

I changed CGO_ENABLED=1 in Makefile:

# gmake build
cp scripts/wg-portal.service dist
CGO_ENABLED=1 go build -o dist/wg-portal \
 -ldflags "-w -s -extldflags \"-static\" -X 'github.com/h44z/wg-portal/internal/server.Version=-'" \
 -tags netgo \
 cmd/wg-portal/main.go
# github.com/h44z/wg-portal/internal/lowlevel
internal/lowlevel/netlink.go:57:50: undefined: netlink.FAMILY_V4
internal/lowlevel/netlink.go:62:50: undefined: netlink.FAMILY_V6
internal/lowlevel/netlink.go:99:17: undefined: netlink.RuleAdd
internal/lowlevel/netlink.go:103:17: undefined: netlink.RuleDel
internal/lowlevel/netlink.go:107:17: undefined: netlink.RuleList
gmake: *** [Makefile:78: build] Error 1

I can at least try to come up with a shim here that shows a useful compilation error like

It would be helpful. Thank you.

@mdlayher
Copy link
Member

Yep, so you can see now that wgctrl-go is building. But ultimately the wg-portal code is not using build tags correctly and assuming Linux/netlink implementation, so your next problem lies there.

@iron-udjin
Copy link
Author

iron-udjin commented Dec 19, 2024

Ok, thank you.
I'll report the problem to wg-portal project.
We can close this issue.

P.S: Thank you for the fast response.

@mdlayher
Copy link
Member

No problem, I'll leave it open for now but edit to make the error more clear.

@mdlayher mdlayher changed the title Unable to build under FreeBSD Report that cgo is required for building for FreeBSD Dec 19, 2024
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

No branches or pull requests

2 participants