Skip to content

cmd/go: go build ./... may or may not write executable to disk depending how many packages the import path pattern matches #39515

Open
@xyzst

Description

@xyzst

What version of Go are you using (go version)?

$ go version
go version go1.14.3 darwin/amd64

Does this issue reproduce with the latest release?

Issue is reproduced with the latest release.

What operating system and processor architecture are you using (go env)?

OS: macOS Catalina (10.15.5)

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/cest-la-vie/Library/Caches/go-build"
GOENV="/Users/cest-la-vie/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/cest-la-vie/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.14.3/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.14.3/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/cest-la-vie/fsociety/dev/go/go-build-issue/L1/M0/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/qc/_15tg89d2xg2blsddq6f9zkc0000gn/T/go-build913708293=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I am trying to build a go module using go build ./... in the same directory as go.mod. It works fine when there's only a single go package (main) and file. But adding another package and file, referencing those functions in main, and executing the aforementioned command does not generate the executable.

I have a very basic go project that reproduces this issue (includes instructions): https://github.com/xyzst/go-build-bug

What did you expect to see?

An executable should be generated in the same directory as go.mod

What did you see instead?

The binary is not generated and I am not able to locate it anywhere.

There are workarounds available:

  • go install ./... still works as intended and the binary is found in the expected location at $GOPATH/bin
  • go build ./path/to/go/file/with/mainpkg.go will generate the binary as expected

Metadata

Metadata

Assignees

No one assigned

    Labels

    GoCommandcmd/goNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions