Skip to content
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 fine-grained go build constraints for go version #71951

Open
pjebs opened this issue Feb 25, 2025 · 6 comments
Open

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

pjebs opened this issue Feb 25, 2025 · 6 comments
Labels
GoCommand cmd/go LanguageProposal Issues describing a requested change to the Go language specification. Proposal
Milestone

Comments

@pjebs
Copy link
Contributor

pjebs commented Feb 25, 2025

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
@pjebs pjebs added the Proposal label Feb 25, 2025
@gopherbot gopherbot added this to the Proposal milestone Feb 25, 2025
@gabyhelp gabyhelp added the LanguageProposal Issues describing a requested change to the Go language specification. label Feb 25, 2025
@seankhliao
Copy link
Member

I believe this is one of the reasons we removed support for binary only packages, I don't see it making it's way back.

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Feb 25, 2025
@pjebs
Copy link
Contributor Author

pjebs commented Feb 25, 2025

My example was specific to my use-case. The proposal is more general in terms of use-cases. Perhaps a Go patch version has a bug that you want your build to avoid. And that's not to mention the inconsistency with go.mod allowing it.

@ianlancetaylor What do you think?

@ianlancetaylor
Copy link
Member

I think this is separate from binary-only packages.

@ianlancetaylor ianlancetaylor moved this to Incoming in Proposals Feb 25, 2025
@ianlancetaylor ianlancetaylor changed the title proposal: Allow fine-grained go build constraints for go version proposal: cmd/go: allow fine-grained go build constraints for go version Feb 25, 2025
@ianlancetaylor ianlancetaylor added the GoCommand cmd/go label Feb 25, 2025
@ianlancetaylor
Copy link
Member

CC @matloob @samthanawalla

@matloob
Copy link
Contributor

matloob commented Feb 26, 2025

I think we'd want to have strong use cases to consider adding a feature like this, given the increased complexity.

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.

Could you explain your use case more? I don't fully understand it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go LanguageProposal Issues describing a requested change to the Go language specification. Proposal
Projects
Status: Incoming
Development

No branches or pull requests

6 participants