英文:
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 get
、go build
或go 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论