From 359d80bbfe7f0490fc51c43af8d986863516c5bb Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Jan 21 2022 21:37:16 +0000 Subject: [PATCH 1/2] Fix quote escapes in gobuildflags macro I had to do this in order to get the %gobuild macro to work. --- diff --git a/rpm/macros.d/macros.go-compilers-golang b/rpm/macros.d/macros.go-compilers-golang index e1b5dd2..3b4a01d 100644 --- a/rpm/macros.d/macros.go-compilers-golang +++ b/rpm/macros.d/macros.go-compilers-golang @@ -29,7 +29,7 @@ # # %make GOBUILDFLAGS="%gobuildflags" # -%gobuildflags() %{expand:%{gocompilerflags} -tags=\\"rpm_crashtraceback ${BUILDTAGS:-}\\" -ldflags \\"${LDFLAGS:-} %{?currentgoldflags} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n') -compressdwarf=false -extldflags '%__global_ldflags %{?__golang_extldflags}'\\" -a -v -x} +%gobuildflags() %{expand:%{gocompilerflags} -tags="rpm_crashtraceback ${BUILDTAGS:-}" -ldflags "${LDFLAGS:-} %{?currentgoldflags} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n') -compressdwarf=false -extldflags '%__global_ldflags %{?__golang_extldflags}'" -a -v -x} # Turn off Go modules %gomodulesmode GO111MODULE=off From 8822b49cdf553d0164b44e15176c38e1523622a2 Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Jan 22 2022 03:02:58 +0000 Subject: [PATCH 2/2] Fix build failures due to https://fedoraproject.org/wiki/Changes/SetBuildFlagsBuildCheck The LDFLAGS environment variable is now set for every RPM build, but in Fedora it contains one flag that is not supported by the golang linker. Fix this by filtering out the unsupported flag. --- diff --git a/rpm/macros.d/macros.go-compilers-golang b/rpm/macros.d/macros.go-compilers-golang index 3b4a01d..84d34b3 100644 --- a/rpm/macros.d/macros.go-compilers-golang +++ b/rpm/macros.d/macros.go-compilers-golang @@ -29,7 +29,11 @@ # # %make GOBUILDFLAGS="%gobuildflags" # -%gobuildflags() %{expand:%{gocompilerflags} -tags="rpm_crashtraceback ${BUILDTAGS:-}" -ldflags "${LDFLAGS:-} %{?currentgoldflags} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n') -compressdwarf=false -extldflags '%__global_ldflags %{?__golang_extldflags}'" -a -v -x} + +# Remove unsupported LDFLAGS +%golang_filter_ldflags %(echo "$LDFLAGS" | sed -e 's/-Wl,-z,relro//') + +%gobuildflags() %{expand:%{gocompilerflags} -tags="rpm_crashtraceback ${BUILDTAGS:-}" -ldflags "%{golang_filter_ldflags} %{?currentgoldflags} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n') -compressdwarf=false -extldflags '%__global_ldflags %{?__golang_extldflags}'" -a -v -x} # Turn off Go modules %gomodulesmode GO111MODULE=off @@ -47,4 +51,4 @@ ${workroot}${GOPATH:+:${GOPATH}} # Define commands for testing %gotestflags %{gocompilerflags} %gotestextldflags %__global_ldflags %{?__golang_extldflags} -%gotest() %{?gomodulesmode} go test %{gotestflags} -ldflags "${LDFLAGS:-} %{?currentgoldflags} -extldflags '%{gotestextldflags}'" %{?**}; +%gotest() %{?gomodulesmode} go test %{gotestflags} -ldflags "%{golang_filter_ldflags} %{?currentgoldflags} -extldflags '%{gotestextldflags}'" %{?**};