Does building with an older golang use package sources from that older version?

125 views
Skip to first unread message

Andrew Athan

unread,
Jan 10, 2024, 8:08:19 PM1/10/24
to golang-nuts
Say I install golang 1.20.12 and go clean -cache and go clean -modcache.

Then I build.

Will that executable be using crypto/tls and other packages "as they were in 1.20.12"? Or is golang fetching the newest available compatible sources, and therefore I may be spinning my wheels trying to see if there is a bug in the latest crypto/tls?

Axel Wagner

unread,
Jan 11, 2024, 12:26:55 AM1/11/24
to Andrew Athan, golang-nuts
You don't even need to run `go clean`. Go will automatically detect whether stuff needs to be rebuilt, as the Go version used to build a package is part of a hash, that is used as a key for the build cache.
And yes, it will use the standard library packages of the Go version that is installed (the one output by `go env GOROOT`). In fact, if you just change the on-disk content of those packages (e.g. edit `$(go env GOROOT)/src/fmt/format.go`) it will automatically detect that and rebuild the changed standard library packages as needed, just like it would with a first party package. This can be a very useful (and fun) debugging tool, as it means you can actually insert debug printfs *into the stdlib* to see what is happening.

All of this assumes your Go installation is setup correctly, of course.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/597a23f1-e212-455a-b621-e64108281da8n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages