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

proposal: plugin: allow overlaying go.mod from another package #29717

Closed
eternal-flame-AD opened this issue Jan 13, 2019 · 1 comment
Closed

Comments

@eternal-flame-AD
Copy link

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

$ go version
go version go1.11.4 linux/amd64

Does this issue reproduce with the latest release?

yes

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

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/ef/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/ef/code/go/"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/go"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build950175600=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Plugins can not be loaded if it shared a dependency with the host package and the required dependency version declared in the host package go.mod is lower than that in the plugin package. An example here.

What did you expect to see?

As there might be several common dependencies(both direct & indirect) between the host package and the plugin package, managing the version constraints manually could be annoying.

Since there is no way to tell go which main package the plugin package is built for, a workaround to this problem is to manually copy all common dependency requirements from the server go.mod, however it requires a lot of human intervention and a non-synchronized go.mod will cause subsequent builds to fail.

The Proposal

I think we can add a comply directive to go.mod. The directive will tell go module system the package dependencies need to be in comply with another main package, as it will be built as a plugin for that package.

module github.com/eternal-flame-AD/gomod-overlay-demo/plugin

comply (
    github.com/eternal-flame-AD/gomod-overlay-demo/server@v1.0.0
)

The comply directive poses these effects:

  • When executing go mod tidy, all applicable require, exclude and replace directives from given version of the foreign module are applied into the current go.mod (In this example, when executing go mod tidy on the plugin module, the version requirement on github.com/gin-gonic/gin will be changed to in comply with the server(v1.1.4))
  • When downloading modules, abort with error if the calculated dependencies does not comply with the packages indicated in the comply directive
@gopherbot gopherbot added this to the Proposal milestone Jan 13, 2019
@rsc
Copy link
Contributor

rsc commented Jan 16, 2019

Plugins require exact package matching, sorry. That's fundamental to ensuring their safety. There's nothing we can do in go.mod to change this.

@rsc rsc closed this as completed Jan 16, 2019
@golang golang locked and limited conversation to collaborators Jan 16, 2020
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