Source: golang-1.24
Version: 1.24.1-1
Tags: patch
User: debian-cr...@lists.debian.org
Usertags: ftcbfs

I looked into cross building the go compiler itself. The packaging
already did a lot of the heavy lifting. Thank you!

The immediate failure is running the host's go executable. As go is a
multi-target compiler, we really want the build's go here. That can be
achieved by appending :native to the relevant Build-Depends.

>From then, the build goes quite far. The failure is from dh_strip
complaining about amd64 executables in various locations. One aspect to
this is that we should tell the build process about the C and C++
compilers as it uses different variable meanings from Debian:

  CC -> CC_FOR_TARGET
  CC_FOR_BUILD -> CC

I propose adding those variables to debian/helpers/goenv.sh.

Unfortunately, that doesn't make dh_strip happy. In a cross build,
./bin contains the build's go tools and a directory ${GOOS}_${GOARCH}
containing the host's go tools. This is different from native builds and
requires some branching to install them.

Likewise, pkg/tool now contains tools for both the build and the host
architecture, but the binary package should only contain the host's
tools.

For correctly installing those files in both native and cross builds,
the packaging needs the GOOS and GOARCH variables, which is why I
suggest moving their computation from debian/helpers/goenv.sh into
debian/rules. Admittedly, it is slightly uglier in make than in shell.

And with all of these changes, we can readily cross build the
golang-1.24 package. What do you think?

I suppose that this likewise applies to other go versions and that the
patch is transferrable there.

If you think that the toolchain freeze is too close to apply this patch,
please defer it until after trixie is released. Cross building go
packages in Debian requires more changes and cross building the go
compiler probably is not the most exciting exercise.

Helmut
diff --minimal -Nru golang-1.24-1.24.1/debian/changelog 
golang-1.24-1.24.1/debian/changelog
--- golang-1.24-1.24.1/debian/changelog 2025-03-05 00:58:41.000000000 +0100
+++ golang-1.24-1.24.1/debian/changelog 2025-03-13 11:38:16.000000000 +0100
@@ -1,3 +1,15 @@
+golang-1.24 (1.24.1-1.1) UNRELEASED; urgency=medium
+
+  * Non-maintainer upload.
+  * Fix FTCBFS: (Closes: #-1)
+    + Build-Depend on a native go compiler.
+    + Move GO{,HOST}{ARCH,OS} from debian/helpers/goenv.sh to debian/rules
+      for use by debhelper.
+    + Export C{C,XX}{,_FOR_TARGET} as required by make.bash.
+    + Install the host's (target in go-speak) tools and compiler only.
+
+ -- Helmut Grohne <hel...@subdivi.de>  Thu, 13 Mar 2025 11:38:16 +0100
+
 golang-1.24 (1.24.1-1) unstable; urgency=medium
 
   * Team upload
diff --minimal -Nru golang-1.24-1.24.1/debian/control 
golang-1.24-1.24.1/debian/control
--- golang-1.24-1.24.1/debian/control   2025-03-05 00:58:41.000000000 +0100
+++ golang-1.24-1.24.1/debian/control   2025-03-13 11:38:16.000000000 +0100
@@ -13,7 +13,7 @@
 Priority: optional
 Build-Depends: debhelper-compat (= 13),
                binutils-gold [arm64],
-               golang-1.24-go | golang-1.23-go | golang-1.22-go,
+               golang-1.24-go:native | golang-1.23-go:native | 
golang-1.22-go:native,
                netbase
 Standards-Version: 4.6.2
 Vcs-Browser: https://salsa.debian.org/go-team/compiler/golang/tree/golang-1.24
diff --minimal -Nru golang-1.24-1.24.1/debian/golang-X.Y-go.dirs 
golang-1.24-1.24.1/debian/golang-X.Y-go.dirs
--- golang-1.24-1.24.1/debian/golang-X.Y-go.dirs        2025-03-05 
00:58:41.000000000 +0100
+++ golang-1.24-1.24.1/debian/golang-X.Y-go.dirs        2025-03-13 
11:38:16.000000000 +0100
@@ -1 +1 @@
-usr/lib/go-X.Y
+usr/lib/go-X.Y/bin
diff --minimal -Nru golang-1.24-1.24.1/debian/golang-X.Y-go.install 
golang-1.24-1.24.1/debian/golang-X.Y-go.install
--- golang-1.24-1.24.1/debian/golang-X.Y-go.install     2025-03-05 
00:58:41.000000000 +0100
+++ golang-1.24-1.24.1/debian/golang-X.Y-go.install     2025-03-13 
11:38:16.000000000 +0100
@@ -1,5 +1,4 @@
 VERSION /usr/lib/go-X.Y/
-bin /usr/lib/go-X.Y/
 go.env /usr/lib/go-X.Y/
 pkg/include /usr/share/go-X.Y/pkg/
-pkg/tool /usr/lib/go-X.Y/pkg/
+pkg/tool/${env:GOOS}_${env:GOARCH} /usr/lib/go-X.Y/pkg/
diff --minimal -Nru golang-1.24-1.24.1/debian/helpers/goenv.sh 
golang-1.24-1.24.1/debian/helpers/goenv.sh
--- golang-1.24-1.24.1/debian/helpers/goenv.sh  2025-03-05 00:58:41.000000000 
+0100
+++ golang-1.24-1.24.1/debian/helpers/goenv.sh  2025-03-13 11:38:16.000000000 
+0100
@@ -1,37 +1,7 @@
 #!/bin/sh
 set -e
 
-__goos__deb_arch_os() {
-       case "$1" in
-               kfreebsd) echo freebsd ;;
-               linux) echo "$1" ;;
-               *) echo >&2 "error: unrecongized DEB_*_ARCH_OS: $1"; exit 1 ;;
-       esac
-}
-
-__goarch__deb_arch_cpu() {
-       case "$1" in
-               amd64|arm|arm64|loong64|mips|ppc64|riscv64|s390x) echo "$1" ;;
-               i386) echo 386 ;;
-               mips64el) echo mips64le ;;
-               mipsel) echo mipsle ;;
-               ppc64el) echo ppc64le ;;
-               *) echo >&2 "error: unrecongized DEB_*_ARCH_CPU: $1"; exit 1 ;;
-       esac
-}
-
-#       build machine
-#           The machine the package is built on.
-#
-#       host machine
-#           The machine the package is built for.
-
-export GOHOSTOS="$(__goos__deb_arch_os "$(dpkg-architecture 
-qDEB_BUILD_ARCH_OS 2>/dev/null)")"
-export GOOS="$(__goos__deb_arch_os "$(dpkg-architecture -qDEB_HOST_ARCH_OS 
2>/dev/null)")"
-
-export GOHOSTARCH="$(__goarch__deb_arch_cpu "$(dpkg-architecture 
-qDEB_BUILD_ARCH_CPU 2>/dev/null)")"
-export GOARCH="$(__goarch__deb_arch_cpu "$(dpkg-architecture 
-qDEB_HOST_ARCH_CPU 2>/dev/null)")"
-
+# GO{,HOST}{ARCH,OS} are set in debian/rules
 if [ -z "$GOHOSTOS" -o -z "$GOOS" -o -z "$GOHOSTARCH" -o -z "$GOARCH" ]; then
        exit 1
 fi
