From be4e58271628ebb7bca2c198d1c380f6dc1de228 Mon Sep 17 00:00:00 2001 From: XiaoShao <26596822+xiaoshao9704@users.noreply.github.com> Date: Sat, 5 Sep 2026 13:08:24 +0800 Subject: [PATCH] hwstats: build on darwin without cgo go-osstat only implements its darwin CPU counters behind cgo (its cpu_darwin_nocgo.go is a stub), so `CGO_ENABLED=0 GOOS=darwin go build` fails in utils/hwstats: # github.com/livekit/protocol/utils/hwstats utils/hwstats/cpu_all.go:24:12: undefined: cpu.Stats utils/hwstats/cpu_all.go:28:20: undefined: cpu.Get utils/hwstats/cpu_all.go:39:19: undefined: cpu.Get This blocks cross-compiling darwin binaries from a linux host, which needs CGO_ENABLED=0. Restrict the go-osstat monitor and the darwin platform monitor to cgo builds, and widen the existing null monitor to cover darwin without cgo. That mirrors what the null monitor already does on other unsupported platforms: CPU stats degrade to a no-op and capacity management is disabled, nothing else changes. Builds with cgo enabled are unaffected. --- .changeset/curly-poems-build.md | 6 ++++++ utils/hwstats/cpu_all.go | 2 ++ utils/hwstats/cpu_darwin.go | 2 +- utils/hwstats/cpu_null.go | 2 +- 4 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 .changeset/curly-poems-build.md diff --git a/.changeset/curly-poems-build.md b/.changeset/curly-poems-build.md new file mode 100644 index 000000000..3ddc94cd7 --- /dev/null +++ b/.changeset/curly-poems-build.md @@ -0,0 +1,6 @@ +--- +"github.com/livekit/protocol": patch +"@livekit/protocol": patch +--- + +Build utils/hwstats on darwin without cgo diff --git a/utils/hwstats/cpu_all.go b/utils/hwstats/cpu_all.go index a0568679a..a39579fbe 100644 --- a/utils/hwstats/cpu_all.go +++ b/utils/hwstats/cpu_all.go @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +//go:build !(darwin && !cgo) + package hwstats import ( diff --git a/utils/hwstats/cpu_darwin.go b/utils/hwstats/cpu_darwin.go index 000050151..5aefade25 100644 --- a/utils/hwstats/cpu_darwin.go +++ b/utils/hwstats/cpu_darwin.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build darwin +//go:build darwin && cgo package hwstats diff --git a/utils/hwstats/cpu_null.go b/utils/hwstats/cpu_null.go index 784c45ce2..651111cf3 100644 --- a/utils/hwstats/cpu_null.go +++ b/utils/hwstats/cpu_null.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build !(linux || darwin) +//go:build !linux && !(darwin && cgo) package hwstats