From 34155f594bf179d72cef17b6c9159f2e8ba7e13b Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Mon, 22 Jul 2024 11:05:38 +0200 Subject: [PATCH] build multi-arch binaries --- .woodpecker/build.yml | 4 +-- Makefile | 59 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 4 deletions(-) diff --git a/.woodpecker/build.yml b/.woodpecker/build.yml index d730bc0..262c2ff 100644 --- a/.woodpecker/build.yml +++ b/.woodpecker/build.yml @@ -19,7 +19,7 @@ steps: "Run build": image: *golang_image commands: - - CGO_ENABLED=0 go build + - make "Publish": image: plugins/gitea-release @@ -27,6 +27,6 @@ steps: api_key: from_secret: gitnet_api_key base_url: https://gitnet.fr - files: ./expiration-check + files: ./build/* when: event: [tag] diff --git a/Makefile b/Makefile index 79eee22..6309f8a 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,57 @@ -build: - go build +CGO_ENABLED = 0 +DIR = ./build +GOARCH = amd64 +GOARM = arm64 +GOOSWIN = windows +GOOSX = darwin +GOOSLINUX = linux +EXECUTABLE = expiration-check + +WINBIN = $(DIR)/$(EXECUTABLE)-win-$(GOARCH).exe +OSXBIN = $(DIR)/$(EXECUTABLE)-darwin-$(GOARCH) +LINUXBIN = $(DIR)/$(EXECUTABLE)-linux-$(GOARCH) +ARMBIN = $(DIR)/$(EXECUTABLE)-linux-$(GOARM) + +CC = go build +CFLAGS = -trimpath +LDFLAGS = all=-w -s +GCFLAGS = all= +ASMFLAGS = all= + +.PHONY: all +all: darwin linux win64 arm + +.PHONY: linux +linux: $(LINUXBIN) + chmod +x $(LINUXBIN) + +.PHONY: arm +arm: $(ARMBIN) + chmod +x $(ARMBIN) + +.PHONY: darwin +darwin: $(OSXBIN) + chmod +x $(OSXBIN) + +.PHONY: win64 +win64: $(WINBIN) + +.PHONY: $(OSXBIN) +$(OSXBIN): + GO111MODULE=$(GOMOD) GOARCH=$(GOARCH) GOOS=$(GOOSX) CGO_ENABLED=$(CGO_ENABLED) $(CC) $(CFLAGS) -o $(OSXBIN) -ldflags="$(LDFLAGS)" -gcflags="$(GCFLAGS)" -asmflags="$(ASMFLAGS)" . + +.PHONY: $(ARMBIN) +$(ARMBIN): + GO111MODULE=$(GOMOD) GOARCH=$(GOARCH) GOOS=$(GOOSLINUX) CGO_ENABLED=$(CGO_ENABLED) $(CC) $(CFLAGS) -o $(ARMBIN) -ldflags="$(LDFLAGS)" -gcflags="$(GCFLAGS)" -asmflags="$(ASMFLAGS)" . + +.PHONY: $(LINUXBIN) +$(LINUXBIN): + GO111MODULE=$(GOMOD) GOARCH=$(GOARCH) GOOS=$(GOOSLINUX) CGO_ENABLED=$(CGO_ENABLED) $(CC) $(CFLAGS) -o $(LINUXBIN) -ldflags="$(LDFLAGS)" -gcflags="$(GCFLAGS)" -asmflags="$(ASMFLAGS)" . + +.PHONY: $(WINBIN) +$(WINBIN): + GO111MODULE=$(GOMOD) GOARCH=$(GOARCH) GOOS=$(GOOSWIN) CGO_ENABLED=$(CGO_ENABLED) $(CC) $(CFLAGS) -o $(WINBIN) -ldflags="$(LDFLAGS)" -gcflags="$(GCFLAGS)" -asmflags="$(ASMFLAGS)" . + +.PHONY: clean +clean: + rm -rf $(DIR)/*