Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible use Go build with extra build steps?

Tags:

go

build

What to do when go build is not enough and ones need to run extra commands along with go build? Does go tools have this use case covered? If so, what's the convention?

I noticed it's possible to pass extra flags to build tools with:

//#cgo pkg-config: glib-2.0 gobject-2.0 etc etc
import "C"

Is it possible to run extra commands or at least tell go build to use a Makefile?

like image 647
marcio Avatar asked Sep 30 '22 06:09

marcio


1 Answers

No. The go tool isn't intended to be a generic build system. There are some provisions made for cgo (like pkg-config), but it's not extendable.

in go1.4 there will be the generate command. This will let you run arbitrary commands for pre-processing source files, but it always has to be a separate step that is run explicitly. You can't hook it into go get, go build, or go install.

Many projects that require a more complicated build use a script or a Makefile, and eschew the general ability go get. Library packages however should strive to be get-able for simplicity in dependecy resolution.

like image 161
JimB Avatar answered Oct 03 '22 04:10

JimB