Repository: go
Issue: doc: declare a standard for packaging Go for downstream distributions
Labels: Documentation,NeedsInvestigation

I have spent the last hour or so very confused, because it seemed like the system's Go 1.17.1 I installed via Arch was very different from the `go version devel go1.18-051df0d722` I installed from source recently. After much digging, I ended up realising that my 1.17.1 was missing all test files and testdata directories, and this seems to be [by design](https://github.com/archlinux/svntogit-community/blob/bd9adbc5205ca199dbe1bf25c6ab077a5bd33113/trunk/PKGBUILD#L81-L82).

I [filed a bug](https://bugs.archlinux.org/task/72209) on the distro in question, and hopefully they'll reconsider. At the very least, they should support some way to install those missing files, because otherwise my install of Go is incomplete; `go test std` gives a weird error and then prints a lot of "no test files" warnings. Similarly, `go test all` is (silently) broken for third party modules importing std.

I'm raising this issue because I'm very surprised that downstreams are installing partial GOROOTs and giving the impression that they are full and complete Go installs. As far as I am aware, the only way that Go is supported is when the GOROOT is used from a binary distribution, or from the result of `make.bash` without removing files.

Unfortunately, it seems like different distributions have their own definitions of a Go install, with varying degrees of what files are included.

Some distros which don't install a full GOROOT:

* Arch Linux, as discussed above, removes `*_test.go` and `testdata` files.
* Alpine does the same as Arch; [link](https://git.alpinelinux.org/aports/tree/community/go/APKBUILD?id=1f51a7d64cd9c142f67fec3fd122ab825a5dcc5d#n167)
* Fedora packages [golang-tests](https://fedora.pkgs.org/34/fedora-x86_64/golang-tests-1.16-2.fc34.noarch.rpm.html) separately from [golang-src](https://fedora.pkgs.org/34/fedora-x86_64/golang-src-1.16-2.fc34.noarch.rpm.html); note that golang-tests is not installed by default
* Homebrew seems to delete a couple of testdata dirs; [link](https://github.com/Homebrew/homebrew-core/blob/4fcd38ceae0b6043289018fd32a9c324511fe6c1/Formula/go.rb#L60-L64)
* Gentoo appears to delete all testdata dirs; [link](https://gitweb.gentoo.org/repo/gentoo.git/tree/dev-lang/go/go-1.17.1.ebuild?id=453fb1ade81143f177daf7465d3620a65d3dce71#n166)
* Nix seems to disable many tests, though it doesn't seem to delete files; [link](https://github.com/NixOS/nixpkgs/blob/a930f7da84786807bb105df40e76b541604c3e72/pkgs/development/compilers/go/1.17.nix#L72-L177)

Distros which appear to install an entire GOROOT:

* Debian appears to include all test files; [link for 1.15 on stable](https://packages.debian.org/bullseye/amd64/golang-1.15-src/filelist)
* Ubuntu seems to do the same as Debian; [link](https://packages.ubuntu.com/hirsute/amd64/golang-1.16-src/filelist)
* FreeBSD seems to also include all files; [link](https://cgit.freebsd.org/ports/tree/lang/go/Makefile?id=c72a8f3160a3d158ee6d095a35f5fed843c5ecb4#n82)
* Winget just uses a full binary install; [link](https://github.com/microsoft/winget-pkgs/blob/8fa1fc3860a989034debc9098e4b129340fd9380/manifests/g/GoLang/Go/1.17.1/GoLang.Go.installer.yaml#L16)

It's also worth noting that some distros split "bin", "src", and "doc" packages. I think I don't have any argument against that, as long as the default install includes all of them.

I understand that it's normal for downstreams to apply light patches to software while packaging. However, I feel like there's a bit of a disconnect happening here: if I install Go with my system's package manager, right now it appears to be a coin toss whether or not that `GOROOT` will be complete with test files and testdata directories. I imagine there might be other inconsistencies too, such as the `misc` or `doc` directories.

I think it's worthwhile to consider whether we want to be in this situation in the long term. I would say not - it's pretty confusing to the end user.

One way I can imagine we could improve the situation in the long term is for the Go project to define a base set of guidelines for packaging Go. For example, if we declare that it should include `GOROOT/src` without deleting test files, then a common source of variance between distributions would go away. It could also declare whether or not it's OK to omit directories like `misc`, `api`, or `doc`.

If we go the route of defining a "minimal Go install" which excludes some files such as `*_test.go` and `testdata`, then I reckon that should be properly tested and supported too. Right now, the experience is somewhat poor, as `go test std` fails with `[amd64] FuncPCTestFn: function FuncPCTestFn missing Go declaration`.

Another route to consider is to reduce the incentive for downstreams to strip files. As far as I have seen, there are two common recurring themes:

* Some files are large. For example, Arch argues that removing test files and data reduces the package size by 100MiB. Perhaps we could try to reduce some of the testdata file sizes.
* Some tests fail or are flaky. For example, Nix seems to disable or patch dozens of tests. Perhaps we should encourage them to file bugs about those.

I will keep editing this post to correct information or add more distros. Edit log:
* I hadn't noticed that Fedora has a `golang-tests` package.