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: can't build plugin package when module is named plugin #58321

Closed
titpetric opened this issue Feb 4, 2023 · 4 comments
Closed

cmd/go: can't build plugin package when module is named plugin #58321

titpetric opened this issue Feb 4, 2023 · 4 comments

Comments

@titpetric
Copy link

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

$ go version
go version 1.19.5

Does this issue reproduce with the latest release?

/

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/root/go/1.19.5/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/go/1.19.5"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/root/.goenv/versions/1.19.5"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/root/.goenv/versions/1.19.5/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19.5"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/root/plugin-compiler/plugin/go.mod"
GOWORK="/root/plugin-compiler/go.work"
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 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2071767594=/tmp/go-build -gno-record-gcc-switches"

What did you do?

  1. created a workspace,
  2. checked out anything really,
  3. created a plugin/ folder,
  4. after adding both folders to the workspace, I tried adding a module for plugin/
root@carbon:~/plugin-compiler/plugin# go mod init plugin 
go: creating new go.mod: module plugin
go: to add module requirements and sums:
	go mod tidy
root@carbon:~/plugin-compiler/plugin# go mod tidy
go: warning: "all" matched no packages
  1. tried adding code for plugin.go (works with go run plugin.go)
package main

import (
	"net/http"
)

func InternalServerError(rw http.ResponseWriter, r *http.Request) {
	rw.WriteHeader(http.StatusInternalServerError)
}

func main(){}
  1. tried tidy and a compile
# go mod tidy
go: warning: "all" matched no packages
# go build -buildmode=plugin .
-buildmode=plugin requires exactly one main package

What did you expect to see?

Successfully built plugin.

What did you see instead?

Complaints about having one main package:

# go list -m 
plugin
github.com/TykTechnologies/tyk
@seankhliao seankhliao changed the title affected/package: plugin, can't build with go workspaces plugin: can't build with go workspaces Feb 4, 2023
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Feb 4, 2023
@bcmills
Copy link
Member

bcmills commented Feb 6, 2023

The problem is the module path: go mod init plugin gives the package an import path of plugin, which collides with the standard-library plugin package.

Go 1.20 at least gives a somewhat more helpful error message:

plugin$ go1.19.5 build -buildmode=plugin .
-buildmode=plugin requires exactly one main package

plugin$ go1.20 build -buildmode=plugin .
ambiguous import: found package plugin in multiple modules:
        plugin (/tmp/tmp.EDj1P18TNO/plugin)
         (/usr/local/google/home/bcmills/sdk/go1.20/src/plugin)

@bcmills bcmills added GoCommand cmd/go and removed compiler/runtime Issues related to the Go compiler and/or runtime. labels Feb 6, 2023
@bcmills bcmills changed the title plugin: can't build with go workspaces cmd/go: can't build plugin package when module is named plugin Feb 6, 2023
@bcmills
Copy link
Member

bcmills commented Feb 6, 2023

Duplicate of #39285

@bcmills bcmills marked this as a duplicate of #39285 Feb 6, 2023
@bcmills bcmills closed this as not planned Won't fix, can't repro, duplicate, stale Feb 6, 2023
@bcmills
Copy link
Member

bcmills commented Feb 6, 2023

Duplicate of #35270

@bcmills bcmills marked this as a duplicate of #35270 Feb 6, 2023
@titpetric
Copy link
Author

@bcmills called it! Thank you very much.

@golang golang locked and limited conversation to collaborators Feb 7, 2024
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