Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve runtime/debug Go 1.18 incompatibility via stable go.mod file parsing #130

Merged
merged 1 commit into from
Nov 15, 2022

Conversation

svengreb
Copy link
Owner

Resolves #129

As of Go 1.18 [1] the debug.ReadBuildInfo [2] function does not work for
Mage executables anymore because the way how module information is
stored changed. Therefore the fields of the returned debug.Module [3]
type only has zero values, including the module path.
The debug.Module.Version [4] field has a default value [5] (`(devel)`)
which is not Semver compatible and causes the parsing to fail.
The change in Go 1.18 [9] also came with the new `debug/buildinfo`
package [10] which allows to read the information from compiled binaries
while the `runtime/debug.ReadBuildInfo` function returns information
from within the running binary. Both are not suitable anymore which is
also described in the Go 1.18 `version` command release notes:

  "The underlying data format of the embedded build information can
  change with new `go` releases, so an older version of `go` may not
  handle the build information produced with a newer version of `go`.
  To read the version information from a binary built with `go` 1.18,
  use the `go` version command and the `debug/buildinfo` package from
  `go` 1.18+."

To get the required module information that was previously provided by
the runtime/debug [6] package the official golang.org/x/mod/modfile [7]
package is now used instead that provides the implementation for a
parser and formatter for `go.mod` files [8] [^1]. This allows to safely
get the module path without the need to depend on runtime/dynamic logic
that might change in future Go versions.

Note that this change also increased the minimum Go version from `1.17`
to `1.19`!

[1]: golang/go@9cec77ac#diff-abdadaf0d85a2e6c8e45da716909b2697d830b0c75149b9e35accda9c38622bdR2234
[2]: https://pkg.go.dev/runtime/[email protected]#ReadBuildInfo
[3]: https://pkg.go.dev/runtime/debug#Module
[4]: https://github.com/golang/go/blob/9cec77ac/src/runtime/debug/mod.go#L52
[5]: https://github.com/golang/go/blob/122a22e0e9eba7fe712030d429fc4bcf6f447f5e/src/cmd/go/internal/load/pkg.go#L2288
[6]: https://pkg.go.dev/runtime/[email protected]
[7]: https://pkg.go.dev/golang.org/x/mod/modfile
[8]: https://pkg.go.dev/cmd/go#hdr-The_go_mod_file
[9]: https://tip.golang.org/doc/go1.18#go-version
[10]: https://tip.golang.org/doc/go1.18#debug/buildinfo

[^1]: https://go.dev/ref/mod#go-mod-file

GH-129
@svengreb svengreb added this to the version-next milestone Nov 15, 2022
@svengreb svengreb self-assigned this Nov 15, 2022
@svengreb svengreb merged commit df29129 into main Nov 15, 2022
@svengreb svengreb deleted the improvement/gh-129-go-1.18-module-file-parsing branch November 15, 2022 22:23
@svengreb svengreb removed their assignment Nov 15, 2022
@svengreb svengreb changed the title Improve runtime/debug Go 1.18 incompat. via go.mod file parsing Improve runtime/debug Go 1.18 incompatibility via stable go.mod file parsing Jul 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve runtime/debug Go 1.18 incompatibility via stable go.mod file parsing
1 participant