the_endian
the_endian

Reputation: 2527

Are transitive dependencies built into a default (statically linked) final Go program binary?

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?

Upvotes: 1

Views: 85

Answers (1)

Dietrich Epp
Dietrich Epp

Reputation: 213827

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.

Upvotes: 1

Related Questions