Skip to content

Commit

Permalink
fix: add osxcross patch to building on M1 macbook
Browse files Browse the repository at this point in the history
- fix #104

Signed-off-by: gythialy <[email protected]>
  • Loading branch information
gythialy committed Sep 29, 2022
1 parent 4d12b28 commit 76cd6b9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
35 changes: 19 additions & 16 deletions Dockerfile.builder
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ ARG GO_VERSION=1.19.1
ARG OSX_VERSION_MIN=10.12
ARG OSX_CROSS_COMMIT=50e86ebca7d14372febd0af8cd098705049161b9

FROM golang:${GO_VERSION}-bullseye AS base
FROM golang:${GO_VERSION:-1.19.1}-bullseye AS base

ARG APT_MIRROR
RUN sed -ri "s/(httpredir|deb).debian.org/${APT_MIRROR:-deb.debian.org}/g" /etc/apt/sources.list \
&& sed -ri "s/(security).debian.org/${APT_MIRROR:-security.debian.org}/g" /etc/apt/sources.list
ENV OSX_CROSS_PATH=/osxcross

FROM ghcr.io/gythialy/golang-cross/osx-sdk:macos-12.3 AS osx-sdk
ENV OSX_CROSS_PATH=/osxcross
FROM base AS osx-cross-base
ARG DEBIAN_FRONTEND=noninteractive
# Install deps
RUN set -x; echo "Starting image build for Debian " \
Expand Down Expand Up @@ -71,20 +69,25 @@ RUN set -x; echo "Starting image build for Debian " \
# FIXME: install gcc-multilib
# FIXME: add mips and powerpc architectures

FROM osx-cross-base AS osx-cross
ARG OSX_CROSS_COMMIT
WORKDIR "${OSX_CROSS_PATH}"
# install osxcross:
RUN git clone https://github.com/tpoechtrager/osxcross.git . \
&& git checkout -q "${OSX_CROSS_COMMIT}" \
&& rm -rf ./.git
COPY --from=osx-sdk "${OSX_CROSS_PATH}/." "${OSX_CROSS_PATH}/"
ARG OSX_VERSION_MIN
RUN UNATTENDED=yes OSX_VERSION_MIN=${OSX_VERSION_MIN} ./build.sh
&& git checkout -q "${OSX_CROSS_COMMIT:-50e86ebca7d14372febd0af8cd098705049161b9}"

FROM osx-cross-base AS final
LABEL maintainer="Goren G<[email protected]>"
ARG DEBIAN_FRONTEND=noninteractive
# install osx sdk
COPY --from=ghcr.io/gythialy/golang-cross/osx-sdk:macos-12.3@sha256:6fc96c49165b28ed79e4228bcf59a001232a8a8e6c1d942a592dfe6e33352640 "${OSX_CROSS_PATH}/." "${OSX_CROSS_PATH}/"

# https://github.com/tpoechtrager/osxcross/issues/313
COPY patch/osxcross-08-52-08.patch "${OSX_CROSS_PATH}/"
RUN \
git config --global user.email "[email protected]" \
&& git config --global user.name "Goren G" \
&& git am osxcross-08-52-08.patch

RUN \
UNATTENDED=yes OSX_VERSION_MIN=${OSX_VERSION_MIN:-10.12} ./build.sh \
&& cp -rf ${OSX_CROSS_PATH}/target/bin ${OSX_CROSS_PATH}/bin \
&& ./cleanup.sh \
&& rm -rf ./.git

COPY --from=osx-cross "${OSX_CROSS_PATH}/." "${OSX_CROSS_PATH}/"
ENV PATH=${OSX_CROSS_PATH}/target/bin:$PATH
ENV PATH=${OSX_CROSS_PATH}/bin:$PATH
15 changes: 15 additions & 0 deletions patch/osxcross-08-52-08.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/wrapper/target.cpp b/wrapper/target.cpp
index 82bf65c404efed9b88da0fe3e74b5205df0b8534..acc6225ae968086c757e445742e5569ed33f4a47 100644
--- a/wrapper/target.cpp
+++ b/wrapper/target.cpp
@@ -743,6 +743,10 @@ bool Target::setup() {
fargs.push_back("-Qunused-arguments");
}

+ if ((SDKOSNum >= OSVersion(11, 1)) && (stdlib == StdLib::libcxx)) {
+ fargs.push_back("-lc++");
+ }
+
if (stdlib == StdLib::libstdcxx && usegcclibs && targetarch.size() < 2 &&
!isGCH()) {
// Use libs from './build_gcc' installation

0 comments on commit 76cd6b9

Please sign in to comment.