-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: cmd/go: build tag for detecting go modules usage #37995
Comments
It may not be necessary to use a build tag to achieve compatibility for both modes because of "minimal module-awareness for legacy operation" that was implemented in commit d4e2128 and issue #25069. Are you familiar with that behavior? |
So how do I achieve my aim? As it stands adding @dmitshur on a separate matter did you get my email from about a week ago? |
Minimal module compatibility lets code built in GOPATH mode stay compatible in this situation. The Modules wiki has more information about this. If a package has a The path |
github.com/cenkalti/backoff default branch is set to v4. When in gopath mode does it use master which is quite old? |
Yes. If you want to support GOPATH-mode users with this particular dependency, probably the simplest approach is to use GOPATH-mode users would then build your dependencies from your |
Is there a way to use this solution just for 1 dependency? |
I don't think so, no — but users who are sensitive to extra dependencies should generally be building in module mode anyway. |
In the blog post: https://blog.golang.org/v2-go-modules they recommend the separate directory approach. They mention the downsides are maintaining 2 separate codebases (this is a big downside I am already facing). They say the benefits are compatibility with GOPATH mode. They didn't mention the issue I just faced. Is this still the recommend approach? For my package, I'd love to abandon the separate directory approach since it looks like supporting GOPATH is not viable (and never was). It's possibly too late now to abandon it because I may have GOPATH users already pointing to the |
Also what's wrong with a build tag for detecting GO MODULES enabled? |
In
If you have I don't know enough about As @bcmills mentioned, you may be able to check in a
We'd rather not add features if there's already a way to solve a problem. There are some options here, and we'd like to be sure none of those can work before pursuing something new. |
That doesn't seem to be the case.
This is not viable. It's already a nuisance maintaining a |
At this point I think you could reasonably just use modules unconditionally in your new versions. |
This proposal has been added to the active column of the proposals project |
Based on the discussion above, this proposal seems like a likely decline. |
No change in consensus, so declined. |
It would be nice if there was a build tag for detecting if go modules is being used.
I have created a package: https://github.com/rocketlaunchr/dbq. I went out of my way to put v2 in a separate
v2
directory so that it would be compatible with go module users and non-go module users. This is supposedly preferred practice.For v2, I want to introduce a dependency (https://github.com/cenkalti/backoff) that is at v4 but did not use the separate directory approach.
For my package, in order to support Go Modules and non-modules users, I need to use a build tag so that I can use
github.com/cenkalti/backoff/v4
for go modules users andgopkg.in/cenkalti/backoff.v4
for non-go modules users.The text was updated successfully, but these errors were encountered: