Improving Build Efficiency in Go: Cache-Based Solutions
The issue of slow build times in Go, particularly for small cgo-based programs, has prompted the Go community to explore alternative solutions. The go build and go run commands have historically been noticeably slower than expected, leading to a desire for improved caching mechanisms.
One possible solution is to utilize a Makefile with a % rule. However, as the Go language designers suggest, Go's built-in build support should eliminate the need for external tools like Makefiles.
Fortunately, a significant improvement is即将到来。Go 1.10,预计于2018年第一季度发布,将大幅提升go build和go install的构建速度。Go命令现在将维护已构建软件包的缓存和其他小型元数据,默认保存在操作系统定义的用户缓存目录中,但可以通过设置$GOCACHE进行移动。
此构建缓存的主要影响是“go test”和“go build”等命令可以快速运行并始终进行增量构建,尽可能积极地重复使用过去的构建步骤。这意味着用户不再需要使用“go test -i”或“go build -i”或“go install”来获取快速增量构建。
值得注意的是,go install不会安装命名包的依赖项。通过阅读“go build build什么?”,可以进一步了解该命令的具体作用。
以上是Go 1.10 如何提高构建效率,尤其是基于 cgo 的小型程序?的详细内容。更多信息请关注PHP中文网其他相关文章!