From b2fdb8c5f844f6538c0125f1656c0fec0d73cb94 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Mon, 26 Sep 2022 18:47:59 +0300 Subject: [PATCH] [#26] Cross compile build Signed-off-by: Denis Kirillov --- .github/workflows/builds.yml | 6 +++++- Makefile | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index 9d6d693..df627e6 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -13,6 +13,10 @@ jobs: build_cli: name: Build CLI runs-on: ubuntu-20.04 + strategy: + matrix: + go_os: [ linux, darwin ] + go_arch: [ amd64, arm64 ] steps: - uses: actions/checkout@v2 @@ -34,7 +38,7 @@ jobs: run: make dep - name: Build CLI - run: make + run: BUILD_OS=${{ matrix.go_os }} BUILD_ARCH=${{ matrix.go_arch }} make - name: Check version run: if [[ $(make version) == *"dirty"* ]]; then exit 1; fi diff --git a/Makefile b/Makefile index 1a5eef0..7b15568 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,8 @@ REPO ?= "$(shell go list -m)" VERSION ?= "$(shell git describe --tags --match "v*" --dirty --always --abbrev=8 2>/dev/null || cat VERSION 2>/dev/null || echo "develop")" +BUILD_OS ?= linux +BUILD_ARCH ?= amd64 GO_VERSION ?= 1.19 LINT_VERSION ?= v1.49.0 @@ -16,9 +18,12 @@ SWAGGER_ARCH = linux_amd64 ifeq ($(UNAME), "Darwin/arm64") SWAGGER_ARCH = darwin_arm64 + BUILD_OS=darwin + BUILD_ARCH=arm64 endif ifeq ($(UNAME), "Darwin/x86_64") SWAGGER_ARCH = darwin_amd64 + BUILD_OS=darwin endif SWAGGER_URL ?= "https://github.com/go-swagger/go-swagger/releases/download/$(SWAGGER_VERSION)/swagger_$(SWAGGER_ARCH)" @@ -36,6 +41,8 @@ all: generate-server $(BINS) $(BINS): $(DIRS) dep @echo "⇒ Build $@" CGO_ENABLED=0 \ + GOOS=$(BUILD_OS) \ + GOARCH=$(BUILD_ARCH) \ go build -v -trimpath \ -ldflags "-X main.Version=$(VERSION)" \ -o $@ ./cmd/neofs-rest-gw @@ -119,6 +126,8 @@ docker/all: -w /src \ -u `stat -c "%u:%g" .` \ --env HOME=/src \ + --env BUILD_OS=$(BUILD_OS) \ + --env BUILD_ARCH=$(BUILD_ARCH) \ golang:$(GO_VERSION) make all # Generate server by swagger spec using swagger docker image