#47 Use Fedora's build flags for cgo.
Opened 2 months ago by gotmax23. Modified 2 months ago
gotmax23/go-rpm-macros master  into  master

@@ -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 @@ 

  %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}'" %{?**};

  }

file modified
+2 -1
@@ -350,7 +350,8 @@ 

    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}" }' ..

As promised, here is my PR to set CGO to use Fedoa's build flags. I tested this with golang-github-containerd-btrfs, but it could probably use some more extended testing.

I agree, if you have a copr with more packages it would help. I can look into it at one point too.

I rebuilt all go packages that contain binaries (generated in the same way that I used for the CVE rebuilds) with this applied to go-rpm-macros in gotmax23/go-rpm-macros-cgo on COPR. Then, I built the failures in gotmax23/go-rpm-macros-cgo-control which didn't include these changes. All of the packages that failed to build in the first COPR also failed in the second one.

I rebuilt all go packages that contain binaries (generated in the same way that I used for the CVE rebuilds) with this applied to go-rpm-macros in gotmax23/go-rpm-macros-cgo on COPR. Then, I built the failures in gotmax23/go-rpm-macros-cgo-control which didn't include these changes. All of the packages that failed to build in the first COPR also failed in the second one.

Hmm, I was just looking at this, and it seems that the patch didn't get applied correctly in the COPR. Let me double check this later to make sure that it actually works as expected.

rebased onto 8cba0c6

2 months ago

Thanks so much for your hard work!