Skip to content

hwstats: build on darwin without cgo - #1770

Open
xiaoshao9704 wants to merge 1 commit into
livekit:mainfrom
xiaoshao9704:darwin-nocgo-hwstats
Open

hwstats: build on darwin without cgo#1770
xiaoshao9704 wants to merge 1 commit into
livekit:mainfrom
xiaoshao9704:darwin-nocgo-hwstats

Conversation

@xiaoshao9704

Copy link
Copy Markdown

Problem

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, where CGO_ENABLED=0 is required. (Context: an open-source project embedding livekit-server and cross-compiling six OS/arch targets from one linux runner; previously discussed in #659 / #272.)

Change

Three build-tag edits, no new code:

file before after
cpu_all.go (none) !(darwin && !cgo)
cpu_darwin.go darwin darwin && cgo
cpu_null.go !(linux || darwin) !linux && !(darwin && cgo)

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. A changeset is included.

Verification

  • CGO_ENABLED=0 go build ./... for darwin/arm64, darwin/amd64, linux, windows, freebsd — pass
  • CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 go build ./... — pass (unchanged path)
  • go vet ./utils/hwstats/... in both cgo modes — clean
  • go test ./utils/hwstats/... — pass

🤖 Generated with Claude Code

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-bot

changeset-bot Bot commented Sep 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: be4e582

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
github.com/livekit/protocol Patch
@livekit/protocol Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@xiaoshao9704

Copy link
Copy Markdown
Author

FYI: the livekit-server side of this (livekit/livekit#4841, dropping the unused getCPUStats in telemetry) has been merged, so this PR is now the only remaining piece for CGO_ENABLED=0 GOOS=darwin builds to succeed end to end. Happy to rebase or adjust if anything is needed.

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

Successfully merging this pull request may close these issues.

1 participant