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: runtime: add custom types and constants for GOOS, GOARCH #64046
Comments
I think that this kind of stuff should be it in a separate package like |
@mateusz834 I don't think its worth it. Its just a couple of constants. Creating a file - goos.go and putting it up there makes more sense. If u can outline what u want to put over there, it would make more sense to me |
Second is okay, it doesn't bloat runtime. but since GOOS is inside runtime, it makes more sense to keep it inside runtime. |
I don't understand the benefit of doing |
@randall77 it makes a huge difference actually. The Compiler catches the typos and accidental mistakes during refactoring, which could go unnoticed until manually tested or BDD tests are written Plus i don't think remembering all the 42 pairs is necessary |
I don't agree, having constants like Windows, Linux, Plan9 would make it not easy to find all of them through a lsp, if this were to be defined in runtime the constants should be prefixed with some kind of |
I would prefer: GOOS_WINDOWS over GOOSWindows . I agree its ok to put it over goos pkg with updated runtime.GOOS doc |
What do you expect to happen to the constant when support for a GOOS or GOARCH is dropped? What about other Go implementations like TinyGo that support a different set of geese and architectures? |
FWIW, GOOS and GOARCH comparisons are a bit unique in that they require more infrastructure to actually run tests for them. It reminds me of #20616. Granted it's hard to imagine writing the comparison in the first place if that kind of infrastructure isn't accessible. That said, this seems like it would be fine as a custom linter, given the rarity of the problem. You could even parse the output of |
@gophun i m not sure whether its doable to drop support for GOOS,GOARCH cuz its not backward's compatible |
@Nasfame Multiple GOOS and GOARCH values have already been dropped in Go's history. NaCl and amd64p32 come to mind. |
@zephyrtronium I see, go toolchain support removed support for different platforms. I get it.. So in that case we can deprecate the constants!! |
Still, what about other Go implementations with different GOOS/GOARCH sets? They can't have different versions of this package; otherwise, a project wouldn't compile with implementation A simply because there's an 'if' check for a platform supported by implementation B but not by A. My opinion: |
@gophun the constants are not going to have different versions. No build directives!! . Its like GOOS values are defined in go source code. I think it makes more sense to compare with those defined values rather than user defined values |
So, will there be constants for all the GOARCHs that gccgo can target, but gc can't? Like alpha, arc, avr32, blackfix, c6x, cris, frv, h8300, hexagon, ia64, m32r, m68k, metag, microblaze, mn10300, nios2, openrisc, parisc, score, sh, tile, unicore32, vax, xtensa |
@gophun The type of GOARCH is still string, so there is still flexibility to compare with all the archs. But I personally think its unnecessary to include architectures and stick the os-arch pairs mentioned in the proposal. If a ticket comes up to include all the architectures supported by gccgo....... |
Proposal: Add custom types and constants for GOOS, GOARCH
Motivation
The current
GOOS
andGOARCH
variables are strings, making it difficult to write platform-specific code. Adding custom types and constants would make it easier and more reliable.Design
Add the GOOS, GOARCH types and constants to the
runtime
package:Prototype
Proposed Implementation for GOOS: https://go.dev/play/p/iXj3bRkQxwL
time.Sleep
??Benefits
runtime.GOOS=="windows"
Backwards Compatibility
To ensure backwards compatibility:
fork src/runtime/extern.go to exter_go1.21.go or use build directives. Currently none employed, so no complications.The text was updated successfully, but these errors were encountered: