From: Shanduur <Shanduur@users.noreply.github.com>
To: ml@inbox.vuxu.org
Subject: [ISSUE] [RFC] add support for CGO_ENABLED parameter for Go build style
Date: Fri, 16 Sep 2022 15:33:45 +0200 [thread overview]
Message-ID: <gh-mailinglist-notifications-41a7ca26-5023-4802-975b-f1789d68868e-void-packages-39315@inbox.vuxu.org> (raw)
[-- Attachment #1: Type: text/plain, Size: 2050 bytes --]
New issue by Shanduur on void-packages repository
https://github.com/void-linux/void-packages/issues/39315
Description:
Adding the new parameter into the template (`go_cgo_enabled`) that can be translated directly to the `CGO_ENABLED`. This could be helpful when building packages than can be built with both go and cgo. I have encountered this issue when preparing the package for [promtail (loki client/exporter)](https://grafana.com/docs/loki/latest/clients/promtail/). When using `CGO_ENABLED=1`, it requires systemd specific header files:
```gcc
# github.com/coreos/go-systemd/sdjournal
vendor/github.com/coreos/go-systemd/sdjournal/journal.go:27:11: fatal error: systemd/sd-journal.h: No such file or directory
27 | // #include <systemd/sd-journal.h>
| ^~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
```
Setting `CGO_ENABLED=0` is a way to skip cgo compilation.
Proposal:
```diff
diff --git a/common/build-style/go.sh b/common/build-style/go.sh
index 9093527860..83006a5adf 100644
--- a/common/build-style/go.sh
+++ b/common/build-style/go.sh
@@ -22,6 +22,10 @@ do_configure() {
}
do_build() {
+ if [[ -z ${go_cgo_enabled} ]]; then
+ go_cgo_enabled=1
+ fi
+
# remove -s and -w from go_ldflags, we should let xbps-src strip binaries itself
for wd in $go_ldflags; do
if [ "$wd" == "-s" ] || [ "$wd" == "-w" ]; then
@@ -40,7 +44,7 @@ do_build() {
# default behavior.
go_mod_mode=
fi
- go install -p "$XBPS_MAKEJOBS" -mod="${go_mod_mode}" -x -tags "${go_build_tags}" -ldflags "${go_ldflags}" ${go_package}
+ CGO_ENABLED=${go_cgo_enabled} go install -p "$XBPS_MAKEJOBS" -mod="${go_mod_mode}" -x -tags "${go_build_tags}" -ldflags "${go_ldflags}" ${go_package}
else
# Otherwise, build using GOPATH
go get -p "$XBPS_MAKEJOBS" -x -tags "${go_build_tags}" -ldflags "${go_ldflags}" ${go_package}
```
next reply other threads:[~2022-09-16 13:33 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-16 13:33 Shanduur [this message]
2022-09-16 13:37 ` paper42
2022-09-16 14:01 ` Shanduur
2022-09-16 14:30 ` Shanduur
2022-09-16 14:31 ` Shanduur
2022-09-16 14:31 ` Shanduur
2022-09-16 14:46 ` Duncaen
2022-09-16 14:49 ` Duncaen
2022-09-16 14:53 ` [ISSUE] [CLOSED] " Shanduur
2022-09-16 14:53 ` Shanduur
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=gh-mailinglist-notifications-41a7ca26-5023-4802-975b-f1789d68868e-void-packages-39315@inbox.vuxu.org \
--to=shanduur@users.noreply.github.com \
--cc=ml@inbox.vuxu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).