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 | ^~~~~~~~~~~~~~~~~~~~~~ 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} ```