英文:
golang - reuse previously built executables if code did not change
问题
我有一个相当大的Go语言项目,它生成了几个可执行文件。当我更新代码时,我希望有一种简单快捷的方式来重新构建它们。然而,构建所有可执行文件需要大约20-25秒的时间,而我大部分时间只更改了1或2个文件。
最终目标是尽可能快地检测到更改,并只重新构建已更改的目标(持续集成)。
附注:项目的某些部分使用了cgo,这占据了构建时间的40-50%。
英文:
I have a pretty big golang project that produces several executables,
when I update my code I want an easy and fast way to rebuild all of them
however it takes ~20-25 sec to build all of them and most of the time I change just 1 or 2
The ultimate goal - detect what changed and rebuild only changed targets as fast as possible(CI)
p.s. some parts of project use cgo, and this takes the 40-50% of the build time
答案1
得分: 6
从你的项目的顶层目录开始执行以下命令:
go install ./...
这将把所有的二进制文件安装到 $GOPATH/bin 目录下。
go install
会缓存构建产物(与 go build
不同),因此可以按照你的需求进行增量构建。
英文:
From the top level of your project
go install ./...
Should install all the binaries into $GOPATH/bin
go install
caches the build artifacts (unlike go build
) so should do incremental builds exactly as you want.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论