Skip to content

Commit 26747c5

Browse files
committed
Add support for macOS binaries
- update build process (Makefile) to generate binaries for supported macOS architectures - `darwin/amd64` - `darwin/arm64` - update README - note OS / Go release combination limitations - list Makefile recipes to target specific macOS build options refs GH-967
1 parent fc263b8 commit 26747c5

File tree

2 files changed

+144
-4
lines changed

2 files changed

+144
-4
lines changed

Makefile

+133-4
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ goclean:
208208
@mkdir -p "$(ASSETS_PATH)"
209209
@rm -vf $(wildcard $(ASSETS_PATH)/*/*-linux-*)
210210
@rm -vf $(wildcard $(ASSETS_PATH)/*/*-windows-*)
211+
@rm -vf $(wildcard $(ASSETS_PATH)/*/*-darwin-*)
211212
@rm -vf $(wildcard $(ASSETS_PATH)/packages/*/*.rpm)
212213
@rm -vf $(wildcard $(ASSETS_PATH)/packages/*/*.rpm.sha256)
213214
@rm -vf $(wildcard $(ASSETS_PATH)/packages/*/*.deb)
@@ -266,8 +267,8 @@ depsinstall:
266267

267268
.PHONY: all
268269
# https://stackoverflow.com/questions/3267145/makefile-execute-another-target
269-
## all: generates assets for Linux distros and Windows
270-
all: clean windows linux
270+
## all: generates assets for Linux distros, Windows and macOS
271+
all: clean windows linux darwin
271272
@echo "Completed all cross-platform builds ..."
272273

273274
.PHONY: quick
@@ -631,6 +632,114 @@ linux-arm64-links:
631632

632633
@echo "Completed generating download links for linux arm64 assets"
633634

635+
.PHONY: darwin-amd64-build
636+
## darwin-amd64-build: builds assets for macOS amd64 systems
637+
darwin-amd64-build:
638+
@echo "Building release assets for darwin amd64 ..."
639+
640+
@set -e; for target in $(WHAT); do \
641+
mkdir -p $(ASSETS_PATH)/$$target && \
642+
echo " building $$target amd64 binary" && \
643+
env GOOS=darwin GOARCH=amd64 $(BUILDCMD) -o $(ASSETS_PATH)/$$target/$$target-darwin-amd64 $(PROJECT_DIR)/cmd/$$target; \
644+
done
645+
646+
@echo "Completed build tasks for darwin amd64"
647+
648+
.PHONY: darwin-amd64-compress
649+
## darwin-amd64-compress: compresses generated macOS amd64 assets
650+
darwin-amd64-compress:
651+
@echo "Compressing release assets for darwin amd64 ..."
652+
653+
@set -e; for target in $(WHAT); do \
654+
echo " compressing $$target amd64 binary" && \
655+
$(COMPRESSCMD) $(ASSETS_PATH)/$$target/$$target-darwin-amd64 > \
656+
$(ASSETS_PATH)/$$target/$$target-darwin-amd64.xz && \
657+
rm -f $(ASSETS_PATH)/$$target/$$target-darwin-amd64; \
658+
done
659+
660+
@echo "Completed compress tasks for darwin amd64"
661+
662+
.PHONY: darwin-amd64-checksums
663+
## darwin-amd64-checksums: generates checksum files for macOS amd64 assets
664+
darwin-amd64-checksums:
665+
@echo "Generating checksum files for darwin amd64 assets ..."
666+
667+
@set -e; for target in $(WHAT); do \
668+
echo " generating $$target checksum file" && \
669+
cd $(ASSETS_PATH)/$$target && \
670+
$(CHECKSUMCMD) $$target-darwin-amd64.xz > $$target-darwin-amd64.xz.sha256 && \
671+
cd $$OLDPWD; \
672+
done
673+
674+
@echo "Completed generation of checksum files for darwin amd64"
675+
676+
.PHONY: darwin-amd64-links
677+
## darwin-amd64-links: generates download URLs for macOS amd64 assets
678+
darwin-amd64-links:
679+
@echo "Generating download links for darwin amd64 assets ..."
680+
681+
@set -e; for target in $(WHAT); do \
682+
echo " generating $$target download links" && \
683+
echo "$(BASE_URL)/$(RELEASE_TAG)/$$target-darwin-amd64.xz" >> $(ALL_DOWNLOAD_LINKS_FILE) && \
684+
echo "$(BASE_URL)/$(RELEASE_TAG)/$$target-darwin-amd64.xz.sha256" >> $(ALL_DOWNLOAD_LINKS_FILE); \
685+
done
686+
687+
@echo "Completed generating download links for darwin amd64 assets"
688+
689+
.PHONY: darwin-arm64-build
690+
## darwin-arm64-build: builds assets for macOS arm64 systems
691+
darwin-arm64-build:
692+
@echo "Building release assets for darwin arm64 ..."
693+
694+
@set -e; for target in $(WHAT); do \
695+
mkdir -p $(ASSETS_PATH)/$$target && \
696+
echo " building $$target arm64 binary" && \
697+
env GOOS=darwin GOARCH=arm64 $(BUILDCMD) -o $(ASSETS_PATH)/$$target/$$target-darwin-arm64 $(PROJECT_DIR)/cmd/$$target; \
698+
done
699+
700+
@echo "Completed build tasks for darwin arm64"
701+
702+
.PHONY: darwin-arm64-compress
703+
## darwin-arm64-compress: compresses generated macOS arm64 assets
704+
darwin-arm64-compress:
705+
@echo "Compressing release assets for darwin arm64 ..."
706+
707+
@set -e; for target in $(WHAT); do \
708+
echo " compressing $$target arm64 binary" && \
709+
$(COMPRESSCMD) $(ASSETS_PATH)/$$target/$$target-darwin-arm64 > \
710+
$(ASSETS_PATH)/$$target/$$target-darwin-arm64.xz && \
711+
rm -f $(ASSETS_PATH)/$$target/$$target-darwin-arm64; \
712+
done
713+
714+
@echo "Completed compress tasks for darwin arm64"
715+
716+
.PHONY: darwin-arm64-checksums
717+
## darwin-arm64-checksums: generates checksum files for macOS arm64 assets
718+
darwin-arm64-checksums:
719+
@echo "Generating checksum files for darwin arm64 assets ..."
720+
721+
@set -e; for target in $(WHAT); do \
722+
echo " generating $$target checksum file" && \
723+
cd $(ASSETS_PATH)/$$target && \
724+
$(CHECKSUMCMD) $$target-darwin-arm64.xz > $$target-darwin-arm64.xz.sha256 && \
725+
cd $$OLDPWD; \
726+
done
727+
728+
@echo "Completed generation of checksum files for darwin arm64"
729+
730+
.PHONY: darwin-arm64-links
731+
## darwin-arm64-links: generates download URLs for macOS arm64 assets
732+
darwin-arm64-links:
733+
@echo "Generating download links for darwin arm64 assets ..."
734+
735+
@set -e; for target in $(WHAT); do \
736+
echo " generating $$target download links" && \
737+
echo "$(BASE_URL)/$(RELEASE_TAG)/$$target-darwin-arm64.xz" >> $(ALL_DOWNLOAD_LINKS_FILE) && \
738+
echo "$(BASE_URL)/$(RELEASE_TAG)/$$target-darwin-arm64.xz.sha256" >> $(ALL_DOWNLOAD_LINKS_FILE); \
739+
done
740+
741+
@echo "Completed generating download links for darwin arm64 assets"
742+
634743
.PHONY: linux-x86
635744
## linux-x86: generates assets for Linux x86
636745
linux-x86: linux-x86-build linux-x86-compress linux-x86-checksums
@@ -656,6 +765,26 @@ linux: linux-x86 linux-x64 linux-arm64
656765
linux-links: linux-x86-links linux-x64-links linux-arm64-links
657766
@echo "Completed generating download links for linux x86, x64, and arm64 assets"
658767

