Will go build pack unused external dependencies?

80 Views Asked by At

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?

enter image description here

1

There are 1 best solutions below

0
Volker On

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.