From ac3f177ac0c57ec5cd1181b5fcf5614118777ccc Mon Sep 17 00:00:00 2001 From: Torin Sandall Date: Thu, 19 May 2016 09:37:05 -0700 Subject: [PATCH] Update build to cross compile Currently targeting linux/amd64 and darwin/amd64 --- .gitignore | 4 +++- .travis.yml | 2 ++ Makefile | 14 +++++++++++++- docs/dev/RELEASE.md | 2 +- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 9e3f5b8090..751f99ff96 100644 --- a/.gitignore +++ b/.gitignore @@ -4,8 +4,10 @@ # build artifacts coverage -opa ast/parser.go +opa +opa_linux_amd64 +opa_darwin_amd64 # runtime artifacts policies diff --git a/.travis.yml b/.travis.yml index 33470dca98..f42a251abf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,6 @@ language: go +env: + - CROSSCOMPILE="linux/amd64 darwin/amd64" go: - 1.5 - 1.6 diff --git a/Makefile b/Makefile index f6c13bd1ae..1400714d1e 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,9 @@ PACKAGES := \ github.com/open-policy-agent/opa/storage/.../ \ github.com/open-policy-agent/opa/util/.../ +GO := go +GOX := gox + BUILD_COMMIT := $(shell ./build/get-build-commit.sh) BUILD_TIMESTAMP := $(shell ./build/get-build-timestamp.sh) BUILD_HOSTNAME := $(shell ./build/get-build-hostname.sh) @@ -18,7 +21,9 @@ LDFLAGS := -ldflags "-X github.com/open-policy-agent/opa/version.Vcs=$(BUILD_COM -X github.com/open-policy-agent/opa/version.Timestamp=$(BUILD_TIMESTAMP) \ -X github.com/open-policy-agent/opa/version.Hostname=$(BUILD_HOSTNAME)" -GO := go +# Set CROSSCOMPILE to space separated list of / pairs +# and "gox" will be used to build the binaries instead of "go". +CROSSCOMPILE ?= GO15VENDOREXPERIMENT := 1 export GO15VENDOREXPERIMENT @@ -31,12 +36,17 @@ deps: $(GO) install ./vendor/github.com/PuerkitoBio/pigeon $(GO) install ./vendor/golang.org/x/tools/cmd/goimports $(GO) install ./vendor/github.com/golang/lint/golint + $(GO) get github.com/mitchellh/gox generate: $(GO) generate build: generate +ifeq ($(CROSSCOMPILE),) $(GO) build -o opa $(LDFLAGS) +else + $(GOX) -osarch="$(CROSSCOMPILE)" $(LDFLAGS) +endif install: generate $(GO) install $(LDFLAGS) @@ -68,3 +78,5 @@ fmt: clean: rm -f ./opa + rm -f ./opa_linux_amd64 + rm -f ./opa_darwin_amd64 diff --git a/docs/dev/RELEASE.md b/docs/dev/RELEASE.md index e1b641e036..30be11025e 100644 --- a/docs/dev/RELEASE.md +++ b/docs/dev/RELEASE.md @@ -68,7 +68,7 @@ CHANGELOG.md snippet and uploading the packages from the build phase. 1. Run command to build packages. This will produce a bunch of binaries (e.g., amd64/linux, i386/linux, amd64/darwin, etc.) that can be published (“distributions”). ``` - make dist + make build CROSSCOMPILE="linux/amd64 darwin/amd64" ``` ## Publishing