go - `go build` 不必要地重建

标签 go build

go build 和 go run 在我的一个小程序上非常慢(特别是 cgo 调用)。我想去缓存二进制文件,以便它只在源更新时重建。我会使用带有 % 规则的简单 Makefile,但语言设计者声称 Go 的构建支持不需要 Makefile。

我是否忽略了另一种选择? Go 社区是否更喜欢另一种构建系统(可能是基于哈希的构建系统)来缓存和重用构建产品?

最佳答案

go buildgo install 将很快(Go 1.10,2018 年第一季度)变得更快:参见 this threadthis文档草稿。

The go command now maintains a cache of built packages and other small metadata (CL 68116 and CL 75473). The cache defaults to the operating system-defined user cache directory but can be moved by setting $GOCACHE.
Run "go env GOCACHE" to see the current effective setting. Right now the go command never deletes anything from the cache. If the cache gets too big, run "go clean -cache" instead of deleting the directory. That command will preserve the cache's log.txt file. In a few weeks I'll ask people to post their log.txt files to a Github issue so that we can evaluate cache size management approaches.

The main effect of the build cache is that commands like "go test" and "go build" run fast and do incremental builds always, reusing past build steps as aggressively as possible.
You do not have to use "go test -i" or "go build -i" or "go install" just to get fast incremental builds. We will not have to teach new users those workarounds anymore. Everything will just be fast.

请注意,go install 不会安装指定包的依赖项:请参阅“What does go build build?”。

关于go - `go build` 不必要地重建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32061750/

相关文章:

java - 在 Eclipse 下实现 Java/Android 中的构建配置

xml - 为什么 Go 的 encoding/xml.Decoder.Token() 没有像它应该的那样生成 xml.Attr token ?

caching - Golang 多模板缓存

unit-testing - 如何对 Go 中结构体的特定方法执行单元测试

go - 如何使用 dgo api.NQuad 删除 dgraph 中的四边形

ios - Xcode:没有一个输入目录包含匹配的应用程序图标/启动图像集

c++ - 使用#ifdef 是正确的策略吗

android - 如何让 android-app-module 识别并使用 gradle-plugin-module 源

performance - 如何测量golang中函数的执行时间,不包括等待时间

linux - Maven - 无法在 shell 脚本中创建资源输出目录