This weekend, I made a series of somewhat unusual changes to pkgsrc.
I removed a bunch of Go packages.
Why? Because of Go modules.
What are Go modules?
To recap: There are two ways to use the
go tool to build Go code.
- The old way is to have a tree, below
$GOPATH, that has all the dependencies in a directory tree according to their import path. For instance, the
golang.org/x/netpackage would be placed in a
$GOPATH/src/golang.org/x/netdirectory. This is what
lang/go/go-package.mkimplements in pkgsrc.
- The new way is to extract the source code wherever you want, just like any C
source. The top-level source directory contains a
go.modfile that specifies dependencies and their versions. The
gotool then downloads a bunch of
.modfiles for those dependencies and unpacks them as needed. This is similar to how Cargo works for Rust code.
Like with Rust, in pkgsrc, we specify a list of dependent module files to be downloaded from the module proxy.
In actual practice, a useful pattern has emerged, where the
list of modules is in a separate file named
go-modules.mk in the package
directory. To create or update the file, simply run
$ make patch
$ make show-go-modules > go-modules.mk
.include the file from the main
But why remove all these packages?
A pkgsrc package built with
lang/go/go-module.mk does not install any source
.a files. Only the binaries are packaged, just like for C.
Go packages that just correspond to intermediate libraries and do not contain
any useful binaries are simply no longer needed. They can be deleted as soon as
nothing depends on them any more.
In particular, I changed all the packages depending on
to be modules, then migrated the go-tools package itself. go-tools depends on a
number of other libraries that nothing else depends on.
By the way, it is fairly simple to make a non-module into a module, even if the
source does not contain a
make patchand change into the top-level source directory.
go mod init github.com/foo/baror whatever the import path is.
- Update the file with
go mod tidy.
- Copy the generated
go.sumfiles to a
filesdirectory and copy them into place in
Some future Go release will deprecate
GOPATH builds, so we must convert all Go
code in pkgsrc to modules at some point. By the way, if upstream has not made
the jump to modules yet, they might be happy about your pull request :)