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

plugin: go build -plugin included package versions seem to be affected by *other* modules in the same workspace #58639

Closed
karelbilek opened this issue Feb 22, 2023 · 4 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge

Comments

@karelbilek
Copy link

karelbilek commented Feb 22, 2023

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

$ go version
go version go1.19.6 darwin/arm64

Does this issue reproduce with the latest release?

Yes, I tried 1.20.1. I can also reproduce it on Linux Intel

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

go env Output
$ go env
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/karelbilek/Library/Caches/go-build"
GOENV="/Users/karelbilek/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/karelbilek/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/karelbilek/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.19.6"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/10/l59c1gsx2tj2k0023f0yvfbc0000gn/T/go-build23416097=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I try to build a plugin, which is a module in workspace, and then use it in another go application.

Minimal example is here, as it involves three different modules and one workspace

https://github.com/karelbilek/go-pluginbug-example

mymain/ is a main module that calls plugin.Open. work/myplugin is a plugin code. work/myother is an unrelated package.

./build.sh does the operation of building work/myplugin as a plugin, then moving it to mymain/ and loading it.

What did you expect to see?

Everything will work, as mymain/ and work/myplugin are using same version of the dependency golang.org/x/sys/execabs.

What did you see instead?

panic: plugin.Open("myplugin"): plugin was built with a different version of package golang.org/x/sys/execabs

When I remove work/go.work, everything works. When the "unrelated" module work/myother is using same version, everything work.

It seems like the version of golang.org/x/sys/execabs in a different module in the same workspace is affecting, which version is included when built as a -plugin. I don't think this is an expected behaviour; it certainly is not intuitive.

This is actually a root cause of this issue in golangci-lint - golangci/golangci-lint#3603 (golangci-lint supports private linters that are loaded as plugins).

I am not sure what dependency is actually built into the plugin; if the bigger one, or the smaller one.

@karelbilek
Copy link
Author

There is #58639 but it seems unrelated.

@seankhliao
Copy link
Member

working as expected for workspaces, everything shares a same set of dependency versions.

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For questions please refer to https://github.com/golang/go/wiki/Questions

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Feb 22, 2023
@karelbilek
Copy link
Author

Thank you for quick answer.

I am still not sure how workspaces work then, but I will ask elsewhere.

@karelbilek
Copy link
Author

Sorry for continuing, I will just note for others.

If someone gets to this issue at a different time and needs to solve how to build plugin with go.mod dependencies and not go.work ones (concretely for golangci-lint, but maybe for other cases), just use GOWORK=off when doing go build -plugin. That's all.

@golang golang locked and limited conversation to collaborators Feb 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge
Projects
None yet
Development

No branches or pull requests

3 participants