what is //go:build difference from //+build?

882 views
Skip to first unread message

xie cui

unread,
Jun 15, 2022, 10:37:16 PM6/15/22
to golang-nuts
about when these feature add to golang?
and is all we can do with //go:build can do with //+build, and vice versa?

Holloway Kean Ho

unread,
Jun 15, 2022, 10:50:21 PM6/15/22
to golang-nuts
They are build-constraints for cross platform support. Doc: https://pkg.go.dev/cmd/go#hdr-Build_constraints

I believe to-date is only using go:build. +build was for Go 1.16 and before so only use that if you plans to support legacy compiler.

Kurtis Rader

unread,
Jun 15, 2022, 10:51:10 PM6/15/22
to xie cui, golang-nuts
See https://stackoverflow.com/questions/68360688/whats-the-difference-between-gobuild-and-build-directives not to mention many other answers to your question. I don't understand your question. Languages like Go, and their associated tools, evolve. In this case the people improving Go decided that a change to the syntax of the magic comments recognized by the Go tool chain made sense. I fail to see the point or your question.

On Wed, Jun 15, 2022 at 7:37 PM xie cui <cuiw...@gmail.com> wrote:
about when these feature add to golang?
and is all we can do with //go:build can do with //+build, and vice versa?

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/252435eb-c787-4f2f-8608-1dc578f66404n%40googlegroups.com.


--
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

peterGo

unread,
Jun 16, 2022, 10:57:12 AM6/16/22
to golang-nuts
Bug-resistant build constraints — Draft Design

Russ Cox
June 30, 2020

https://go.googlesource.com/proposal/+/master/design/draft-gobuild.md

Peter

peterGo

unread,
Jun 16, 2022, 11:09:36 AM6/16/22
to golang-nuts
This information is in the release notes.

Go 1.17 Release Notes
https://go.dev/doc/go1.17

//go:build lines

The go command now understands //go:build lines and prefers them over // +build lines. The new syntax uses boolean expressions, just like Go, and should be less error-prone. As of this release, the new syntax is fully supported, and all Go files should be updated to have both forms with the same meaning. To aid in migration, gofmt now automatically synchronizes the two forms. For more details on the syntax and migration plan, see https://golang.org/design/draft-gobuild.

Go 1.18 Release Notes
https://go.dev/doc/go1.18

//go:build lines

Go 1.17 introduced //go:build lines as a more readable way to write build constraints, instead of // +build lines. As of Go 1.17, gofmt adds //go:build lines to match existing +build lines and keeps them in sync, while go vet diagnoses when they are out of sync.

Since the release of Go 1.18 marks the end of support for Go 1.16, all supported versions of Go now understand //go:build lines. In Go 1.18, go fix now removes the now-obsolete // +build lines in modules declaring go 1.18 or later in their go.mod files.

For more information, see https://go.dev/design/draft-gobuild.

Peter


On Wednesday, June 15, 2022 at 10:37:16 PM UTC-4 cuiw...@gmail.com wrote:
Reply all
Reply to author
Forward
0 new messages