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.
rebased onto 359d80bbfe7f0490fc51c43af8d986863516c5bb
This is hackish.
Please also modify the gotest line
-%gotest() %{?gomodulesmode} go test %{gotestflags} -ldflags "${LDFLAGS:-} %{?currentgoldflags} -extldflags '%{gotestextldflags}'" %{?**}; +%gotest() %{?gomodulesmode} go test %{gotestflags} -ldflags "%{golang_filter_ldflags} %{?currentgoldflags} -extldflags '%{gotestextldflags}'" %{?**};
I can't do it myself cause your fork seems locked for edit.
2 new commits added
Fix build failures due to https://fedoraproject.org/wiki/Changes/SetBuildFlagsBuildCheck
Fix quote escapes in gobuildflags macro
@eclipseo Ok, I've update gotest as well. What do you think about removing the escape characters from the quotations? I couldn't get the current master branch to work without doing that, but I assume it must be like that for some reason?
Thank you kindly!
I'm not sure why we had escape characters, I didn't code that part. I'll run some tests.
We may have a problem on some packages. For some of them we redefine LDFLAGS: https://sourcegraph.com/search?q=context:global+r:src.fedoraproject.org+file:.*%5C.spec%24+LDFLAGS%3D%22-X&patternType=regexp&case=yes
This is because our LDFLAGS here should not contains the %optflags but only flags destined to the Go compiler. It is a bug in the macros that should have been solved. It has been question of fixing this by prefixing it by GOLDFLAGS, but there was problem to sync it with c9 stream.
If I do that change, this will require patching several go packages.
I would expect that packages which redefine LDFLAGS are unaffected by the SetBuildFlagsBuildCheck change. What problems is it causing with those packages?
There is no problem with your patch. I will push it.
I'll try fixing our LDFLAGS problem later,
Pull-Request has been merged by eclipseo
It looks like this change did not work as expected. %{golang_filter_ldflags} seems to expand to an empty string.
%{golang_filter_ldflags}
Rpm %() command substitution does not inherit environment variables.
%()
@gota Do you have an example of a build where this fails? It was working for me when I tested it in mock.
It looks like this change did not work as expected. %{golang_filter_ldflags} seems to expand to an empty string. Rpm %() command substitution does not inherit environment variables.
What package? It does not really matter because we shouldn't pass ldflags here.
No builds are completely broken, but redefining LDFLAGS doesn't work. Instead of filtering out -Wl,-z,relro and keeping the rest of the LDFLAGS, %{golang_filter_ldflags} expands to nothing.
-Wl,-z,relro
@gotmax23 OK, can you show me an example build where %{golang_filter_ldflags} expands to nothing? I would like to try to figure out what is going on.
You can look at gh as an example. The specfile contains
gh
export LDFLAGS="-X github.com/cli/cli/v2/internal/build.Version=%{version}-Fedora \ -X github.com/cli/cli/v2/internal/build.Date=$(date -d "@${SOURCE_DATE_EPOCH}" +%Y-%m-%d)"
See below for the output of %gobuild -o %{gobuilddir}/bin/gh %{goipath}/cmd/gh before and after the %set_build_flags change and this patch.
%gobuild -o %{gobuilddir}/bin/gh %{goipath}/cmd/gh
%set_build_flags
--- before 2022-01-27 10:23:37.043713622 -0600 +++ after 2022-01-27 10:23:43.049679273 -0600 @@ -1 +1 @@ -go build -buildmode pie -compiler gc '-tags=rpm_crashtraceback ' -ldflags '-X github.com/cli/cli/v2/internal/build.Version=2.4.0-Fedora -X github.com/cli/cli/v2/internal/build.Date=2022-01-12 -X github.com/cli/cli/v2/version=2.4.0 -B 0x3fc7a0d2a6e88d144a2e228cf80e9a7873f5f977 -compressdwarf=false -extldflags '\''-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--build-id=sha1 '\''' -a -v -x -o /builddir/build/BUILD/cli-2.4.0/_build/bin/gh github.com/cli/cli/v2/cmd/gh +go build -buildmode pie -compiler gc '-tags=rpm_crashtraceback ' -ldflags ' -X github.com/cli/cli/v2/version=2.4.0 -B 0xb50933f80a9206aaf2a818ea51c909c379380ae9 -compressdwarf=false -extldflags '\''-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--build-id=sha1 -Wl,-dT,/builddir/build/BUILD/cli-2.4.0/.package_note-gh-2.4.0-6.fc36.x86_64.ld '\''' -a -v -x -o /builddir/build/BUILD/cli-2.4.0/_build/bin/gh github.com/cli/cli/v2/cmd/gh
You can reproduce this issue by running echo %golang_filter_ldflags in any specfile.
echo %golang_filter_ldflags
@gotmax23 This pull request should fix it: https://pagure.io/go-rpm-macros/pull-request/40
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.