768+
.PHONY: darwin-amd64
769+
## darwin-amd64: generates assets for macOS amd64
770+
darwin-amd64: darwin-amd64-build darwin-amd64-compress darwin-amd64-checksums
771+
@echo "Completed all tasks for darwin amd64"
772+
773+
.PHONY: darwin-arm64
774+
## darwin-arm64: generates assets for macOS arm64
775+
darwin-arm64: darwin-arm64-build darwin-arm64-compress darwin-arm64-checksums
776+
@echo "Completed all tasks for darwin arm64"
777+
778+
.PHONY: darwin
779+
## darwin: generates assets for macOS amd64 and arm64 systems
780+
darwin: darwin-amd64 darwin-arm64
781+
@echo "Completed all tasks for darwin"
782+
783+
.PHONY: darwin-links
784+
## darwin-links: generates download URLs for macOS amd64 and arm64 assets
785+
darwin-links: darwin-amd64-links darwin-arm64-links
786+
@echo "Completed generating download links for darwin amd64 and arm64 assets"
787+
659788
.PHONY: packages-stable
660789
## packages-stable: generates "stable" release series DEB and RPM packages
661790
packages-stable: linux-x64-build
@@ -813,7 +942,7 @@ package-links:
813942

814943
.PHONY: links
815944
## links: generates download URLs for release assets
816-
links: windows-x86-links windows-x64-links linux-x86-links linux-x64-links linux-arm64-links package-links
945+
links: windows-x86-links windows-x64-links linux-x86-links linux-x64-links linux-arm64-links darwin-amd64-links darwin-arm64-links package-links
817946
@echo "Completed generating download links for all release assets"
818947

819948
.PHONY: dev-build
@@ -823,7 +952,7 @@ dev-build: clean linux-x64-dev-build packages-dev package-links linux-x64-dev-co
823952

824953
.PHONY: release-build
825954
## release-build: generates stable build assets for public release
826-
release-build: clean windows linux-x86 linux-arm64 packages-dev clean-linux-x64-dev packages-stable linux-x64-compress linux-x64-checksums links
955+
release-build: clean windows linux-x86 linux-arm64 packages-dev clean-linux-x64-dev packages-stable linux-x64-compress linux-x64-checksums darwin links
827956
@echo "Completed all tasks for stable release build"
828957

829958
.PHONY: helper-builder-setup

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,13 @@ been tested.
409409
- Windows 10
410410
- Ubuntu Linux 18.04+
411411
- Red Hat Enterprise Linux 7+
412+
- macOS 11 Big Sur
413+
- NOTE: You may need to build from source using an older Go release if your
414+
version of macOS is not supported by the current "oldstable" version of Go
415+
- "stable" release builds for this project are usually generated from the
416+
most recent "oldstable" Go release version while "dev" or "unstable"
417+
release builds are generated from the most recent "stable" or release
418+
candidate Go release
412419

413420
## Installation
414421

@@ -488,6 +495,10 @@ settings intended to optimize for size and to prevent dynamic linkage.
488495
- `make linux-x64-build`
489496
- for use on Linux arm64
490497
- `make linux-arm64-build`
498+
- for use on macOS amd64
499+
- `make darwin-amd64-build`
500+
- for use on macOS arm64
501+
- `make darwin-arm64-build`
491502
1. Copy the newly compiled binary from the applicable `/tmp` subdirectory path
492503
(based on the clone instructions in this section) below and deploy where
493504
needed.

0 commit comments

Comments
 (0)