This decides on requiring Golang >= 1.11, since that introduces the new standard concept of "Go modules": https://blog.golang.org/using-go-modules Previously such a concept was dealt with by any number of external 3rd party. These didn't seemlessly integrate into the go toolchain in the way modules do. The particularly attractive benefits of Go modules are - You are /not/ forced to use a particular directory hierarchy that matches your package import name. - Independent of any global $GOPATH which may or may not be set in your user sesion. - External dependencies do not need vendoring (copying) into the libvirt source tree. The toolchain downloads (with local caching) as needed, or can be pointed to a local OS distro provided copy Right now Fedora's Go packaging does not support Go modules, and obviously doesn't dynamically download packages during build. Thus in the RPM we need to turn off the normal Go module support and point it at the local copies of deps, provided by RPMs. This is still static linking, but without the deps being bundled in libvirt's src.rpm. Fedora also does not yet have the %gobuildflags macro defined, so in the short term we must define the desired Go build flags to ensure debuginfo RPMs work. Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx> --- configure.ac | 1 + libvirt.spec.in | 19 ++++++++++++++++++- m4/virt-golang.m4 | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 m4/virt-golang.m4 diff --git a/configure.ac b/configure.ac index af8cbcdfd8..b835a10698 100644 --- a/configure.ac +++ b/configure.ac @@ -511,6 +511,7 @@ LIBVIRT_ARG_TLS_PRIORITY LIBVIRT_ARG_SYSCTL_CONFIG +LIBVIRT_CHECK_GOLANG LIBVIRT_CHECK_DEBUG LIBVIRT_CHECK_DTRACE LIBVIRT_CHECK_NUMAD diff --git a/libvirt.spec.in b/libvirt.spec.in index 7f5183f341..1c74dbb252 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -401,6 +401,8 @@ BuildRequires: libtirpc-devel BuildRequires: firewalld-filesystem %endif +BuildRequires: golang >= 1.11 + Provides: bundled(gnulib) %description @@ -1161,6 +1163,21 @@ export SOURCE_DATE_EPOCH=$(stat --printf='%Y' %{_specdir}/%{name}.spec) autoreconf -if %endif +# We're building without go modules enabled, so +# must make a local Go root with the old style +# dir naming scheme/hierarchy +mkdir -p gocode/src/libvirt.org + +export GO111MODULE=off +export GOPATH=/usr/share/gocode:`pwd`/gocode + +%if 0%{?fedora} >= 32 +GOBUILDFLAGS="%gobuildflags" +%else +GOBUILDFLAGS="-buildmode pie -compiler gc -tags=\"rpm_crashtraceback ${BUILDTAGS:-}\" -ldflags \"${LDFLAGS:-} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \n') -extldflags '-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld '\" -a -v -x" +%endif +export GOBUILDFLAGS + rm -f po/stamp-po %configure --with-runstatedir=%{_rundir} \ %{?arg_qemu} \ @@ -1224,7 +1241,7 @@ rm -f po/stamp-po --enable-expensive-tests \ --with-init-script=systemd \ %{?arg_login_shell} -make %{?_smp_mflags} V=1 +make %{?_smp_mflags} V=1 GOBUILDFLAGS="$GOBUILDFLAGS" %install rm -fr %{buildroot} diff --git a/m4/virt-golang.m4 b/m4/virt-golang.m4 new file mode 100644 index 0000000000..2e39bdac7d --- /dev/null +++ b/m4/virt-golang.m4 @@ -0,0 +1,46 @@ +dnl Golang checks +dnl +dnl Copyright (C) 2019 Red Hat, Inc. +dnl +dnl This library is free software; you can redistribute it and/or +dnl modify it under the terms of the GNU Lesser General Public +dnl License as published by the Free Software Foundation; either +dnl version 2.1 of the License, or (at your option) any later version. +dnl +dnl This library is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY; without even the implied warranty of +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +dnl Lesser General Public License for more details. +dnl +dnl You should have received a copy of the GNU Lesser General Public +dnl License along with this library. If not, see +dnl <http://www.gnu.org/licenses/>. +dnl + +AC_DEFUN([LIBVIRT_CHECK_GOLANG], [ + AC_PATH_PROGS([GO], [go], [no]) + if test "x$ac_cv_path_GO" != "xno" + then + with_go=yes + else + with_go=no + fi + AM_CONDITIONAL([HAVE_GOLANG], [test "$with_go" != "no"]) + + if test "$with_go" != "no" + then + GOVERSION=`$ac_cv_path_GO version | awk '{print \$ 3}' | sed -e 's/go//' -e 's/rc.*//'` + GOMAJOR=`echo $GOVERSION | awk -F . '{print \$ 1}'` + GOMINOR=`echo $GOVERSION | awk -F . '{print \$ 2}'` + + dnl We want to use go modules which first arrived in 1.11 + AC_MSG_CHECKING([for Go version >= 1.11]) + if test "$GOMAJOR" != "1" || test "$GOMINOR" -lt "11" + then + with_go=no + AC_MSG_RESULT([no]) + else + AC_MSG_RESULT([yes]) + fi + fi +]) -- 2.21.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list