英文:
Are transitive dependencies built into a default (statically linked) final Go program binary?
问题
在Go编程语言中,假设使用默认的“静态链接”构建,我想知道以下情况:假设我的go.mod
文件中有2个模块,但go.sum
文件中有50个模块(假设每个go.mod
中的2个模块都有25个传递依赖),这50个模块是否都会被构建到我的程序输出的二进制文件中?也就是说,go build
命令是否会获取这些传递依赖并将它们全部编译,并将它们静态链接到输出的二进制文件中?如果是这样,它是针对整个模块还是只针对程序实际引用的部分进行的呢?
对于vendored依赖,它的行为是否相同?
英文:
In the Go
programming language, assuming a default "statically linked" build, I'm wondering if, for example in the case I have 2 modules in go.mod
but 50 in go.sum
, (assume 25 transitive for each of the 2 in my go.mod
), are all 50 of the modules listed in go.sum
actually going to be built into my program's output binary? That is, does go build
fetch those transitive dependencies and compile them all, statically linking them into the output binary? If so, Does it do so for the entire modules or only the portions actually referenced by my program?
Does it behave in the same manner for vendored dependencies?
答案1
得分: 1
Go只会构建和链接实际被你的程序部分引用的包(包括传递引用)。
正如你所指出的,go.sum
文件可能比你的项目实际需要构建的包集合要大得多(在你的系统上,使用所选配置)。go.sum
(和go.mod
)文件中将包含对仅在某些配置下才需要的包的引用,这是其中一个原因。
英文:
Go will only build and link the packages actually referenced by the parts of your program being built (including transitive references).
As you noted, the go.sum
file may be larger--possibly much larger--than the set of packages your project actually requires in order to build (on your system, with the selected configuration). Among other reasons, the go.sum
(and go.mod
) file will contain references to packages which are only needed under certain configurations.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论