[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bug#960842: add <triplet>-go wrappers and golang-go-for-host



Hi,

On Mon, May 18, 2020 at 09:53:04AM -0700, Tianon Gravi wrote:
> I'm curious though, is there a technical reason we need so many extra
> binary packages, especially when each binary package amounts to
> essentially a single very short shell script?  Couldn't we instead
> package them all together into one binary package, something like
> "golang-go-multiarch-wrappers" ?

We could try fusing the golang-go-<triplet> either into
golang-go-for-host or into a shared golang-go-multiarch-wrappers.  If we
try the former, golang-go-for-host would have to depend on a native
golang-go. My patch expresses that by going via arch:all m-a:foreign
packages. The golang-go-for-host -> golang-go-<triplet> dependency
looses its architecture constraint due to Multi-Arch: foreign. If
golang-go-for-host were to depend on golang-go directly, we'd have to
make it Multi-Arch: foreign or we'd have to make it Multi-Arch: allowed
and annotate the dependency with :any. The outcome of that isn't
obvious.

So the other way would be golang-go-multiarch-wrappers. Unlike with gcc,
this is actually feasible, because we know the available targets ahead
of time. We cannot retroactively add architectures without rebuilding
all of go. So that actually works. It just didn't occur to me any
earlier. I'd prefer to have this package provide all the
golang-go-<triplet> instances as virtual packages though.

Another issue with fusing into golang-go-for-host (but not the other
way) is that it requires adding the relevant target architecture using
dpkg --add-architecture.

A weak argument is consistency with gccgo. This is precisely the layout
that gccgo uses (except that gccgo uses Arch:any packages instead of
Arch:all). Keeping this layout as virtual packages seems sensible
though.

So yeah, I think it's actually possible to fuse them into a
golang-go-multiarch-wrappers package. Let me propose a different name
though: golang-go-for-build. That way it'd precisely mirrors what we do
for binutils already and what we will be doing for the gcc frontends.

Here you go. Thank you for the valuable question.

Helmut
diff --minimal -Nru golang-defaults-1.14~1/debian/changelog golang-defaults-1.14~1.1/debian/changelog
--- golang-defaults-1.14~1/debian/changelog	2020-03-07 13:47:33.000000000 +0100
+++ golang-defaults-1.14~1.1/debian/changelog	2020-05-17 14:16:54.000000000 +0200
@@ -1,3 +1,10 @@
+golang-defaults (2:1.14~1.1) UNRELEASED; urgency=medium
+
+  * Non-maintainer upload.
+  * Introduce golang-go-for-host package. (Closes: #-1)
+
+ -- Helmut Grohne <helmut@subdivi.de>  Sun, 17 May 2020 14:16:54 +0200
+
 golang-defaults (2:1.14~1) unstable; urgency=medium
 
   * Update to Go 1.14 (src:golang-1.14). Closes: #952831
diff --minimal -Nru golang-defaults-1.14~1/debian/control golang-defaults-1.14~1.1/debian/control
--- golang-defaults-1.14~1/debian/control	2020-03-07 13:45:40.000000000 +0100
+++ golang-defaults-1.14~1.1/debian/control	2020-05-17 14:16:54.000000000 +0200
@@ -70,6 +70,54 @@
  native toolchain ("gc compiler"). Packages that want to build with whichever
  of gc or gccgo is available should depend on golang-any.
 
+Package: golang-go-for-build
+Architecture: all
+Multi-Arch: foreign
+Depends: golang-go (>= ${source:Version})
+Provides:
+	golang-go-x86-64-linux-gnu,
+	golang-go-aarch64-linux-gnu,
+	golang-go-arm-linux-gnueabi,
+	golang-go-arm-linux-gnueabihf,
+	golang-go-i686-linux-gnu,
+	golang-go-mips-linux-gnu,
+	golang-go-mips64el-linux-gnuabi64,
+	golang-go-mipsel-linux-gnu,
+	golang-go-powerpc64le-linux-gnu,
+	golang-go-riscv64-linux-gnu,
+	golang-go-s390x-linux-gnu,
+Description: Go programming language compiler wrappers
+ The Go programming language is an open source project to make programmers more
+ productive. Go is expressive, concise, clean, and efficient. Its concurrency
+ mechanisms make it easy to write programs that get the most out of multicore
+ and networked machines, while its novel type system enables flexible and
+ modular program construction. Go compiles quickly to machine code yet has the
+ convenience of garbage collection and the power of run-time reflection. It's a
+ fast, statically typed, compiled language that feels like a dynamically typed,
+ interpreted language.
+ .
+ This is a wrapper package. A dependency on golang-go-for-build provides a go
+ compiler for native builds. A dependency on golang-go-<triplet> provides a
+ <triplet>-go compiler wrapper for targeting the named architcture.
+
+Package: golang-go-for-host
+Architecture: amd64 arm64 armel armhf i386 mips mips64el mipsel ppc64el riscv64 s390x
+Multi-Arch: same
+Depends: golang-go${archsuffix} (>= ${source:Version})
+Description: Go programming language compiler wrapper
+ The Go programming language is an open source project to make programmers more
+ productive. Go is expressive, concise, clean, and efficient. Its concurrency
+ mechanisms make it easy to write programs that get the most out of multicore
+ and networked machines, while its novel type system enables flexible and
+ modular program construction. Go compiles quickly to machine code yet has the
+ convenience of garbage collection and the power of run-time reflection. It's a
+ fast, statically typed, compiled language that feels like a dynamically typed,
+ interpreted language.
+ .
+ This is a dependency package that depends on architecture-suffixed golang-go
+ package matching the architecture of this package. When depending on this
+ package, go must be called through the wrapper only.
+
 Package: golang-any
 Architecture: any
 Depends: golang-go (>= ${source:Version}) | gccgo-go (>= ${source:Version}),
@@ -149,7 +197,7 @@
  http://localhost:6060/doc/install.html.
 
 Package: golang
-Architecture: amd64 arm64 armel armhf i386 mips mips64 mipsel ppc64el riscv64 s390x
+Architecture: amd64 arm64 armel armhf i386 mips mips64el mipsel ppc64el riscv64 s390x
 Depends: golang-${golang:GOVER},
          golang-doc (>= ${source:Version}),
          golang-go (>= ${source:Version}),
diff --minimal -Nru golang-defaults-1.14~1/debian/control.sh golang-defaults-1.14~1.1/debian/control.sh
--- golang-defaults-1.14~1/debian/control.sh	1970-01-01 01:00:00.000000000 +0100
+++ golang-defaults-1.14~1.1/debian/control.sh	2020-05-17 14:16:54.000000000 +0200
@@ -0,0 +1,218 @@
+#!/bin/sh
+
+GOLANG_GO_ARCHS="$1"
+
+cat <<EOF
+Source: golang-defaults
+Maintainer: Go Compiler Team <team+go-compiler@tracker.debian.org>
+Uploaders: Michael Stapelberg <stapelberg@debian.org>,
+           Paul Tagliamonte <paultag@debian.org>,
+           Tianon Gravi <tianon@debian.org>,
+           Michael Hudson-Doyle <mwhudson@debian.org>,
+           Mart�Ferrari <tincho@debian.org>,
+           Dr. Tobias Quathamer <toddy@debian.org>,
+           Anthony Fok <foka@debian.org>
+Section: devel
+Priority: optional
+Build-Depends: debhelper-compat (= 12),
+               dh-exec
+Standards-Version: 4.4.0
+Vcs-Browser: https://salsa.debian.org/go-team/compiler/golang-defaults
+Vcs-Git: https://salsa.debian.org/go-team/compiler/golang-defaults.git
+Homepage: https://golang.org
+
+Package: golang-go
+Architecture: $GOLANG_GO_ARCHS
+Depends: golang-\${golang:GOVER}-go,
+         golang-src (>= \${source:Version}),
+         \${misc:Depends}
+Suggests: git
+Breaks: gccgo-5 (<< 5.3.1-12~),
+        gccgo-6 (<< 6-20160319-1~),
+        golang-doc (<< 2:1.6.1+1~),
+        golang-go-darwin-386,
+        golang-go-darwin-amd64,
+        golang-go-freebsd-386,
+        golang-go-freebsd-amd64,
+        golang-go-freebsd-arm,
+        golang-go-linux-386,
+        golang-go-linux-amd64,
+        golang-go-linux-arm,
+        golang-go-netbsd-386,
+        golang-go-netbsd-amd64,
+        golang-go-windows-386,
+        golang-go-windows-amd64,
+        golang-go.tools (<< 1:0.0~git20151026.0.0f9d71c-1~),
+        golang-golang-x-tools (<< 1:0.0~git20151026.0.0f9d71c-1~)
+Conflicts: gccgo-go
+Replaces: golang-doc (<< 2:1.6.1+1~),
+          golang-go-darwin-386,
+          golang-go-darwin-amd64,
+          golang-go-freebsd-386,
+          golang-go-freebsd-amd64,
+          golang-go-freebsd-arm,
+          golang-go-linux-386,
+          golang-go-linux-amd64,
+          golang-go-linux-arm,
+          golang-go-netbsd-386,
+          golang-go-netbsd-amd64,
+          golang-go-windows-386,
+          golang-go-windows-amd64,
+          golang-go.tools (<< 1:0.0~git20151026.0.0f9d71c-1~),
+          golang-golang-x-tools (<< 1:0.0~git20151026.0.0f9d71c-1~)
+Description: Go programming language compiler, linker, compiled stdlib
+ The Go programming language is an open source project to make programmers more
+ productive. Go is expressive, concise, clean, and efficient. Its concurrency
+ mechanisms make it easy to write programs that get the most out of multicore
+ and networked machines, while its novel type system enables flexible and
+ modular program construction. Go compiles quickly to machine code yet has the
+ convenience of garbage collection and the power of run-time reflection. It's a
+ fast, statically typed, compiled language that feels like a dynamically typed,
+ interpreted language.
+ .
+ This is a dependency package that depends on the default Go toolchain and
+ compiled standard library. It is only built on architectures that have a
+ native toolchain ("gc compiler"). Packages that want to build with whichever
+ of gc or gccgo is available should depend on golang-any.
+
+Package: golang-go-for-build
+Architecture: all
+Multi-Arch: foreign
+Depends: golang-go (>= \${source:Version})
+Provides:
+EOF
+for arch in $GOLANG_GO_ARCHS; do
+	echo "	golang-go-$(dpkg-architecture -f "-a$arch" -qDEB_HOST_GNU_TYPE 2>/dev/null | tr _ -),"
+done
+cat <<EOF
+Description: Go programming language compiler wrappers
+ The Go programming language is an open source project to make programmers more
+ productive. Go is expressive, concise, clean, and efficient. Its concurrency
+ mechanisms make it easy to write programs that get the most out of multicore
+ and networked machines, while its novel type system enables flexible and
+ modular program construction. Go compiles quickly to machine code yet has the
+ convenience of garbage collection and the power of run-time reflection. It's a
+ fast, statically typed, compiled language that feels like a dynamically typed,
+ interpreted language.
+ .
+ This is a wrapper package. A dependency on golang-go-for-build provides a go
+ compiler for native builds. A dependency on golang-go-<triplet> provides a
+ <triplet>-go compiler wrapper for targeting the named architcture.
+
+Package: golang-go-for-host
+Architecture: $GOLANG_GO_ARCHS
+Multi-Arch: same
+Depends: golang-go\${archsuffix} (>= \${source:Version})
+Description: Go programming language compiler wrapper
+ The Go programming language is an open source project to make programmers more
+ productive. Go is expressive, concise, clean, and efficient. Its concurrency
+ mechanisms make it easy to write programs that get the most out of multicore
+ and networked machines, while its novel type system enables flexible and
+ modular program construction. Go compiles quickly to machine code yet has the
+ convenience of garbage collection and the power of run-time reflection. It's a
+ fast, statically typed, compiled language that feels like a dynamically typed,
+ interpreted language.
+ .
+ This is a dependency package that depends on architecture-suffixed golang-go
+ package matching the architecture of this package. When depending on this
+ package, go must be called through the wrapper only.
+
+Package: golang-any
+Architecture: any
+Depends: golang-go (>= \${source:Version}) | gccgo-go (>= \${source:Version}),
+         \${misc:Depends}
+Description: Go programming language -- gccgo on "non-Go" platforms
+ The Go programming language is an open source project to make programmers more
+ productive. Go is expressive, concise, clean, and efficient. Its concurrency
+ mechanisms make it easy to write programs that get the most out of multicore
+ and networked machines, while its novel type system enables flexible and
+ modular program construction. Go compiles quickly to machine code yet has the
+ convenience of garbage collection and the power of run-time reflection. It's a
+ fast, statically typed, compiled language that feels like a dynamically typed,
+ interpreted language.
+ .
+ This is a dependency package that depends on the default Go toolchain and
+ compiled standard library or gccgo on architectures that do not have a native
+ toolchain ("gc compiler") port. Because the gccgo and Go releases are not on
+ the same schedule, it is not guaranteed that the version of the Go language
+ provided by the version of gccgo that this package depends upon will match the
+ version of this package.
+
+Package: gccgo-go
+Architecture: any
+Depends: gccgo-9,
+         \${misc:Depends}
+Conflicts: golang-go
+Description: Go programming language -- gccgo
+ The Go programming language is an open source project to make programmers more
+ productive. Go is expressive, concise, clean, and efficient. Its concurrency
+ mechanisms make it easy to write programs that get the most out of multicore
+ and networked machines, while its novel type system enables flexible and
+ modular program construction. Go compiles quickly to machine code yet has the
+ convenience of garbage collection and the power of run-time reflection. It's a
+ fast, statically typed, compiled language that feels like a dynamically typed,
+ interpreted language.
+ .
+ Installing this package will install the gccgo implementation as /usr/bin/go.
+ It conflicts with golang-go.
+
+Package: golang-src
+Architecture: $GOLANG_GO_ARCHS
+Depends: golang-\${golang:GOVER}-src,
+         \${misc:Depends}
+Description: Go programming language - source files
+ The Go programming language is an open source project to make programmers more
+ productive. Go is expressive, concise, clean, and efficient. Its concurrency
+ mechanisms make it easy to write programs that get the most out of multicore
+ and networked machines, while its novel type system enables flexible and
+ modular program construction. Go compiles quickly to machine code yet has the
+ convenience of garbage collection and the power of run-time reflection. It's a
+ fast, statically typed, compiled language that feels like a dynamically typed,
+ interpreted language.
+ .
+ This is a dependency package that depends on the default Go standard library
+ source code, which is needed for the go build process.
+
+Package: golang-doc
+Architecture: all
+Section: doc
+Depends: golang-\${golang:GOVER}-doc,
+         golang-go (>= \${source:Version}),
+         \${misc:Depends}
+Description: Go programming language - documentation
+ The Go programming language is an open source project to make
+ programmers more productive. Go is expressive, concise, clean, and
+ efficient. Its concurrency mechanisms make it easy to write programs
+ that get the most out of multicore and networked machines, while its
+ novel type system enables flexible and modular program construction.
+ Go compiles quickly to machine code yet has the convenience of
+ garbage collection and the power of run-time reflection. It's a fast,
+ statically typed, compiled language that feels like a dynamically
+ typed, interpreted language.
+ .
+ This is a dependency package that depends on the default Go documentation. You
+ can view the formatted documentation by installing the golang-golang-x-tools
+ package, running "godoc --http=:6060", and then visiting
+ http://localhost:6060/doc/install.html.
+
+Package: golang
+Architecture: $GOLANG_GO_ARCHS
+Depends: golang-\${golang:GOVER},
+         golang-doc (>= \${source:Version}),
+         golang-go (>= \${source:Version}),
+         golang-src (>= \${source:Version}),
+         \${misc:Depends}
+Description: Go programming language compiler - metapackage
+ The Go programming language is an open source project to make
+ programmers more productive. Go is expressive, concise, clean, and
+ efficient. Its concurrency mechanisms make it easy to write programs
+ that get the most out of multicore and networked machines, while its
+ novel type system enables flexible and modular program construction.
+ Go compiles quickly to machine code yet has the convenience of
+ garbage collection and the power of run-time reflection. It's a
+ fast, statically typed, compiled language that feels like a
+ dynamically typed, interpreted language.
+ .
+ This package is a metapackage that, when installed, guarantees
+ that (most of) a full Go development environment is installed.
+EOF
diff --minimal -Nru golang-defaults-1.14~1/debian/rules golang-defaults-1.14~1.1/debian/rules
--- golang-defaults-1.14~1/debian/rules	2020-03-07 13:42:52.000000000 +0100
+++ golang-defaults-1.14~1.1/debian/rules	2020-05-17 14:16:54.000000000 +0200
@@ -1,10 +1,27 @@
 #!/usr/bin/make -f
 # -*- makefile -*-
 
+GOLANG_GO_ARCHS=amd64 arm64 armel armhf i386 mips mips64el mipsel ppc64el riscv64 s390x
+
+include /usr/share/dpkg/architecture.mk
+
 export GOVER := $(shell debian/helpers/getver.pl)
+HOST_ARCH_SUFFIX=-$(subst _,-,$(DEB_HOST_GNU_TYPE))
 
 %:
 	dh $@
 
+debian/control:debian/control.sh
+	./$< "$(GOLANG_GO_ARCHS)" > $@.tmp
+	mv $@.tmp $@
+
+override_dh_auto_install-indep:
+	mkdir -p debian/golang-go-for-build/usr/bin
+	set -e; for arch in $(GOLANG_GO_ARCHS); do \
+		gnu_type=$$(dpkg-architecture -f "-a$$arch" -qDEB_HOST_GNU_TYPE); \
+		./make-cross-go.sh "$$arch" > debian/golang-go-for-build/usr/bin/$$gnu_type-go; \
+		chmod +x debian/golang-go-for-build/usr/bin/$$gnu_type-go; \
+	done
+
 override_dh_gencontrol:
-	dh_gencontrol -- -Vgolang:GOVER=$(GOVER)
+	dh_gencontrol -- -Vgolang:GOVER=$(GOVER) -Varchsuffix=$(HOST_ARCH_SUFFIX)
diff --minimal -Nru golang-defaults-1.14~1/make-cross-go.sh golang-defaults-1.14~1.1/make-cross-go.sh
--- golang-defaults-1.14~1/make-cross-go.sh	1970-01-01 01:00:00.000000000 +0100
+++ golang-defaults-1.14~1.1/make-cross-go.sh	2020-05-17 14:16:54.000000000 +0200
@@ -0,0 +1,49 @@
+#!/bin/sh
+
+ARCH="$1"
+GOARM=
+case "$(dpkg-architecture -f "-a$ARCH" -qDEB_HOST_ARCH_CPU 2>/dev/null)/$(dpkg-architecture -f "-a$ARCH" -qDEB_HOST_ARCH_ABI 2>/dev/null)" in
+	amd64/base) GOARCH=amd64 ;;
+	amd64/x32) GOARCH=amd64p32 ;;
+	arm/eabi) GOARCH=arm; GOARM=5 ;;
+	arm/eabihf) GOARCH=arm; GOARM=7 ;;
+	arm64/base) GOARCH=arm64 ;;
+	i386/base) GOARCH=386 ;;
+	mips/base) GOARCH=mips ;;
+	mips64/abi64) GOARCH=mips64 ;;
+	mips64el/abi64) GOARCH=mips64le ;;
+	mipsel/base) GOARCH=mipsle ;;
+	powerpc/base) GOARCH=ppc ;;
+	ppc64/base) GOARCH=ppc64 ;;
+	ppc64el/base) GOARCH=ppc64le ;;
+	riscv64/base) GOARCH=riscv64 ;;
+	s390/base) GOARCH=s390 ;;
+	s390x/base) GOARCH=s390x ;;
+	sparc/base) GOARCH=sparc ;;
+	sparc64/base) GOARCH=sparc64 ;;
+	*)
+		echo "cannot determine GOARCH for $ARCH" 2>&1
+		exit 1
+	;;
+esac
+
+echo "#!/bin/sh"
+echo "export GOARCH=$GOARCH"
+if test -n "$GOARM"; then
+	echo "export GOARM=$GOARM"
+else
+	echo "unset GOARM"
+fi
+if dpkg-architecture -f "-a$ARCH" -ilinux-any; then
+	echo "export GOOS=linux"
+fi
+GNU_TYPE=$(dpkg-architecture -f "-a$ARCH" -qDEB_HOST_GNU_TYPE 2>/dev/null)
+cat <<EOF
+: "\${CC:=$GNU_TYPE-gcc}"
+export CC
+: "\${PKG_CONFIG:=$GNU_TYPE-pkg-config}"
+export PKG_CONFIG
+: "\${CGO_ENABLED:=1}"
+export CGO_ENABLED
+exec /usr/bin/go "\$@"
+EOF

Reply to: