Newbie build question: cannot find package "context"

I’m trying to get a basic build environment up and running so I can break some of fd0’s excellent work… sadly, I’m 100% new to writing anything in go and don’t know much about how the import/dependency infra is supposed to work. I tried following the build instructions here as described, but ran into the following error:

lwobker@lwobker-vms:~/go/src/github.com/restic/restic$ go build ./cmd/restic
cmd/restic/cmd_diff.go:4:2: cannot find package "context" in any of:
        /home/lwobker/go/src/github.com/restic/restic/vendor/context (vendor tree)
        /usr/lib/go-1.6/src/context (from $GOROOT)
        /home/lwobker/go/src/context (from $GOPATH)

The full output is pasted below for reference. It’s obviously some type of error in where the context package lives, and I’m pretty sure that I could make it work (or at least peel the onion one more layer) by manually moving around where the go packages live, but I also think that the point of the build/contributing.md instructions is to have something that should “just work” for everyone, so I figured I’d bring it up and see if there’s something that could/should be fixed in the tree.

I’m working from this commit in master on Jan 7 2018…

lwobker@lwobker-vms:~$ env | grep GO
GOPATH=/home/lwobker/go
lwobker@lwobker-vms:~$ mkdir -p "$GOPATH/src/github.com/restic"
lwobker@lwobker-vms:~$ cd "$GOPATH/src/github.com/restic"
lwobker@lwobker-vms:~/go/src/github.com/restic$ git clone https://github.com/restic/restic
Cloning into 'restic'...
remote: Counting objects: 33722, done.
remote: Compressing objects: 100% (83/83), done.
remote: Total 33722 (delta 67), reused 112 (delta 59), pack-reused 33577
Receiving objects: 100% (33722/33722), 37.08 MiB | 23.13 MiB/s, done.
Resolving deltas: 100% (20301/20301), done.
 Checking connectivity... done.
rest    lwobker@lwobker-vms:~/go/src/github.com/restic$ cd restic/
lwobker@lwobker-vms:~/go/src/github.com/restic/restic$ go build ./cmd/restic
cmd/restic/cmd_diff.go:4:2: cannot find package "context" in any of:
        /home/lwobker/go/src/github.com/restic/restic/vendor/context (vendor tree)
        /usr/lib/go-1.6/src/context (from $GOROOT)
        /home/lwobker/go/src/context (from $GOPATH)
lwobker@lwobker-vms:~/go/src/github.com/restic/restic$

That’s the developer reference you’ve read there, end-users should use go run build.go, which would have told you that your version of Go is way too old (older than 1.7), and restic requires at least Go 1.8. :slight_smile:

Ah, I’m sorry, did you mean to use the developer instructions? In this case, please let me know if you have any further questions! In the Go world, it’s rather well known that the context package is only available in Go 1.7 or newer… :slight_smile:

Yeah, I was looking at the developer instructions (was planning on messing around with the blob and pack file sizes referenced in the other threads)… no problem expecting me to know the Go-specific stuff… my Ubuntu 16.04/Xenial environment installed go-1.6 by default so that didn’t work and amazingly enough google and stackExchange didn’t immediately point me to the right solution. Now that I have a version of go that is not from the neolithic era I’m off and running :wink:

1 Like