可以使用Go构建并添加额外的构建步骤吗?

huangapple go评论76阅读模式
英文:

Is it possible use Go build with extra build steps?

问题

go build不足以满足需求,需要在go build之外运行额外的命令时,应该怎么做?Go工具是否覆盖了这种用例?如果是这样,惯例是什么?

我注意到可以通过以下方式向构建工具传递额外的标志:

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

是否可以运行额外的命令,或者至少告诉go build使用一个Makefile?

英文:

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?

答案1

得分: 4

不,go工具并不打算成为一个通用的构建系统。虽然有一些针对cgo(如pkg-config)的规定,但它并不可扩展。

在go1.4中,将会有一个generate命令。这将允许您运行任意命令来预处理源文件,但它始终必须是一个单独的步骤,需要显式地运行。您不能将其与go getgo buildgo install关联起来。

许多需要更复杂构建的项目使用脚本或Makefile,并避免使用通用的go get能力。然而,库包应该努力成为可get的,以简化依赖解析。

英文:

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.

答案2

得分: 1

我不相信你可以添加额外的步骤。

pkg-config是内置构建系统的一个特殊关键字。

通常,更复杂的构建是通过一个makefile来完成的,在适当的步骤中调用go build。

英文:

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.

huangapple
  • 本文由 发表于 2014年12月10日 22:02:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/27402956.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定