From 8cba0c6d03530fa3d02e706e7a6c9ad075855ad6 Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Jul 03 2022 05:56:47 +0000 Subject: Use Fedora's build flags for cgo. --- diff --git a/rpm/macros.d/macros.go-compilers-golang b/rpm/macros.d/macros.go-compilers-golang index 74428a3..5630c0f 100644 --- a/rpm/macros.d/macros.go-compilers-golang +++ b/rpm/macros.d/macros.go-compilers-golang @@ -31,6 +31,9 @@ # %gobuildflags() %{expand:%{gocompilerflags} -tags="rpm_crashtraceback ${BUILDTAGS:-}" -ldflags "${LDFLAGS:-} %{?currentgoldflags} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n') -compressdwarf=false -linkmode=external -extldflags '%{build_ldflags} %{?__golang_extldflags}'" -a -v -x} +%cgo_set_build_flags export CGO_CFLAGS="%{build_cflags}" CGO_CPPFLAGS="%{build_cxxflags}" CGO_FFLAGS="%{build_fflags}" CGO_LDFLAGS="%{build_ldflags}" + + # Turn off Go modules %gomodulesmode GO111MODULE=off @@ -43,6 +46,7 @@ %undefine _auto_set_build_flags # https://bugzilla.redhat.com/show_bug.cgi?id=995136#c12 %global _dwz_low_mem_die_limit 0 + %cgo_set_build_flags %{?gobuilddir:GOPATH="%{gobuilddir}:${GOPATH:+${GOPATH}:}%{?gopath}"} %{?gomodulesmode} \\ go build %{gobuildflags} %{?**}; } @@ -53,5 +57,6 @@ ${workroot}${GOPATH:+:${GOPATH}} %gotestextldflags %{build_ldflags} %{?__golang_extldflags} %gotest() %{expand: %undefine _auto_set_build_flags + %cgo_set_build_flags %{?gomodulesmode} go test %{gotestflags} -ldflags "${LDFLAGS:-} %{?currentgoldflags} -extldflags '%{gotestextldflags}'" %{?**}; } diff --git a/rpm/macros.d/macros.go-rpm b/rpm/macros.d/macros.go-rpm index 8890023..aad857e 100644 --- a/rpm/macros.d/macros.go-rpm +++ b/rpm/macros.d/macros.go-rpm @@ -350,7 +350,8 @@ local function process(suffix) if (suffix ~= "") and (suffix ~= nil) then zsuffix = "-z " .. suffix .. " " end - print(rpm.expand('%goenv ' .. zsuffix .. myenvflags .. '\\n' .. + print(rpm.expand('%cgo_set_build_flags' .. '\\n' .. + '%goenv ' .. zsuffix .. myenvflags .. '\\n' .. '%{?currentgoldflags:LDFLAGS="${LDFLAGS} %{?currentgoldflags}" }' .. '%{?gotestflags:GO_TEST_FLAGS="%{gotestflags}" }' .. '%{?gotestextldflags:GO_TEST_EXT_LD_FLAGS="%{gotestextldflags}" }' ..