Cobra: Cross-compilation fails without explicitly installing mousetrap

Created on 11 Mar 2016  路  5Comments  路  Source: spf13/cobra

I have a CLI built using cobra: dropbox/dbxcli. If I try to cross-compile it (using gox, but other methods fail similarly), I get failures like:

21.32s$ gox -osarch="darwin/amd64 linux/amd64 windows/amd64" -output "dist/{{.Dir}}_{{.OS}}_{{.Arch}}"
Number of parallel builds: 1
-->     linux/amd64: github.com/dropbox/dbxcli
-->   windows/amd64: github.com/dropbox/dbxcli
-->    darwin/amd64: github.com/dropbox/dbxcli
1 errors occurred:
--> windows/amd64 error: exit status 1
Stderr: ../../spf13/cobra/command_win.go:9:2: cannot find package "github.com/inconshreveable/mousetrap" in any of:
    /home/travis/.gimme/versions/go1.6.linux.amd64/src/github.com/inconshreveable/mousetrap (from $GOROOT)
    /home/travis/gopath/src/github.com/inconshreveable/mousetrap (from $GOPATH)

You can see more details here: https://travis-ci.org/dropbox/dbxcli/builds/115377102

Explicitly installing mousetrap does fix the issue, but filing this because it violates principle of least surprise.

Most helpful comment

What you wanted to do was GOOS=windows go get -u github.com/spf13/cobra That will get the windows dependencies, rather than the local OS dependencies.

All 5 comments

FWIW, I can not reproduce this.

@diwakergupta mousetrap is a required dependency for Windows builds. Cross compilation, or even just compiling on Windows will fail if this library isn't present.

In your build osx and linux built fine. If your command was
gox -osarch="darwin/amd64 linux/amd64" -output "dist/{{.Dir}}_{{.OS}}_{{.Arch}}"
It would also run correctly.

Perhaps I'm missing something, but I everything I see here is working as expected.
Closing, but feel free to re-open with additional information.

@spf13 I'm confused by your response. You're saying that mousetrap is a required depenency for windows builds. Okay I get that.

Then you say linux and osx build fine if you just build those. Yes, I agree with that, what does that have to do with the windows compile issue?

Are you saying that I personally need to include mouse trap as a dependency of my project if I want to both use cobra as a depency and compile against windows? If so, how do I do that? When and where in my project do i reference that dependency? Wouldn't it throw an error since it's not explicitly used?

The only solution i see is to clone mousetrap to $GOPATH prior to building against windows. Why would we manually install dependencies? If cobra requires this library, why doesn't it install when I run go get -d -v ./...? Is it because go get assumes it needs to get linux depenencies only because i'm issuing go get from a linux machine? Is there a way for go get to install all dependencies for all architectures?

What you wanted to do was GOOS=windows go get -u github.com/spf13/cobra That will get the windows dependencies, rather than the local OS dependencies.

I have the same problem. What is the exact solution with gox?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lukasmalkmus picture lukasmalkmus  路  4Comments

zevdg picture zevdg  路  5Comments

niski84 picture niski84  路  4Comments

supershal picture supershal  路  4Comments

anuraaga picture anuraaga  路  5Comments