Skip to content

proposal: cmd/go: allow fine-grained go build constraints for go version #71951

Closed as not planned
@pjebs

Description

@pjebs

Proposal Details

It would be great if *.go files can allow more fine-grained version constraints.
The go.mod file permits it - so it seems like an incongruency.

My project is dealing with compiled object files which have been compiled on a very specific go version/OS/arch. It is important to be able to differentiate between different versions of go with precision.

=== go.mod ===
module mymod
go 1.22.3

=== main1.go ===
//go:build go1.23.5 && !go1.23.6
package main
func main() {
	println("built using go1.23.5")
}

=== main2.go ===
//go:build go1.23.6 && !go1.24
package main
func main() {
	println("built using go1.23.6")
}
$ go1.23.5  run .
package mymod: build constraints exclude all Go files in /Users/x/Documents/test-go-build-constraints

$ go1.23.6  run .
package mymod: build constraints exclude all Go files in /Users/x/Documents/test-go-build-constraints

Metadata

Metadata

Assignees

No one assigned

    Labels

    GoCommandcmd/goProposalWaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.

    Type

    No type

    Projects

    Status

    Incoming

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions