7

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?

marcio
  • 10,002
  • 11
  • 54
  • 83

2 Answers2

4

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.

JimB
  • 104,193
  • 13
  • 262
  • 255
  • Would be too good to be true to be able to override go build with a makefile. Go generate seems promising, though. – marcio Dec 10 '14 at 16:48
1

I don't believe you can add extra steps.

pkg-config is a special keyword for the built in build system.

Normally, more complex builds are accomplished with a makefile that calls go build at the appropriate step.

David Budworth
  • 11,248
  • 1
  • 36
  • 45