英文:
Download and prepare go package's dependencies to be used on another, isolated machine
问题
我有两台机器:Alice 和 Bob。Alice 不连接网络,而 Bob 连接网络。
我想在 Alice 上构建和运行一个 Go 程序,但它需要多个依赖项。有没有一种方便的方法可以从 Bob 准备所有这些依赖项,这样我只需要将一个目录从 Bob 复制到 Alice,然后在 Alice 上运行 go build?
英文:
I've got two machines: Alice and Bob. Alice is not connected to the network, Bob is.
I'd like to build and run a go program on Alice, but it requires multiple dependencies. Is there a convenient way to prepare all those dependencies from Bob so I just have to copy one directory from Bob to Alice and run go build (on Alice)?
答案1
得分: 2
所有编译的源代码都在$GOPATH中。将其复制到Alice将为您提供重建软件包所需的一切。由于您的源代码也应该在$GOPATH中,所以不需要复制其他内容。
如果您使用的是go1.6+或带有GO15VENDOREXPERIMENT=1的go1.5,您可以将所有依赖项放入项目的vendor/子目录中,以便将它们一起打包。
在go中进行交叉编译也非常简单(除非您需要cgo),只需设置GOOS和GOARCH环境变量即可。
Go构建参考文档:https://golang.org/pkg/go/build/
http://dave.cheney.net/2015/08/22/cross-compilation-with-go-1-5
英文:
All the source for compilation is in $GOPATH. Copying that to Alice will give you everything you need to rebuild the package. Since your source should be in $GOPATH as well, there shouldn't be anything else to copy.
If you're using go1.6+, or go1.5 with GO15VENDOREXPERIMENT=1, you can put all the dependencies into a vendor/ subdirectory of your project, to package them together.
Cross-compilation is also very easy in go (unless you require cgo), by setting the GOOS and GOARCH environment variables.
Go build reference: https://golang.org/pkg/go/build/
http://dave.cheney.net/2015/08/22/cross-compilation-with-go-1-5
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论