-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: allow replace directives in go.mod to work for standard libraries #35283
Comments
Or you can patch your stdlib, which a number of projects do. I'd liike to see Go support for patching stdlib & runtime, e.g. an env variable giving a patchfile or directory, and a way to amend the version string to "1.13.3_myproject-1.1" |
This is in general not possible. The standard library is not a collection of individual modules. It is more like a single module. That is, the packages in the standard library are very tightly coupled. You can't mix and match some from one version of Go and some from another, nor some hacked up and some not. |
@rsc, what do you think about Go support for patching stdlib & runtime, e.g.
|
To expand on @rsc's comment, @networkimprov Why not just patch GOROOT directly and build a toolchain from there? That seems far simpler. |
@jayconrod $GOROOT contents may be discarded on upgrade. And any patches are invisible at build-time. You wouldn't want everything you build to carry patches necessary for a certain app. I currently patch my $GOROOT directly, but runtime.Version() does not reflect this fact. I looked for a way to amend the .Version() result, but didn't come up with something straightforward. I forget why offhand... |
There are a lot of ways to handle this. For example, as commits on a branch that gets rebased after upgrading. Or as a list of files applied by a bash script.
I think you can write to In general though, anyone who's patching the standard library or toolchain in their project has a fairly specialized use case, and I wouldn't expect one solution to work for everyone. This is a bit off-topic from the original issue in any case ( |
Thanks for the thoughtful replies. It sounds like the premise of my proposal was off-base, so more generally: I think it'd be helpful to have a portable way to patch standard packages imported by a Go project, "portable" in this sense meaning being able to use a module that patches standard packages with nothing more than Is there a potential place for some mechanism along those lines in Go? |
@jayconrod since the original suggestion isn't achievable, I'd like to hear from @rsc whether a patch-support proposal is worth investing time in. It would solve the stated problem. Patching runtime or stdlib should not require a git-clone of the Go project, nor a toolchain build from source. A number of Windows users currently duplicate stdlib code in order to patch it; see #34681. |
I wouldn't support this proposal. It would result in modules running slightly different, incompatible dialects of Go. That would prevent the ecosystem from scaling and would cause problems for large projects. It's also not clear how this would be implemented. Would I'm not familiar with the details of file flags in #34681. My (somewhat uninformed) opinion is that if a standard library package isn't working as desired, it should either be fixed (assuming it won't break other users) or forked. |
If you want to patch the standard library, I would say go ahead and do that. This proposal is a likely decline: it's too invasive for too little benefit. |
One reason many projects need patches is that each Go release stops getting regression fixes after 6 months (see #34622). What would you think of a proposal re adjusting the runtime.Version() result to reflect a non-released (e.g. patched) instance? |
You can set the Version by creating a I've found it's relatively easy to maintain a custom branch (eg, go1.13.4mpx) and tags when I want to use newer features but need (otherwise outstanding) fixes to the stable tree. This works, provided you don't want to distribute source to people who don't use your branch. |
Thanks, but patching runtime or stdlib should not require a git-clone of the Go project, nor a toolchain build from source (which I mentioned above :-) I currently distribute a stdlib patch in my releases, which has to work after |
I forgot to add the final comment label last week. This is still a likely decline. |
If people want to replace specific parts of the standard library, I think #30241 or something similar would provide a more consistent way to do that. If we decide that a given standard-library package should be independently upgradeable, we can make that package forward to a corresponding package in some other, actual module (such as |
Consensus did not change, so declining. |
This may be completely incompatible with Go's architecture, but I'm putting it out there as a request for comments :)
Basically, make this work:
This would allow for forking standard libraries without requiring users to use a forked version of Go. In my case, I've implemented #22836 and would like to use it in my project without maintaining a full Go fork.
What version of Go are you using (
go version
)?The text was updated successfully, but these errors were encountered: