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

cmd/go: build by command line files does not contain module info #57049

Closed
oiooj opened this issue Dec 2, 2022 · 1 comment
Closed

cmd/go: build by command line files does not contain module info #57049

oiooj opened this issue Dec 2, 2022 · 1 comment

Comments

@oiooj
Copy link
Member

oiooj commented Dec 2, 2022

Example code:

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.

@oiooj oiooj added the modules label Dec 2, 2022
@seankhliao 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
@seankhliao
Copy link
Member

Working as intended, see CL 339170

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Dec 2, 2022
@golang golang locked and limited conversation to collaborators Dec 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants