Skip to content

Commit

Permalink
Update build to cross compile
Browse files Browse the repository at this point in the history
Currently targeting linux/amd64 and darwin/amd64
  • Loading branch information
tsandall committed May 25, 2016
1 parent 74eaf06 commit ac3f177
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

# build artifacts
coverage
opa
ast/parser.go
opa
opa_linux_amd64
opa_darwin_amd64

# runtime artifacts
policies
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
language: go
env:
- CROSSCOMPILE="linux/amd64 darwin/amd64"
go:
- 1.5
- 1.6
Expand Down
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 <platform>/<arch> pairs
# and "gox" will be used to build the binaries instead of "go".
CROSSCOMPILE ?=

GO15VENDOREXPERIMENT := 1
export GO15VENDOREXPERIMENT
Expand All @@ -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)
Expand Down Expand Up @@ -68,3 +78,5 @@ fmt:

clean:
rm -f ./opa
rm -f ./opa_linux_amd64
rm -f ./opa_darwin_amd64
2 changes: 1 addition & 1 deletion docs/dev/RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ac3f177

Please sign in to comment.