Hi, I’m @Luo Zhu
This article was first published on luo Zhu’s official website
This article synchronizes in the public account “luo Zhu early teahouse”, reprint please contact the author.
Creation is not easy, form a habit, quality three even!
Gox is a simple, easy-to-use Go cross-build tool that behaves much like a standard Go build. Gox will compile in parallel for multiple platforms. Gox will also build a chain of cross-compilation tools for you.
The installation
To install Gox, use Go Get. We marked the version, so feel free to look at that and compile.
$ go get github.com/mitchellh/gox
...
$ gox -h
...
Copy the code
use
If you know how to use Go Build, then you know how to use Gox. For example, to build the current package, don’t specify any parameters, just call GOx. By default, Gox is parallelized based on the number of cpus you have and built for each platform by default.
$ gox
Number of parallel builds: 4
--> darwin/386: github.com/mitchellh/gox
--> darwin/amd64: github.com/mitchellh/gox
--> linux/386: github.com/mitchellh/gox
--> linux/amd64: github.com/mitchellh/gox
--> linux/arm: github.com/mitchellh/gox
--> freebsd/386: github.com/mitchellh/gox
--> freebsd/amd64: github.com/mitchellh/gox
--> openbsd/386: github.com/mitchellh/gox
--> openbsd/amd64: github.com/mitchellh/gox
--> windows/386: github.com/mitchellh/gox
--> windows/amd64: github.com/mitchellh/gox
--> freebsd/arm: github.com/mitchellh/gox
--> netbsd/386: github.com/mitchellh/gox
--> netbsd/amd64: github.com/mitchellh/gox
--> netbsd/arm: github.com/mitchellh/gox
--> plan9/386: github.com/mitchellh/gox
Copy the code
Or, if you want to create a package and subpackages.
$ gox ./... .Copy the code
Or, if you want to build multiple different packages.
$ gox github.com/mitchellh/gox github.com/hashicorp/serf
...
Copy the code
Or if you want to build only Linux packages.
$ gox -os="linux"
...
Copy the code
Or maybe you just want to build a package for 64-bit Linux.
$ gox -osarch="linux/amd64"
...
Copy the code
Want to know more! Simply run Gox-H for help and other information.
Compare this to other cross-compilation tools
Thank you very much for these other options. Each paves the way for cross-compilation in many ways, making cross-compilation approachable.
- Dave Cheney’s golang-crosscompileGox can compile for multiple platforms, so it can easily run on any platform supported by Go, whereas Dave’s scripts require a shell. Gox is also built in parallel. Dave’s script is built sequentially. Gox is built in to make it easier to use
OS/Arch
Filter function. - Goxc: a very rich tool that can even build system packages, upload binaries, generate download web pages, etc. Gox is a super thin alternative that cross-compiles only binaries. Gox builds packages in parallel, whereas GOXC does not. Gox does not enforce the output structure of a particular build binary.