3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

gox でビルドするバイナリの出力先を好みに合わせて変える

Posted at

gox は Vagrant はじめ数々の HashiCorp プロダクトでおなじみの Mitchell Hashimoto さんによる、Go のクロスコンパイルを簡単に行うためのコマンドラインツールです。

gox でビルドを実行すると、デフォルトではファイル名に OS 名や CPU アーキテクチャ名が含まれるものになってしまいます。

$ gox
Number of parallel builds: 4

-->      darwin/386: github.com/yuya-takeyama/gox-test
-->    darwin/amd64: github.com/yuya-takeyama/gox-test
-->       linux/386: github.com/yuya-takeyama/gox-test
-->     linux/amd64: github.com/yuya-takeyama/gox-test
-->       linux/arm: github.com/yuya-takeyama/gox-test
-->     freebsd/386: github.com/yuya-takeyama/gox-test
-->   freebsd/amd64: github.com/yuya-takeyama/gox-test
-->     openbsd/386: github.com/yuya-takeyama/gox-test
-->   openbsd/amd64: github.com/yuya-takeyama/gox-test
-->     windows/386: github.com/yuya-takeyama/gox-test
-->   windows/amd64: github.com/yuya-takeyama/gox-test
-->     freebsd/arm: github.com/yuya-takeyama/gox-test
-->      netbsd/386: github.com/yuya-takeyama/gox-test
-->    netbsd/amd64: github.com/yuya-takeyama/gox-test
-->      netbsd/arm: github.com/yuya-takeyama/gox-test
-->       plan9/386: github.com/yuya-takeyama/gox-test
$ tree
.
├── gox-test_darwin_386
├── gox-test_darwin_amd64
├── gox-test_freebsd_386
├── gox-test_freebsd_amd64
├── gox-test_freebsd_arm
├── gox-test_linux_386
├── gox-test_linux_amd64
├── gox-test_linux_arm
├── gox-test_netbsd_386
├── gox-test_netbsd_amd64
├── gox-test_netbsd_arm
├── gox-test_openbsd_386
├── gox-test_openbsd_amd64
├── gox-test_plan9_386
├── gox-test_windows_386.exe
├── gox-test_windows_amd64.exe
└── main.go

0 directories, 17 files

gox には -output オプションがあり、ここに text/template 形式のフォーマットで出力先を指定できます。

 gox -output "pkg/{{.OS}}_{{.Arch}}/{{.Dir}}"
Number of parallel builds: 4

-->      darwin/386: github.com/yuya-takeyama/gox-test
-->    darwin/amd64: github.com/yuya-takeyama/gox-test
-->       linux/386: github.com/yuya-takeyama/gox-test
-->     linux/amd64: github.com/yuya-takeyama/gox-test
-->       linux/arm: github.com/yuya-takeyama/gox-test
-->     freebsd/386: github.com/yuya-takeyama/gox-test
-->   freebsd/amd64: github.com/yuya-takeyama/gox-test
-->     openbsd/386: github.com/yuya-takeyama/gox-test
-->   openbsd/amd64: github.com/yuya-takeyama/gox-test
-->     windows/386: github.com/yuya-takeyama/gox-test
-->   windows/amd64: github.com/yuya-takeyama/gox-test
-->     freebsd/arm: github.com/yuya-takeyama/gox-test
-->      netbsd/386: github.com/yuya-takeyama/gox-test
-->    netbsd/amd64: github.com/yuya-takeyama/gox-test
-->      netbsd/arm: github.com/yuya-takeyama/gox-test
-->       plan9/386: github.com/yuya-takeyama/gox-test
$ tree
.
├── main.go
└── pkg
    ├── darwin_386
    │   └── gox-test
    ├── darwin_amd64
    │   └── gox-test
    ├── freebsd_386
    │   └── gox-test
    ├── freebsd_amd64
    │   └── gox-test
    ├── freebsd_arm
    │   └── gox-test
    ├── linux_386
    │   └── gox-test
    ├── linux_amd64
    │   └── gox-test
    ├── linux_arm
    │   └── gox-test
    ├── netbsd_386
    │   └── gox-test
    ├── netbsd_amd64
    │   └── gox-test
    ├── netbsd_arm
    │   └── gox-test
    ├── openbsd_386
    │   └── gox-test
    ├── openbsd_amd64
    │   └── gox-test
    ├── plan9_386
    │   └── gox-test
    ├── windows_386
    │   └── gox-test.exe
    └── windows_amd64
        └── gox-test.exe

17 directories, 17 files
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?