Github messages for voidlinux
 help / color / mirror / Atom feed
* [ISSUE] [RFC] add support for CGO_ENABLED parameter for Go build style
@ 2022-09-16 13:33 Shanduur
  2022-09-16 13:37 ` paper42
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: Shanduur @ 2022-09-16 13:33 UTC (permalink / raw)
  To: ml

[-- 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}
```

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-09-16 14:53 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-16 13:33 [ISSUE] [RFC] add support for CGO_ENABLED parameter for Go build style Shanduur
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

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).