@@ -70,4 +40,28 @@
 fi
 export GOARM
 
+if [ "$(dpkg-architecture -qDEB_HOST_ARCH 2>/dev/null)" = "$(dpkg-architecture 
-qDEB_BUILD_ARCH 2>/dev/null)" ]; then
+       : "${CC:=${CC_FOR_BUILD:-gcc}}"
+       CC_FOR_TARGET="$CC"
+       : "${CXX:=${CXX_FOR_BUILD:-g++}}"
+       CXX_FOR_TARGET="$CXX"
+else
+       if [ -z "${CC:-}" ]; then
+               CC_FOR_TARGET="$CC"
+       else
+               CC_FOR_TARGET="$(dpkg-architecture -qDEB_HOST_GNU_TYPE 
2>/dev/null)-gcc"
+       fi
+       CC="${CC_FOR_BUILD:-gcc}"
+       if [ -n "${CXX:-}" ]; then
+               CXX_FOR_TARGET="$CXX"
+       else
+               CXX_FOR_TARGET="$(dpkg-architecture -qDEB_HOST_GNU_TYPE 
2>/dev/null)-g++"
+       fi
+       CXX="${CXX_FOR_BUILD:-g++}"
+fi
+export CC
+export CC_FOR_TARGET
+export CXX
+export CXX_FOR_TARGET
+
 eval "$@"
diff --minimal -Nru golang-1.24-1.24.1/debian/rules 
golang-1.24-1.24.1/debian/rules
--- golang-1.24-1.24.1/debian/rules     2025-03-05 00:58:41.000000000 +0100
+++ golang-1.24-1.24.1/debian/rules     2025-03-13 11:38:16.000000000 +0100
@@ -20,6 +20,18 @@
 # Go 1.12 needs a build cache, otherwise the build fails.
 export GOCACHE := $(GOPATH)/gocache
 
+__goos__deb_arch_os = $(or $(filter $(1),linux),$(if $(filter 
$(1),kfreebsd),freebsd,$(error unrecognized DEB_*_ARCH_OS: $(1))))
+__goarch__deb_arch_cpu_map_i386 = 386
+__goarch__deb_arch_cpu_map_mips64el = mips64le
+__goarch__deb_arch_cpu_map_mipsel = mipsle
+__goarch__deb_arch_cpu_map_ppc64el = ppc64le
+__goarch__deb_arch_cpu = $(or $(filter $(1),amd64 arm arm64 loong64 mips ppc64 
riscv64 s390x),$(__goarch__deb_arch_cpu_map_$(1)),$(error unrecognized 
DEB_*_ARCH_CPU: $(1)))
+
+export GOHOSTOS := $(call __goos__deb_arch_os,$(DEB_BUILD_ARCH_OS))
+export GOOS := $(call __goos__deb_arch_os,$(DEB_HOST_ARCH_OS))
+export GOHOSTARCH := $(call __goarch__deb_arch_cpu,$(DEB_BUILD_ARCH_CPU))
+export GOARCH := $(call __goarch__deb_arch_cpu,$(DEB_HOST_ARCH_CPU))
+
 # source files generated during building.
 # especially zbootstrap.go has different defaultGOARM values on armhf and 
armel,
 # since the value is set from debian/helpers/goenv.sh
@@ -74,6 +86,7 @@
        dh_compress -Xusr/share/doc/golang-$(GOVER)-doc/html
 
 execute_after_dh_install-arch:
+       cp bin/$(if $(filter 
$(DEB_BUILD_ARCH),$(DEB_HOST_ARCH)),,$(GOOS)_$(GOARCH)/)* 
debian/golang-$(GOVER)-go/usr/lib/go-$(GOVER)/bin/
        cp --parent -v $(GENERATED_FILES) 
debian/golang-$(GOVER)-go/usr/share/go-$(GOVER)/
 
 execute_after_dh_install-indep:

Reply via email to