go語言的交叉編譯

GGox 是一個簡單的,不花俏的Go平臺交叉編譯工具,它的用處就和標準的 go build 同樣。Gox 會並行地爲多種平臺編譯。Gox 同時也提供了一套交叉編譯工具鏈。 linux

GGox 項目地址:https://github.com/mitchellh/gox git

安裝

爲了安裝 Gox,請使用 go get。咱們已經爲版本打上了標籤,因此能夠隨便切換標籤進行編譯: github

$ go get github.com/mitchellh/gox
...
$ gox -h
... windows


用法

在你使用 Gox 以前,你必須先有一套交叉編譯工具鏈。Gox 能夠自動幫你完成這個。你須要作的只是運行(每次更新 Go 都要這樣作這步): 工具

$ gox -build-toolchain
... ui

當你完成這個,你能夠已經準備好進行交叉編譯了。
若是你知道怎麼去使用 go build, 那麼你也知道怎麼去使用 Gox 了。例如,編譯當前的項目,無需提供參數,只須要調用gox。Gox 就會根據 CPU 的數量並行地爲各個平臺編譯: spa


$ gox
Number of parallel builds: 4 get

--> 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 it

或者,你只想編譯某個項目和子項目: 編譯

$ gox ./...
...

或者,你想僅僅爲 linux 編譯:

$ gox -os="linux"
...

或者,你僅僅只想爲 64 位的 linux 編譯:

$ gox -osarch="linux/amd64"
...

還有更多的選項,能夠經過 gox -h 查看幫助。

相關文章
相關標籤/搜索