概要
以下、自分用のメモです。忘れないうちにメモメモ。。。
多分、使うことは無いと思いますが、Tipsとして知っていても良いかも。
Goは、クロスコンパイルが得意な言語です。
特定のGOOSとGOARCH向けにコンパイルする際、当然それ向けの標準ライブラリなどがコンパイルされることになりますが
それをプレビルドしておくことも出来ます。
試してみる
今のOSは以下です。
$ go env | grep -E '(GOOS|GOARCH)' GOARCH="amd64" GOOS="linux"
標準ライブラリのビルド物は GOROOT/pkg にあります。
$ ls -l $(go env GOROOT)/pkg total 8 drwxr-xr-x 2 gitpod gitpod 81 Aug 1 22:47 include drwxr-xr-x 31 gitpod gitpod 4096 Aug 1 22:49 linux_amd64 drwxr-xr-x 31 gitpod gitpod 4096 Aug 1 22:49 linux_amd64_race drwxr-xr-x 3 gitpod gitpod 25 Aug 1 22:46 tool
今、対象となるGOOSとGOARCHのみがあります。
んで、ここで以下のようにすると
$ GOOS=windows GOARCH=amd64 go install std
$ ls -l $(go env GOROOT)/pkg total 12 drwxr-xr-x 2 gitpod gitpod 81 Aug 1 22:47 include drwxr-xr-x 31 gitpod gitpod 4096 Aug 1 22:49 linux_amd64 drwxr-xr-x 31 gitpod gitpod 4096 Aug 1 22:49 linux_amd64_race drwxr-xr-x 3 gitpod gitpod 25 Aug 1 22:46 tool drwxr-xr-x 31 gitpod gitpod 4096 Aug 31 07:38 windows_amd64 $ ls $(go env GOROOT)/pkg/windows_amd64 archive compress crypto debug encoding.a flag.a hash html.a index io.a math mime.a os path.a reflect.a runtime strconv.a sync.a testing.a time.a vendor bufio.a container crypto.a embed.a errors.a fmt.a hash.a image internal log math.a net os.a plugin.a regexp runtime.a strings.a syscall.a text unicode bytes.a context.a database encoding expvar.a go html image.a io log.a mime net.a path reflect regexp.a sort.a sync testing time unicode.a
windows_amd64 が出来上がりました。
参考情報
過去の記事については、以下のページからご参照下さい。
サンプルコードは、以下の場所で公開しています。