containerbuildsystem / cachi2

GNU General Public License v3.0
5 stars 20 forks source link

[Go >=1.21+] Log the actual toolchain to be used for a given module instead of the pre-installed toolchain #550

Open eskultety opened 1 month ago

eskultety commented 1 month ago

Currently, we report the toolchain we selected to process a project, e.g. 1.21.0 (pre-installed) but that toolchain might not end being the one to be used for the given project as the project may specify any micro release for the toolchain it desires (e.g. 1.21.8) which we're currently handling by passing GOTOOLCHAIN=auto to the underlying Go process which will first download the desired toolchain and then process the requested command (and project) with it. We should ideally report the target toolchain that we're invoking instead of the intermediary toolchain that will just download the target one.

eskultety commented 1 month ago

I worried for a moment that we'd fall into the trap of reporting the wrong toolchain due to automatic toolchain switching Go's capable of (e.g. dummy-lib@v0.0.1 requires go >= 1.21.7; switching to go1.21.10), but that only happens during go build and only after go mod tidy (e.g. without running tidy: dummy-lib@v0.0.1 requires go >= 1.21.7 (running go 1.21.4)). In either case, for a project dependency prefetch, all of the mentioned above is irrelevant as the toolchain declared by the main project has always has to be >= to the highest toolchain version of all of its dependencies, IOW the toolchain keyword specified by a dependency only gains meaning when building the dependency itself as the main module, but not when building it indirectly; as confirmed by docs:

Modules that are dependencies of other modules may need to set a minimum Go version requirement lower than the preferred toolchain to use when working in that module directly. In this case, the toolchain line in go.mod or go.work sets a preferred toolchain that takes precedence over the go line when the go command is deciding which toolchain to use.