Managing Go Tool Dependencies

You might be interested to take advantage of this upcoming feature in Go 1.24 (to be released Feb 2025).

That is, you can manage tool dependencies via the go.mod file, and download and run them. Below is an example relevant for users of the Gorums library. But first, to use this feature before the release of Go 1.24, you can install the gotip tool:

go install golang.org/dl/gotip@latest
gotip download

Then you can use the gotip command instead of the go command to run stuff that requires Go 1.24.

% gotip version
go version devel go1.24-4daf7922f3 Tue Dec 3 20:01:57 2024 +0000 darwin/arm64

If you want to live on the edge, you can make gotip the default Go command by adding the following to your .zshrc or .bashrc:

# Make gotip the default Go command;
# gotip is installed in ~/go/bin and ~/sdk/gotip/bin contains the gotip distribution.
# (This export must be here and not in .zshenv since otherwise it won't be placed first in the PATH)
[[ -x $(command -v gotip) ]] && export PATH=$(gotip env GOROOT)/bin:$PATH

Then you can run the go command:

% go version
go version devel go1.24-4daf7922f3 Tue Dec 3 20:01:57 2024 +0000 darwin/arm64

Back to managing tool dependencies

Now, back to the example of managing tool dependencies in go.mod. Here is how you can add tool dependencies:

go get -u -tool github.com/relab/gorums/cmd/protoc-gen-gorums
go get -u -tool google.golang.org/grpc/cmd/protoc-gen-go-grpc
go get -u -tool google.golang.org/protobuf/cmd/protoc-gen-go

After which go.mod will have these lines added:

tool (
	github.com/relab/gorums/cmd/protoc-gen-gorums
	google.golang.org/grpc/cmd/protoc-gen-go-grpc
	google.golang.org/protobuf/cmd/protoc-gen-go
)

Then you can do:

# Run the tool (must be in same repository as go.mod)
% pwd
/Users/meling/work/distsys/dat520
% go tool protoc-gen-gorums --version
protoc-gen-gorums v0.7.0-devel
% cd; pwd
/Users/meling
% go tool protoc-gen-gorums --version
go: no such tool "protoc-gen-gorums"
# Install all tools in $GOBIN (globally available)
% cd work/distsys/dat520
% go install tool
# Run the tool from anywhere
% protoc-gen-gorums --version
protoc-gen-gorums v0.7.0-devel

If you want to remove a tool dependency, you can do:

go mod edit -droptool google.golang.org/grpc/cmd/protoc-gen-go-grpc

After which go.mod will have these lines added:

tool (
	github.com/relab/gorums/cmd/protoc-gen-gorums
	google.golang.org/protobuf/cmd/protoc-gen-go
)
Hein Meling
Hein Meling
Professor of Distributed Systems

My main interest is in secure and dependable distributed computing, including cryptocurrencies and blockchains.