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

Build tags does not work in main package #22669

Closed
sammy007 opened this issue Nov 11, 2017 · 4 comments
Closed

Build tags does not work in main package #22669

sammy007 opened this issue Nov 11, 2017 · 4 comments

Comments

@sammy007
Copy link

sammy007 commented Nov 11, 2017

I want to restrict whole project from compilation on go versions < 1.9 so I put this into main.go

// +build go1.9

package main

...

it does not work, meanwhile it's ok if specified in other package within project. Is it yet another "idiomatic" gem I am not aware of or there is another "canonical" way?

I am asking because in 1.8 the json deserializer just broke some projects in very weird way and caused edge cases so such crutches will be required because core library no longer can be trusted.

@artyom
Copy link
Member

artyom commented Nov 11, 2017

Seems to be working as expected:

example ¶ cat main.go 
// +build go1.10

package main

func main() {
	println("hello")
}
example ¶ go version
go version go1.9.2 darwin/amd64
example ¶ go build
can't load package: package .: build constraints exclude all Go files in /tmp/example

With Go 1.8:

example ¶ cat main.go 
// +build go1.9

package main

func main() {
	println("hello")
}
example ¶ go version
go version go1.9.2 darwin/amd64
example ¶ go build ; echo $?
0
example ¶ GOROOT=/tmp/go /tmp/go/bin/go version
go version go1.8.5 darwin/amd64
example ¶ GOROOT=/tmp/go /tmp/go/bin/go build
can't load package: package .: no buildable Go source files in /tmp/example

@sammy007
Copy link
Author

With go 1.6

// +build go1.10

package main

import (
	"fmt"
)

func main() {
	fmt.Println("Hello, playground")
}
go version
go version go1.6.2 linux/amd64
go build x.go
./x
Hello, playground

@sammy007
Copy link
Author

sammy007 commented Nov 11, 2017

Maybe works because source file given to build command, my bad. But why go get works if there is a restriction?

@sammy007
Copy link
Author

Well, likely depends on my build scripts.

@golang golang locked and limited conversation to collaborators Nov 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants