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

With go1.18rc1 getting error: constraints: package constraints is not in GOROOT #13

Closed
xmlking opened this issue Feb 19, 2022 · 10 comments

Comments

@xmlking
Copy link

xmlking commented Feb 19, 2022

go get github.com/tidwall/btree@generics
go: downloading github.com/tidwall/btree v1.1.1-0.20220103194347-7411d3930522
github.com/tidwall/btree imports
constraints: package constraints is not in GOROOT (/Users//sdk/go1.18rc1/src/constraints)

@tidwall
Copy link
Owner

tidwall commented Feb 19, 2022

Try changing go get to go1.18rc1 get.

@sjansen
Copy link

sjansen commented Feb 19, 2022

I'm seeing the problem using go1.18rc1 installed two different ways.

Installer:

$ /usr/local/go/bin/go version
go version go1.18rc1 darwin/arm64
$ /usr/local/go/bin/go get github.com/tidwall/btree@generics
github.com/tidwall/btree imports
	constraints: package constraints is not in GOROOT (/usr/local/go/src/constraints)

go install golang.org/dl/go1.18rc1@latest

$ ~/go/bin/go1.18rc1 version
go version go1.18rc1 darwin/arm64
$ ~/go/bin/go1.18rc1 get github.com/tidwall/btree@generics
github.com/tidwall/btree imports
	constraints: package constraints is not in GOROOT (/Users/sjansen/sdk/go1.18rc1/src/constraints)

Based on the draft release notes, it looks like constraints is being treated as experimental and as such was moved to golang.org/x/exp/constraints

@sjansen
Copy link

sjansen commented Feb 19, 2022

Unfortunately, adding replace constraints => golang.org/x/exp v0.0.0-20220218215828-6cf2b201936e to my go.mod did not help.

Looks like it's deliberately unsupported: golang/go#35283

@tidwall
Copy link
Owner

tidwall commented Feb 20, 2022

Right now I'm using go1.18beta2.

Once installed run the following commands to produce a Go 1.18 program that uses gitHub.com/tidwall/btree with generics support.

# create a new directory
mkdir helloworld
cd helloworld

# write a Go program "main.go" 
cat > main.go << EOF
package main

import "github.com/tidwall/btree"

func main() {
	var m btree.Map[string, string]
	m.Set("hello", "world")
	println(m.Get("hello"))
}
EOF

# add the Go module dependencies
go1.18beta2 mod init helloworld
go1.18beta2 get github.com/tidwall/btree@generics
go1.18beta2 mod tidy

# run the file program
go1.18beta2 run main.go

output:

hello true

@tidwall
Copy link
Owner

tidwall commented Feb 20, 2022

The "constraints" package is built into 1.18.

@xmlking
Copy link
Author

xmlking commented Feb 20, 2022

The problem is with go1.18rc1 not with go1.18beta2.

@tidwall
Copy link
Owner

tidwall commented Feb 20, 2022

My bad, my brain was registering beta1 instead of rc1.

I pushed a fix moments ago. Thanks.

@tidwall
Copy link
Owner

tidwall commented Feb 20, 2022

golang/go#50792

@xmlking
Copy link
Author

xmlking commented Feb 20, 2022

works now.
tested at https://github.com/xmlking/go-workspace

@tidwall
Copy link
Owner

tidwall commented Mar 22, 2022

Now that Go 1.18 is officially released 🎉 I'm gonna close this issue. Thanks!

@tidwall tidwall closed this as completed Mar 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants