Closed shanduur closed 2 years ago
You can export CGO_ENABLED in the template like it's done for example in v2ray.
@paper42 I don't think so, here is commit:
[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]$
Full log: xbps-src.log
common/environment/build-style/go.sh
sets CGO_ENABLED=1
, you would have to use export CGO_ENABLED=0
in pre_build()
.
This means some packages are doing this wrong, and those could be updated:
Adding the new parameter into the template (
go_cgo_enabled
) that can be translated directly to theCGO_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). When usingCGO_ENABLED=1
, it requires systemd specific header files:Setting
CGO_ENABLED=0
is a way to skip cgo compilation.Proposal: