For those who stumble across this question - it is currently already possible to create your own build preprocessing tools.
For this you can use a -toolexec
flag to specify a tool that will run a custom program at each stage of the build: compile, asm, link.
A naive example:
go build -a -toolexec "yourtool someargs"
This will run yoortool
for each build step by passing all the arguments to yourtool
, so that you can do literally anything, as long as this tool have enough permissions.
There are multiple projects that utilizes this to autoinstrument go code with tracing, for example. But, unfortunately, there is little to no documentation on how to implement such tools yourself.
You can watch a video of Jon Bodners's talk, which describes the principle with examples in a simplified but still detailed way.