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

Support for go modules #124

Closed
joshuarubin opened this issue Jul 19, 2018 · 5 comments
Closed

Support for go modules #124

joshuarubin opened this issue Jul 19, 2018 · 5 comments

Comments

@joshuarubin
Copy link

Beginning in go 1.11 go will have opt-in support for the vgo module system proposed by Russ Cox.

We've started testing support for this using Go tip and have run into an issue with mage.

We have a library that we use with our common mage operations. It is tagged and has a version greater than 1. As a result, its go.mod file lists the module as something like module github.com/foo/bar/v2. This means that imports of this module in the magefile would use import bar "github.com/foo/bar/v2" even though the module is downloaded (and would have been placed in the $GOPATH) at github.com/foo/bar.

The error we get when trying to compile the magefile is something like:

Error: failed to check types in directory: magefile.go:18:8: could not import github.com/foo/bar/v2 (cannot find package "github.com/foo/bar/v2" in any of:
        ~/go/src/github.com/foo/baz/vendor/github.com/foo/bar/v2 (vendor tree)
        ~/.gvm/gos/master/src/github.com/foo/bar/v2 (from $GOROOT)
        ~/go/src/github.com/foo/bar/v2 (from $GOPATH))

This stems from the fact that the stdlib go/* packages do not (and may never: golang/go#26433) support modules. The recommendation was to, instead, use the still in development golang.org/x/tools/go/packages package (which will only support Go 1.11 and later).

Until this issue is resolved, mage can't work seamlessly with go modules at all. Either we import with github.com/foo/bar in the magefile and vgo will use the latest v1 release (which is the wrong version), or we import github.com/foo/bar/v2 in the magefile and mage fails to build the magefile at all.

@natefinch
Copy link
Member

Someone else saw this same error... I'll have to look into it. I think it may not be modules. It may be the fact that mage uses a customized version of go/build.

@rsc
Copy link

rsc commented Jul 19, 2018

golang.org/x/tools/go/packages will support Go 1.10 as well, probably not Go 1.9.

@rsc
Copy link

rsc commented Jul 20, 2018

I just tried the latest version of mage and reproduced the problem. It looks like it really is modules. But I have a fix for go/build for Go 1.11 that should make mage and many other programs keep working.

@natefinch
Copy link
Member

Thank you @rsc, I really appreciate it.

@natefinch
Copy link
Member

This is fixed by #131

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants