Demo how to install binary dependencies for Go with modules without abusing your code dependencies.
Before Go 1.13 solution with tools.go (golang/go#25922) had worked well enough without abusing go.mod/go.sum file by dependencies hidden under a tag. Now with go 1.13.x go mod tidy adds such dependencies to module's go.mod go.sum files, which I want to avoid.
- binary dependencies described in
_tools/linter/tools.go.- symbol
_in top level directory name hides dependency code from go build tools. - second level directory
linterexist because it's allows go tools work properly inside it (go tools don't like directory names with underscores)
- symbol
- Directory
_tools/linterinitialized as separate go module (in this casecf-workers-proxy-9e9.pages.dev/nordicdyno/golang-tools-linter). This allows track binaries dependencies like it was proposed by «tools.gosolution» in golang/go#25922, but without mixing tools and project dependencies. - Binaries could be installed without any extra tools (except shell), just by running
_tools/install.sh.- This script just runs
ls-importsutility in the context of tools module and sends its output togo installcommand. - The tool
ls-importsis carried inside_tools/ls-importsdirectory and all that it does just prints all imports from provided files.
- This script just runs
- Your project's binary tools and their dependencies separated from your code.
- Versions of dependencies these extra tools don't collide with your dependencies versions and don't interfere with them in unpredictable ways.
- Dependencies of binary dependencies still interfere with each other, until we separate them in their own
dependency holdermodules - You need a shell to install tools. (It's easily solvable with docker or a little bit more complicated
ls-imports/deps-installtool)
build binary:
go build
install tools (linter):
make tools-install
run linter:
make lint