You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import (
"fmt"
"runtime/debug"
)
func main() {
info, ok := debug.ReadBuildInfo()
if ok {
fmt.Printf("%s %s\n", "main module path:", info.Main.Path)
} else {
panic("not ok")
}
}
Init as "x": go mod init x
Build a bin file by go build:
use 1.17:
main module path: x
use 1.18, we got:
main module path: x
build a bin file by go build main.go:
use 1.17:
main module path: x
but use 1.18, we got:
main module path:
and use master branch,
main module path:
if we use go version -m binfile:
x build by go build
go version -m x
Mac:$ go version -m x
x: devel go1.20-185766de0f Fri Nov 11 04:31:34 2022 +0000
path x
mod x (devel)
build -buildmode=exe
build -compiler=gc
build CGO_ENABLED=1
build CGO_CFLAGS=
build CGO_CPPFLAGS=
build CGO_CXXFLAGS=
build CGO_LDFLAGS=
build GOARCH=arm64
build GOOS=darwin
main build by go build main.go
go version -m main (no module x)
Mac:$ go version -m main
main: devel go1.20-185766de0f Fri Nov 11 04:31:34 2022 +0000
path command-line-arguments
build -buildmode=exe
build -compiler=gc
build CGO_ENABLED=1
build CGO_CFLAGS=
build CGO_CPPFLAGS=
build CGO_CXXFLAGS=
build CGO_LDFLAGS=
build GOARCH=arm64
build GOOS=darwin
We can get main module info from buildinfo API useing 1.17 (go build or go build xx.go)
But from 1.18, we can't get main module info from buildinfo API if we build bin file using go build xxx.go and this change not written in 1.18 release notes.
The text was updated successfully, but these errors were encountered:
seankhliao
changed the title
runtime/debug: build by command line files can not read main module buildinfo
cmd/go: build by command line files does not contain module info
Dec 2, 2022
Example code:
Init as "x": go mod init x
Build a bin file by
go build
:use 1.17:
use 1.18, we got:
build a bin file by
go build main.go
:use 1.17:
but use 1.18, we got:
and use master branch,
if we use go version -m binfile:
x
build by go buildgo version -m x
main
build by go build main.gogo version -m main (no module x)
We can get main module info from
buildinfo
API useing 1.17 (go build or go build xx.go)But from 1.18, we can't get main module info from
buildinfo
API if we build bin file usinggo build xxx.go
and this change not written in 1.18 release notes.The text was updated successfully, but these errors were encountered: