From 3acd42f8d7bbae138ca48088d2f7ca88b5e6dd80 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Wed, 9 Dec 2020 01:45:48 +0800 Subject: [PATCH] Use gox to cross-compile (#274) use gox for cross-compile use xgo base image correct flags for gox no need to test drone anymore Co-authored-by: Matti R Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/274 Reviewed-by: 6543 <6543@obermui.de> Reviewed-by: Norwin Co-Authored-By: techknowlogick Co-Committed-By: techknowlogick --- .drone.yml | 9 +-------- Makefile | 39 ++++++--------------------------------- 2 files changed, 7 insertions(+), 41 deletions(-) diff --git a/.drone.yml b/.drone.yml index 0e4b953..6329cd1 100644 --- a/.drone.yml +++ b/.drone.yml @@ -6,10 +6,6 @@ platform: os: linux arch: amd64 -workspace: - base: /go - path: src/code.gitea.io/tea - steps: - name: build pull: always @@ -31,7 +27,6 @@ steps: - pull_request - name: unit-test - pull: always image: golang:1.15 commands: - make unit-test-coverage @@ -45,7 +40,6 @@ steps: - pull_request - name: release-test - pull: always image: golang:1.15 commands: - make test @@ -70,8 +64,7 @@ steps: - tag - name: static - pull: always - image: techknowlogick/xgo:latest + image: golang:1.15 environment: GOPROXY: https://goproxy.cn commands: diff --git a/Makefile b/Makefile index 88743fe..d419210 100644 --- a/Makefile +++ b/Makefile @@ -140,45 +140,18 @@ $(EXECUTABLE): $(SOURCES) $(GO) build -mod=vendor $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@ .PHONY: release -release: release-dirs release-windows release-linux release-darwin release-copy release-compress release-check +release: release-dirs release-os release-compress release-check .PHONY: release-dirs release-dirs: mkdir -p $(DIST)/binaries $(DIST)/release -.PHONY: release-windows -release-windows: - @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ - cd /tmp && $(GO) get -u src.techknowlogick.com/xgo; \ +.PHONY: release-os +release-os: + @hash gox > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ + cd /tmp && $(GO) get -u github.com/mitchellh/gox; \ fi - GO111MODULE=off xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'windows/*' -out tea-$(VERSION) . -ifeq ($(CI),drone) - cp /build/* $(DIST)/binaries -endif - -.PHONY: release-linux -release-linux: - @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ - cd /tmp && $(GO) get -u src.techknowlogick.com/xgo; \ - fi - GO111MODULE=off xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'linux/amd64,linux/386,linux/arm-5,linux/arm-6,linux/arm64,linux/mips64le,linux/mips,linux/mipsle' -out tea-$(VERSION) . -ifeq ($(CI),drone) - cp /build/* $(DIST)/binaries -endif - -.PHONY: release-darwin -release-darwin: - @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ - cd /tmp && $(GO) get -u src.techknowlogick.com/xgo; \ - fi - GO111MODULE=off xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '$(LDFLAGS)' -targets 'darwin/*' -out tea-$(VERSION) . -ifeq ($(CI),drone) - cp /build/* $(DIST)/binaries -endif - -.PHONY: release-copy -release-copy: - cd $(DIST); for file in `find /build -type f -name "*"`; do cp $${file} ./release/; done; + CGO_ENABLED=0 gox -verbose -cgo=false -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -osarch='!darwin/386 !darwin/arm64 !darwin/arm' -os="windows linux darwin" -arch="386 amd64 arm arm64" -output="$(DIST)/binaries/release/tea-$(VERSION)-{{.OS}}-{{.Arch}}" .PHONY: release-compress release-compress: