cloudflared icon indicating copy to clipboard operation
cloudflared copied to clipboard

🐛compile error( FreeBSD )

Open kinchan opened this issue 1 year ago • 8 comments

Hi, I used FreeBSD 14. Compile error now. Please help


gmake cloudflared

GOOS=freebsd GOARCH=amd64 go build -mod=vendor -ldflags='-X "main.Version=2024.11.1-11-gb3304bf0" -X "main.BuildTime=2024-11-30-2155 UTC" ' github.com/cloudflare/cloudflared/cmd/cloudflared

github.com/cloudflare/cloudflared/cmd/cloudflared/tunnel

cmd/cloudflared/tunnel/cmd.go:559:15: undefined: diagnostic.NewSystemCollectorImpl gmake: *** [Makefile:138: cloudflared] Error 1


kinchan avatar Nov 30 '24 22:11 kinchan

I am on TrueNAS Core Jail with FreeBSD 13.4-RELEASE-p2 and having similar issues with latest and 2024.12.2 tag

gmake cloudflared
GOOS=freebsd GOARCH=amd64  go build -mod=vendor  -ldflags='-X "main.Version=2024.12.2-1-g2714d10d" -X "main.BuildTime=2025-01-05-2240 UTC" ' github.com/cloudflare/cloudflared/cmd/cloudflared
# github.com/cloudflare/cloudflared/diagnostic
diagnostic/diagnostic.go:170:30: undefined: network.NetworkCollectorImpl
gmake: *** [Makefile:138: cloudflared] Error 1

vrtareg avatar Jan 05 '25 22:01 vrtareg

Switching to 2024.11.1 tag helped to build.

vrtareg avatar Jan 05 '25 23:01 vrtareg

This looks like related to folder "diagnostic" which has been added after "2024.11.1" tag. Is it even compatible with FreeBSD?

vrtareg avatar Feb 23 '25 23:02 vrtareg

Hi, The diagnostic code seems to support the official builds only and burns on all the coded but unofficially supported OS like the BSDs. By adding a FreeBSD flavour to the compile and duplicating the Mac SystemCollectorImpl implementation resulted in a successful compile. These steps were tested on the 2025.02.0 release. I would not use the current FreeBSD port version of cloudflared.

Make sure to utilise the Cloudflare GO fork installed using .teamcity/install-cloudflare-go.sh else unsupported crypto messages will prevent connection to CF.

  • Patch 1
--- diagnostic/network/collector_unix.go.orig   2025-02-19 03:35:58 UTC
+++ diagnostic/network/collector_unix.go
@@ -1,4 +1,4 @@
-//go:build darwin || linux
+//go:build darwin || linux || freebsd

 package diagnostic

  • Patch 2
--- diagnostic/network/collector_unix_test.go.orig  2025-02-19 03:36:14 UTC
+++ diagnostic/network/collector_unix_test.go
@@ -1,4 +1,4 @@
-//go:build darwin || linux
+//go:build darwin || linux || freebsd

 package diagnostic_test
  • Copy diagnostic/system_collector_macos.go to diagnostic/system_collector_freebsd.go

  • Patch 3

--- diagnostic/system_collector_freebsd.go.orig   2025-02-19 03:35:59 UTC
+++ diagnostic/system_collector_freebsd.go
@@ -1,4 +1,4 @@
-//go:build darwin
+//go:build freebsd

 package diagnostic

A similar set of changes is needed for OpenBSD.

NothingTooSerious avatar Feb 24 '25 11:02 NothingTooSerious

Hi, NothingTooSerious

Great thank you for your comment. Patch is good. I made latest cloudflared for FreeBSD. Thank you again.

kinchan avatar Feb 25 '25 04:02 kinchan

Thanks a lot @NothingTooSerious

vrtareg avatar Feb 25 '25 06:02 vrtareg

Happy to hear it was of use.

NothingTooSerious avatar Feb 25 '25 14:02 NothingTooSerious

Ah, I didn't notice this issue. I submitted a PR back in January to resolve this for my OPNsense firewall. https://github.com/cloudflare/cloudflared/pull/1396

I just reworked my fork, so I've closed my PR and will leave https://github.com/cloudflare/cloudflared/pull/1421 to handle it.

I didn't need any modifications to the Makefile myself, but I am compiling on FreeBSD 14.1, not cross-compiling, so that could matter. I also made system_collector_unix.go in an attempt to not actually be FreeBSD specific; it was confirmed to compile on FreeBSD 14.1 and openBSD 7.6 for amd64.

Here's my cleaned up release https://github.com/kjake/cloudflared/releases/tag/2025.2.1, which correctly reports version to not confuse the Tunnels dashboard.

kjake avatar Apr 02 '25 02:04 kjake