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: cmd/go: discover module from package being built #68059

Open
rittneje opened this issue Jun 18, 2024 · 3 comments
Open

proposal: cmd/go: discover module from package being built #68059

rittneje opened this issue Jun 18, 2024 · 3 comments
Labels
Milestone

Comments

@rittneje
Copy link

Proposal Details

I am filing this proposal as a followup to #68043.

Currently the go command discovers the module based upon the working directory it is executed from. This results in confusing and unexpected behavior when you do for example go build ./path/to/module/package, since in that case it will either fail (if GO111MODULE=on) or fall back to non-module mode (if GO111MODULE=auto). In the latter case, this also means it will build with the wrong DefaultGODEBUG.

I propose that instead of discovering the module based on the current working directory, the go command instead discovers it based upon the location of the package you are building. So in the example of go build ./path/to/module/package, it will use the module rooted at ./path/to/module, assuming that ./path/to/module/go.mod exists.

@gopherbot gopherbot added this to the Proposal milestone Jun 18, 2024
@bjorndm
Copy link

bjorndm commented Jun 19, 2024

This will be difficult for backwards compatibility reasons. A go.work file might help, or perhaps a new environment variable could be added.

@rittneje
Copy link
Author

@bjorndm What backwards compatibility reasons?

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

No branches or pull requests

4 participants