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

* Re: [RFC] add support for CGO_ENABLED parameter for Go build style
  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
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: paper42 @ 2022-09-16 13:37 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 223 bytes --]

New comment by paper42 on void-packages repository

https://github.com/void-linux/void-packages/issues/39315#issuecomment-1249376667

Comment:
You can export CGO_ENABLED in the template like it's done for example in v2ray.

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

* Re: [RFC] add support for CGO_ENABLED parameter for Go build style
  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
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Shanduur @ 2022-09-16 14:01 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 2885 bytes --]

New comment by Shanduur on void-packages repository

https://github.com/void-linux/void-packages/issues/39315#issuecomment-1249403203

Comment:
@paper42 I don't think so, [here is commit](https://github.com/void-linux/void-packages/compare/master...Shanduur:void-packages:new-package-promtail):
```
[void@freepc void-packages]$ cat srcpkgs/promtail/template
# Template file for 'promtail'
pkgname=promtail
version=2.6.1
revision=1
wrksrc="loki-${version}"
build_style=go
go_import_path="github.com/grafana/loki"
go_package="${go_import_path}/clients/cmd/promtail"
short_desc="Like Prometheus, but for logs"
maintainer="Mateusz Urbanek <murbanek@shanduur.com>"
license="Apache-2.0"
homepage="https://grafana.com/oss/loki/"
distfiles="https://github.com/grafana/loki/archive/v${version}.tar.gz"
checksum=4b41175e552dd198bb9cae213df3c0d9ca8cacd0b673f79d26419cea7cfb2df7

export CGO_ENABLED=0

pre_build() {
	msg_warn "CGO_ENABLED: got: $(go env CGO_ENABLED), wanted: $(CGO_ENABLED=0 go env CGO_ENABLED)\n"
}
[void@freepc void-packages]$ ./xbps-src pkg promtail
=> xbps-src: updating repositories for host (x86_64-musl)...
[*] Updating repository `https://repo-default.voidlinux.org/current/musl/x86_64-musl-repodata' ...
[*] Updating repository `https://repo-default.voidlinux.org/current/musl/nonfree/x86_64-musl-repodata' ...
[*] Updating repository `https://repo-default.voidlinux.org/current/musl/debug/x86_64-musl-repodata' ...
=> xbps-src: updating software in / masterdir...
=> xbps-src: cleaning up / masterdir...
=> promtail-2.6.1_1: removing autodeps, please wait...
=> promtail-2.6.1_1: building [go] for x86_64-musl...
   [host] go-1.19_1: found (/host/binpkgs/add-grafana-loki)
=> promtail-2.6.1_1: installing host dependencies: go-1.19_1 ...
=> promtail-2.6.1_1: running pre-build hook: 02-script-wrapper ...
=> promtail-2.6.1_1: running pre_build ...
=> WARNING: CGO_ENABLED: got: 1, wanted: 0
=> promtail-2.6.1_1: running do_build ...
=> Using vendor dir for promtail Go dependencies.
WORK=/tmp/go-build987700878
mkdir -p $WORK/b1062/
cd /builddir/loki-2.6.1/vendor/github.com/coreos/go-systemd/sdjournal
TERM='dumb' /usr/lib/go/pkg/tool/linux_amd64/cgo -objdir $WORK/b1062/ -importpath github.com/coreos/go-systemd/sdjournal -- -I $WORK/b1062/ -mtune=generic -O2 -pipe ./journal.go
# 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.
=> ERROR: promtail-2.6.1_1: do_build: 'go install -p "$XBPS_MAKEJOBS" -mod="${go_mod_mode}" -x -tags "${go_build_tags}" -ldflags "${go_ldflags}" ${go_package}' exited with 2
=> ERROR:   in do_build() at common/build-style/go.sh:43
[void@freepc void-packages]$
```

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

* Re: [RFC] add support for CGO_ENABLED parameter for Go build style
  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
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Shanduur @ 2022-09-16 14:30 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 186 bytes --]

New comment by Shanduur on void-packages repository

https://github.com/void-linux/void-packages/issues/39315#issuecomment-1249443110

Comment:
Full log: [Uploading xbps-src.log…]()


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

* Re: [RFC] add support for CGO_ENABLED parameter for Go build style
  2022-09-16 13:33 [ISSUE] [RFC] add support for CGO_ENABLED parameter for Go build style Shanduur
                   ` (2 preceding siblings ...)
  2022-09-16 14:30 ` Shanduur
@ 2022-09-16 14:31 ` Shanduur
  2022-09-16 14:31 ` Shanduur
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Shanduur @ 2022-09-16 14:31 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 186 bytes --]

New comment by Shanduur on void-packages repository

https://github.com/void-linux/void-packages/issues/39315#issuecomment-1249443110

Comment:
Full log: [Uploading xbps-src.log…]()


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

* Re: [RFC] add support for CGO_ENABLED parameter for Go build style
  2022-09-16 13:33 [ISSUE] [RFC] add support for CGO_ENABLED parameter for Go build style Shanduur
                   ` (3 preceding siblings ...)
  2022-09-16 14:31 ` Shanduur
@ 2022-09-16 14:31 ` Shanduur
  2022-09-16 14:46 ` Duncaen
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Shanduur @ 2022-09-16 14:31 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 243 bytes --]

New comment by Shanduur on void-packages repository

https://github.com/void-linux/void-packages/issues/39315#issuecomment-1249444742

Comment:
Full log: [xbps-src.log](https://github.com/void-linux/void-packages/files/9584945/xbps-src.log)


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

* Re: [RFC] add support for CGO_ENABLED parameter for Go build style
  2022-09-16 13:33 [ISSUE] [RFC] add support for CGO_ENABLED parameter for Go build style Shanduur
                   ` (4 preceding siblings ...)
  2022-09-16 14:31 ` Shanduur
@ 2022-09-16 14:46 ` Duncaen
  2022-09-16 14:49 ` Duncaen
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Duncaen @ 2022-09-16 14:46 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 267 bytes --]

New comment by Duncaen on void-packages repository

https://github.com/void-linux/void-packages/issues/39315#issuecomment-1249461270

Comment:
`common/environment/build-style/go.sh` sets `CGO_ENABLED=1`, you would have to use `export CGO_ENABLED=0` in `pre-build()`.

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

* Re: [RFC] add support for CGO_ENABLED parameter for Go build style
  2022-09-16 13:33 [ISSUE] [RFC] add support for CGO_ENABLED parameter for Go build style Shanduur
                   ` (5 preceding siblings ...)
  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
  8 siblings, 0 replies; 10+ messages in thread
From: Duncaen @ 2022-09-16 14:49 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 267 bytes --]

New comment by Duncaen on void-packages repository

https://github.com/void-linux/void-packages/issues/39315#issuecomment-1249461270

Comment:
`common/environment/build-style/go.sh` sets `CGO_ENABLED=1`, you would have to use `export CGO_ENABLED=0` in `pre_build()`.

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

* Re: [ISSUE] [CLOSED] [RFC] add support for CGO_ENABLED parameter for Go build style
  2022-09-16 13:33 [ISSUE] [RFC] add support for CGO_ENABLED parameter for Go build style Shanduur
                   ` (6 preceding siblings ...)
  2022-09-16 14:49 ` Duncaen
@ 2022-09-16 14:53 ` Shanduur
  2022-09-16 14:53 ` Shanduur
  8 siblings, 0 replies; 10+ messages in thread
From: Shanduur @ 2022-09-16 14:53 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 2053 bytes --]

Closed 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

* Re: [RFC] add support for CGO_ENABLED parameter for Go build style
  2022-09-16 13:33 [ISSUE] [RFC] add support for CGO_ENABLED parameter for Go build style Shanduur
                   ` (7 preceding siblings ...)
  2022-09-16 14:53 ` [ISSUE] [CLOSED] " Shanduur
@ 2022-09-16 14:53 ` Shanduur
  8 siblings, 0 replies; 10+ messages in thread
From: Shanduur @ 2022-09-16 14:53 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 253 bytes --]

New comment by Shanduur on void-packages repository

https://github.com/void-linux/void-packages/issues/39315#issuecomment-1249469414

Comment:
This means some packages are doing this wrong, and those could be updated:
- gogs @jprjr 
- v2ray @ipkalm 

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