Dear Maintainer,
[Goal]
Enable microarchitecture variant support (like amd64v3) for Go packages built in the archive.
[Problem]
Currently, if a build is triggered with DEB_HOST_ARCH_VARIANT=amd64v3, dpkg-buildflags correctly translates this for bundled C/C++ code.
However, the native Go compiler ignores this and continues to build at the baseline amd64 level.
To actually utilize these optimizations, Go (since 1.18) requires the GOAMD64 environment variable to be set.
[Proposed Solution]
We need dh-golang to act as the bridge. dh-golang should read the DEB_HOST_ARCH_VARIANT environment variable provided by dpkg and explicitly export GOAMD64.
For example, if $ENV{DEB_HOST_ARCH} is amd64 and $ENV{DEB_HOST_ARCH_VARIANT} is amd64v3, dh-golang should extract the v3 and set GOAMD64=v3 in the build environment (provided the package maintainer hasn't already explicitly overridden it).
I am currently putting together a patch for lib/Debian/Debhelper/Buildsystem/golang.pm to implement this and will attach it to this bug report shortly.