-
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
cmd/go: add *_unix.go recognition (and presumably unix build tag) #20322
Comments
More concretely, does this mean "unix" would mean anything in a pre-defined list of GOOS values? Would we proactively add unsupported GOOS values that might be supported later, like we did with GOARCH values, or would "unix" mean anything that's not windows or plan9 or nacl? Wait, is nacl unix? Also, should we define "posix"? Currently we have some _posix.go files which include windows. I don't object to this, but I'm just curious which definition we'd use. |
All good questions for which I don't know the answer. My main concern is maintaining the long list of os names in the build tags. Making things easier would be an advantage too. Discussion needed. |
I'd suggest the focus should be on user code and the standard library, and a new build tag is required (perhaps "unix"). The standard library has clear manifestations of a notion of "unix" in packages intended for general use (most obviously in net), and I'd suggest any GOOS that implements these should satisfy the build constraint word "unix." For example, if nacl's net package supports network types "unix", "unixgram" and "unixpacket" it would satisfy some of the predicates the "unix" build constraint should require. The *_unix.go convention could implicitly define +build unix. |
That's pretty much what I mean. |
Related: #6325 |
Looking at the list of OSes, the BSD's may be the most homogeneous and largest sublist. But do you count Solaris, Darwin? Even if not, just defining Looking at the feature sets, posix may be the simplest target, but which subset of posix? Is it just the shared subset of all the unix-like OSes currently supported? When a new posix-y OS is added does that mean it can't be added to posix if it's missing one thing the other posix OSes support or do the set of guaranteed features lose a member? Since posix is so vast and as far as I know in practice little agreed upon, that seems the most problematic. Looking at the stdlib, there seems to be very little agreement in practice among which OSes to include, even in Looking to the future, if the list is not proactive, as Brad put it, that means a new OS could suddenly match with a new version of Go when it should not. That may be worrisome but then again currently we have the situation where a new GOOS doesn't match anything without manual intervention. Of course, even a future proofed list is only as good as targets currently known and can't contain as yet uninvented OSes, and then the same issues arise as with posix. |
From a user code perspective it shouldn't matter if the "unix" is bsd, lunix, solaris or other. I'd consider mandating cgo for test purposes for "unix" candidates and having a cgo-centric test suite to make sure all the unix-type-things for a given Go toolchain aren't at odds with the C toolchain as known to the Go toolchain for a given GOOS. |
This is basically a straight duplicate of #6325, as @dominikh points out. The problem here, as there, is that "unix" changes based on various details - sometimes it includes Linux, sometimes not, for example. It's not clear we want to be in the business of defining it exactly one way. Also, this should not affect users terribly much, given that we try to provide OS-independent APIs to the largest extent possible. |
You're skirting the point here, which is just to avoid maintaining the huge list of Unix variants Go supports. It's to discriminate the basic difference between Windows and Unix. Windows has many versions, but there is only one predefined "windows" tag, in the sense the foo_windows.go works. I'm asking for the same courtesy for Unix. |
Ignoring ios and android for the moment, as they're essentially defined to be "variants" of darwin and linux, and only looking at the GOOS build tags, the complete list, as of 1.8, is:
The goal, as I understand it, is to be able to use I'm going to ignore the implications of defining unix or posix and just look at what's in the stdlib so there's some data. (Apologies if I made any mistakes). Looking at the (Windows is not what most people think of when they thing posix. An alternative would be to allow something like † using
For the
Looking at that it seems !windows,!plan9 would get the most existing In practice how build tags are written seems to be somewhat ad hoc. Maybe gofmt could sort them in a standard way or golint warn if they're not alphabetical? Perhaps a new tool that deals solely with build constraints? |
Here's similar for every GOOS build tag : |
It sounds like the real interesting use would be outside the standard library. Can someone survey what usages look like outside, like in the go corpus files? |
Maybe the best expression of "unix" is !windows,!android,!plan9,!nacl as it's much easier to express why a GOOS is !unix and the build tag waters aren't muddied when user code has to pander to particular variants of things that aren't !unix. |
On hold for someone to present evidence about the need for this outside the standard library. |
Any code that needs to support variant operating systems would need this. For example, Upspin has errors_unix.go:5:// +build darwin linux freebsd netbsd Is that the right list? No. What is? I don't know, and the code will go out of date as new variants arise. The code in that file is Unix-generic, but what is Unix from Go's point of view? It seems to me that if we can define golang.org/x/sys/unix then we can define build tag unix and _unix.go. |
I have gathered some stats on the GitHub dataset in BigQuery. First I extracted all the "// +build" lines:
The raw result is attached as lines.csv.gz Then I calculated the cooccurrences using a Neugram script Finally, I normalized the co-occurrence matrix by column (sum=1) and plotted it using How to interpret: OS Y -> OS X cell is whiter if X occurs with Y more often than with the rest of the column. E.g. Plan9 is mentioned together with Windows more often than with anything else. |
There is a new GOOS value to take into account now: aix . About golang.org/x, here are some recent (2018/05/30) data about how it depends on "linux", goos, and goarch . That provides an idea about the amount of work required for adding a new operating system or a new architecture. Number of times the expression: '// +build ...linux...' appears in the sources of each package: Number of times the key-word: 'linux' appears in the sources of each package: Number of times the key-word: 'goos' appears in the sources of each package: Number of times the key-word: 'goarch' appears in the sources of each package: |
dang I thought this was going to be a proposal to port Go to run on the old PDP unix made at bell labs. :( Also, I explored thinking about this awhile back but how hard would it be to port Go to run on top of a virtual OS layer like inferno? |
The go tool does not recognize '_unix' as a file suffix. See (github.com/golang/go/issues/20322).
On Jun 5 2017 I wrote:
Issue #38364 and #37503 may be evidence that the standard library is need enough, because it would make it easier to maintain Unix-like ports outside the main Go tree. Perhaps it would be enough to define unix = all the Unixes and then systems that want to use a unix tag can filter with things like
(There's a proposal to make these better. Still not ready to post that yet.) |
Let's move discussion to #51572. |
The new "unix" build tag matches any Unix or Unix-like system. This is only recognized on go:build lines, not in file names. For #20322 Fixes #51572 Change-Id: I3a991f9e69353b25e259bc6462709cdcd83640fb Reviewed-on: https://go-review.googlesource.com/c/go/+/389934 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Rob Pike <r@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
For #20322 For #51572 Change-Id: Id0b4799d097d01128e98ba4cc0092298357bca45 Reviewed-on: https://go-review.googlesource.com/c/go/+/389935 Trust: Ian Lance Taylor <iant@golang.org> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
From Go 1.19, the build constraint 'unix' proposed in golang/go#20322 is satisfied by any sufficiently Unix-like value of GOOS, as defined by src/go/build/syslist.go. This commit adds a 'UnixOS' list containing the values of GOOS that would satisfy the 'unix' constraint in Go 1.19.
From Go 1.19, the build constraint 'unix' proposed in golang/go#20322 is satisfied by any sufficiently Unix-like value of GOOS, as defined by src/go/build/syslist.go. This commit adds a predefined 'unix' condition with the same meaning, available for use in test scripts. The condition is satisfied if the target GOOS is one of the list of Unix-like systems defined in 'imports.UnixOS'. Fixes rogpeppe#166.
From Go 1.19, the build constraint 'unix' proposed in golang/go#20322 is satisfied by any sufficiently Unix-like value of GOOS, as defined by src/go/build/syslist.go. This commit adds a predefined 'unix' condition with the same meaning, available for use in test scripts. The condition is satisfied if the target GOOS is one of the list of Unix-like systems defined in 'imports.UnixOS'. Fixes rogpeppe#166. Co-authored-by: Daniel Martí <mvdan@mvdan.cc>
From Go 1.19, the build constraint 'unix' proposed in golang/go#20322 is satisfied by any sufficiently Unix-like value of GOOS, as defined by src/go/build/syslist.go. This commit adds a 'UnixOS' list containing the values of GOOS that would satisfy the 'unix' constraint in Go 1.19. Co-authored-by: Paul Jolly <paul@myitcv.io>
From Go 1.19, the build constraint 'unix' proposed in golang/go#20322 is satisfied by any sufficiently Unix-like value of GOOS, as defined by src/go/build/syslist.go. This commit adds a predefined 'unix' condition with the same meaning, available for use in test scripts. The condition is satisfied if the target GOOS is one of the list of Unix-like systems defined in 'imports.UnixOS'. Fixes rogpeppe#166. Co-authored-by: Daniel Martí <mvdan@mvdan.cc>
From Go 1.19, the build constraint 'unix' proposed in golang/go#20322 is satisfied by any sufficiently Unix-like value of GOOS, as defined by src/go/build/syslist.go. This commit adds a 'UnixOS' list containing the values of GOOS that would satisfy the 'unix' constraint in Go 1.19. Co-authored-by: Paul Jolly <paul@myitcv.io>
From Go 1.19, the build constraint 'unix' proposed in golang/go#20322 is satisfied by any sufficiently Unix-like value of GOOS, as defined by src/go/build/syslist.go. This commit adds a predefined 'unix' condition with the same meaning, available for use in test scripts. The condition is satisfied if the target GOOS is one of the list of Unix-like systems defined in 'imports.UnixOS'. Fixes #166. Co-authored-by: Daniel Martí <mvdan@mvdan.cc>
Change https://go.dev/cl/426296 mentions this issue: |
For #20322 For #51572 Fixes #54712 Change-Id: I22fcfa820e83323bfdf1a40deee7286240f02b3e GitHub-Last-Rev: cd2c653 GitHub-Pull-Request: #54716 Reviewed-on: https://go-review.googlesource.com/c/go/+/426296 Run-TryBot: Heschi Kreinick <heschi@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com> Reviewed-by: Bryan Mills <bcmills@google.com>
Change https://go.dev/cl/426814 mentions this issue: |
…ld tag For #20322 For #51572 Updates #54712 Fixes #54736 Change-Id: I22fcfa820e83323bfdf1a40deee7286240f02b3e GitHub-Last-Rev: cd2c653 GitHub-Pull-Request: #54716 Reviewed-on: https://go-review.googlesource.com/c/go/+/426296 Run-TryBot: Heschi Kreinick <heschi@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> (cherry picked from commit 3c6a5cd) Reviewed-on: https://go-review.googlesource.com/c/go/+/426814 Run-TryBot: Bryan Mills <bcmills@google.com>
…ld tag For golang#20322 For golang#51572 Updates golang#54712 Fixes golang#54736 Change-Id: I22fcfa820e83323bfdf1a40deee7286240f02b3e GitHub-Last-Rev: cd2c653 GitHub-Pull-Request: golang#54716 Reviewed-on: https://go-review.googlesource.com/c/go/+/426296 Run-TryBot: Heschi Kreinick <heschi@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> (cherry picked from commit 3c6a5cd) Reviewed-on: https://go-review.googlesource.com/c/go/+/426814 Run-TryBot: Bryan Mills <bcmills@google.com>
Change https://go.dev/cl/437235 mentions this issue: |
Convert a few occurrences that were submitted after CL 389935. For #20322 For #51572 Change-Id: I0047361916c402f8e37f515e6b09d451bd499e6e Reviewed-on: https://go-review.googlesource.com/c/go/+/437235 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
It does understand *_windows.go, and I was surprised to (re)learn that it does not support *_unix.go. Would it do so, things would be clearer and all the *_unix.go files that already exist wouldn't need to maintain their
tags as the list grows.
The text was updated successfully, but these errors were encountered: