将会构建打包未使用的外部依赖吗?

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

Will go build pack unused external dependencies?

问题

我有一个计划在多个项目中使用的lib模块。它将依赖于许多其他模块。

但并不是所有的项目都会使用lib提供的函数。我想知道如果一个项目只依赖于lib提供的b/func B,在项目构建过程中是否会打包所有未使用的模块?

我了解到Go的最小构建单元是一个包。在这种情况下,ext-depency A模块ext-depency N模块会被打包到我的project模块二进制文件中吗?

我该如何测试这个?

将会构建打包未使用的外部依赖吗?

英文:

I have a lib module planned to be used across projects. It will depend on many other modules.

But not all the projects will use functions provided by lib. I'm wondering if a project only depends on b/func B provided by lib, will it pack all the unused modules during project's build?

I understand go's smallest build unit is a pkg. In such case will ext-depency A module and ext-depency N module pack it into my project module binary?

How can I test this?

将会构建打包未使用的外部依赖吗?

答案1

得分: 2

但并不是所有的项目都会使用库提供的函数。我想知道,如果一个项目只依赖于库提供的 b/func B,那么在项目构建过程中,是否会打包所有未使用的模块?

不会。

我理解,Go 的最小构建单元是一个包。在这种情况下,外部依赖 A 模块和外部依赖 N 模块会打包到我的项目模块二进制文件中吗?

不知道你在问什么。

我该如何测试这个?

检查生成的二进制文件。(不,不要这样做)。

老实说,这完全不是个问题。这里没有什么可看或担心的。生成的二进制文件只包含必要的内容,没有其他东西。未使用的内容在链接过程中会被剥离。

英文:

>But not all the projects will use functions provided by lib. I'm wondering if a project only depends on b/func B provided by lib, will it pack all the unused modules during project's build?

No.

> I understand go's smallest build unit is a pkg. In such case will ext-depency A module and ext-depency N module pack it into my project module binary?

No idea what you are asking.

> How can I test this?

Inspect the generated binary. (No, don't do that).

Honestly, this is a 100% non problem. Nothing to see or worry here. Forget all this. The generated binary contains what is necessary and nothing else. Unused stuff is stripped during linking.

huangapple
  • 本文由 发表于 2022年9月21日 16:46:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/73797855.html
匿名

发表评论

匿名网友

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

确定