最小重新编译

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

Minimal recompilation

问题

我有一个被许多其他模块使用的Go模块。我希望在进行简单实现更改时尽量减少重新编译的工作量。我该如何做到这一点?

例如,

package mymodule

import "fmt"

func MyFunc() {
    // 旧代码 -> fmt.Println("one")
    fmt.Println("two")
}

理论上,只需重新编译mymodule并将其与其他模块的.o文件重新链接,就可以实现这样的更改,而无需重新编译依赖于它的模块。

Go的go build或其他命令是否可以实现这一点?如果不能,我该如何实现?

英文:

I have a go module that a lot of other modules use. I want to achieve minimal recompilation in case of a simple implementation change. How do I go about this?

For example,

package mymodule

import "fmt"

func MyFunc() {
    // old code -> fmt.Println("one")
    fmt.Println("two")
}

A change like this can theoretically just be relinked with the .o files of other modules after recompiling mymodule without recompiling modules that depend on it.

Does go build or any other command do this? If not, how do I achieve this?

答案1

得分: 1

这已经由标准的Go编译器处理了。你不需要做任何事情。

实际上,正是这个使用案例在很大程度上激发了Go的创造。你可以阅读更多相关信息

起初,我们在Google的一些大型软件中遇到了长时间的编译时间,即使使用了我们庞大的分布式编译集群。C和C++中的依赖管理(或者说缺乏依赖管理)导致太多的代码需要通过编译器。

可以说,Go是在等待一个大型编译过程时构思出来的。

英文:

This is already handled by the standard Go compiler. You need to do nothing.

In fact, it was this very use case that largely inspired the creation of Go in the first place. You can read more about it.

> The starting point was long compile times—for some of our big software at Google, build times can be unreasonably long, even with our large distributed compilation clusters. The dependency management (or lack thereof) in C and C++ results in far too much code going through the compiler.
>
> You might say that Go was conceived while waiting for a big
> compilation.

huangapple
  • 本文由 发表于 2021年7月13日 16:09:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/68358757.html
匿名

发表评论

匿名网友

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

确定