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

feat: always disable cgo support (static builds) #12600

Merged
merged 1 commit into from
Feb 3, 2023

Conversation

powersj
Copy link
Contributor

@powersj powersj commented Feb 2, 2023

This ensures that cgo is always disabled with builds using the Makefile. Telegraf does not support importing C libraries or depending on any of them in the first place. This is to ensure cross-platform and cross-OS support.

Our official builds for Windows, macOS, and BSD are cross-compiled. In these cases, cgo is already disabled. This primarily affects the linux builds. This will enable us to deliver the much requested arm64 docker images for Alpine.

In #8278, a check for the glibc version was added after a user noticed the binary was depending on newer versions of glibc. This removes those checks as static builds will not need these checks.

Finally, this removes the no longer necessary static specific build.

fixes: #8997

@telegraf-tiger telegraf-tiger bot added the feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin label Feb 2, 2023
This ensures that cgo is always disabled with builds using
the Makefile. Telegraf does not support importing C libraries
or depending on any of them in the first place. This is to
ensure cross-platform and cross-OS support.

Our official builds for Windows, macOS, and BSD are
cross-compiled. In these cases, cgo is already disabled. This
primarily affects the linux builds. This will enable us to deliver
the much requested arm64 docker images for Alpine.

In influxdata#8278, a check for the glibc version was added after a
user noticed the binary was depending on newer versions of
glibc. This removes those checks as static builds will not need
these checks.

Finally, this removes the no longer necessary static specific
build.
@telegraf-tiger
Copy link
Contributor

telegraf-tiger bot commented Feb 2, 2023

@powersj powersj marked this pull request as ready for review February 2, 2023 16:27
Copy link
Contributor

@jdstrand jdstrand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll let @srebhan comment on the specifics, but I looked over the PR and it looks reasonable. I'm a fan of disabling CGO unless it is absolutely required and this should improve portability and maintenance in general.

Fyi, in an Ubuntu 20.04 container, I ran make and CGO is disabled:

$ make
...
CGO_ENABLED=0 go build -ldflags " -X github.com/influxdata/telegraf/internal.Commit=c6976f77 -X github.com/influxdata/telegraf/internal.Branch=HEAD -X github.com/influxdata/telegraf/internal.Version=1.26.0-c6976f77" ./cmd/telegraf
$ go version -m ./telegraf | grep CGO_ENABLED
	build	CGO_ENABLED=0

# compare to current deb
$ go version -m ./usr/bin/telegraf |grep CGO_ENABLED
	build	CGO_ENABLED=1

Copy link
Contributor

@srebhan srebhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I guess we need to use go env -w CGO_ENABLED="0" to make this work on windows. I'll test that later...

@srebhan srebhan merged commit d137d97 into influxdata:master Feb 3, 2023
powersj added a commit to powersj/telegraf that referenced this pull request Mar 13, 2023
This should not have been removed and not sure why it was part of a
previous PR.

fixes: influxdata#12600
@srebhan srebhan added this to the v1.26.0 milestone Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Binary portability / CGO_ENABLED
3 participants