Skip to content

Commit 193a92d

Browse files
committed
build: add support for building osx binaries
1 parent 52b30e9 commit 193a92d

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

Dockerfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
# Build go app.
2+
3+
FROM crazymax/osxcross:latest-alpine AS osxcross
24
FROM golang:alpine AS gobuilder
35

46
RUN mkdir -p /src
57
WORKDIR /src
68
COPY . .
79

8-
RUN apk update && apk add make gcc linux-headers libc-dev
10+
RUN apk update && apk add make gcc linux-headers libc-dev clang lld musl-dev
11+
912
RUN make STATIC=true build-go
13+
RUN --mount=type=bind,from=osxcross,source=/osxcross,target=/osxcross \
14+
make ghost-darwin
1015

1116
FROM python:alpine AS pybuilder
1217

Makefile

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ PY_FILES=$(shell find py -name "*.py")
1515

1616
# Supported architectures for ghost binary
1717
GHOST_ARCHS=amd64 386 arm64 arm
18-
GHOST_BINS=$(addprefix $(BIN)/ghost.linux., $(GHOST_ARCHS))
18+
GHOST_LINUX_BINS=$(addprefix $(BIN)/ghost.linux., $(GHOST_ARCHS))
19+
20+
GHOST_DARWIN_ARCHS=amd64 arm64
21+
GHOST_DARWIN_BINS=$(addprefix $(BIN)/ghost.darwin., $(GHOST_DARWIN_ARCHS))
1922

2023
# Get list of apps with package.json
2124
APP_DIRS=$(shell find apps -maxdepth 1 -mindepth 1 \
@@ -69,9 +72,24 @@ $(BIN)/ghost.linux.%:
6972
$(call cmd_msg,GO,$(notdir $@))
7073
@GOOS=linux GOARCH=$* $(GO) build $(LDFLAGS) -o $@ $(CURDIR)/cmd/ghost
7174

72-
ghost-all: $(GHOST_BINS) $(GHOST_BINS:=.sha1)
75+
ghost-linux: $(GHOST_LINUX_BINS) $(GHOST_LINUX_BINS:=.sha1)
76+
77+
$(BIN)/ghost.darwin.%.sha1: $(BIN)/ghost.darwin.%
78+
$(call cmd_msg,SHA1,$(notdir $<))
79+
@cd $(BIN) && sha1sum $(notdir $<) | awk '{ print $$1 }' > $(notdir $@)
80+
81+
$(BIN)/ghost.darwin.%:
82+
$(call cmd_msg,GO,$(notdir $@))
83+
@PATH="/osxcross/bin:$$PATH" \
84+
LD_LIBRARY_PATH="/osxcross/lib:$$LD_LIBRARY_PATH" \
85+
CC=o64-clang CXX=o64-clang++ \
86+
MACOSX_DEPLOYMENT_TARGET=10.8 \
87+
CGO_ENABLED=1 \
88+
GOOS=darwin GOARCH=$* $(GO) build $(LDFLAGS) -o $@ $(CURDIR)/cmd/ghost
89+
90+
ghost-darwin: $(GHOST_DARWIN_BINS) $(GHOST_DARWIN_BINS:=.sha1)
7391

74-
build-go: overlordd ghost ghost-all
92+
build-go: overlordd ghost ghost-linux
7593

7694
build-py:
7795
@ln -sf ../py/ghost.py bin

0 commit comments

Comments
 (0)