Skip to content

Commit f5c58d7

Browse files
committed
add mac gcc builds [ci skip]
This became possible after working around a list of toolchain and curl issues, within curl itself. Then figuring out why gcc became inherently incompatible with Apple SDKs, and implementing the necessary toolchain fix in this repo too. Mac gcc builds are rather a tech demo and test bed, and it doesn't seem to support cross-CPU builds, multi-arch builds. Ref: curl/curl#14097
1 parent b461404 commit f5c58d7

File tree

2 files changed

+62
-8
lines changed

2 files changed

+62
-8
lines changed

.github/workflows/build.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,34 @@ jobs:
590590
*-*-macos*.*
591591
urls.txt
592592
593+
mac-gcc:
594+
runs-on: macos-latest
595+
timeout-minutes: 30
596+
env:
597+
CW_JOBS: '4'
598+
steps:
599+
- uses: actions/checkout@v4
600+
with:
601+
fetch-depth: '300'
602+
- name: 'build'
603+
env:
604+
GITHUB_TOKEN: '${{ github.token }}'
605+
run: |
606+
export CW_CCSUFFIX='-14'
607+
export CW_CONFIG='${{ github.ref_name }}-mac-gcc-a64'
608+
export CW_REVISION='${{ github.sha }}'
609+
sh -c ./_ci-mac-homebrew.sh
610+
611+
- name: 'list dependencies'
612+
run: cat urls.txt
613+
- uses: actions/upload-artifact@v4
614+
with:
615+
name: 'curl-macos-gcc-arm64'
616+
retention-days: 5
617+
path: |
618+
*-*-macos*.*
619+
urls.txt
620+
593621
win-llvm-from-mac:
594622
runs-on: macos-latest
595623
timeout-minutes: 30

_build.sh

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,9 @@ build_single_target() {
848848
_OSVER="$(printf '%02d%02d' \
849849
"$(printf '%s' "${macminver}" | cut -d '.' -f 1)" \
850850
"$(printf '%s' "${macminver}" | cut -d '.' -f 2)")"
851-
_CMAKE_GLOBAL+=" -DCMAKE_OSX_ARCHITECTURES=${_machines}"
851+
if [ "${_CC}" != 'gcc' ]; then
852+
_CMAKE_GLOBAL+=" -DCMAKE_OSX_ARCHITECTURES=${_machines}"
853+
fi
852854
elif [ "${_OS}" = 'linux' ]; then
853855
if [ "${_HOST}" != "${_OS}" ] || \
854856
[ "${unamem}" != "${_machine}" ]; then
@@ -1190,15 +1192,39 @@ build_single_target() {
11901192

11911193
# Explicitly set the SDK root.
11921194
# We set it for all build tools for macOS to gain control over this.
1193-
_SYSROOT="$(xcrun -sdk macosx --show-sdk-path)" # E.g. /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
1195+
_SYSROOT="$(xcrun -sdk macosx --show-sdk-path 2>/dev/null)" # E.g. /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
1196+
1197+
# Installed/selected Xcode version and SDK version:
1198+
xcodebuild -version || true
1199+
xcrun -sdk macosx --show-sdk-path || true
11941200

1195-
# Standard gcc (as of v13.2.0 and v14.1.0) fails to compile some headers in macOS SDK 13.x.
1196-
# Issue: https://github.com/curl/curl/issues/10356
1197-
# Revert to SDK 12.x as a workaround, e.g. /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk
11981201
if [ "${_CC}" = 'gcc' ]; then
1199-
tmp="$(echo "${_SYSROOT}" | sed -E 's/[0-9\.]+\.sdk$/12.sdk/g')"
1200-
if [ -d "${tmp}" ]; then
1201-
_SYSROOT="${tmp}"
1202+
1203+
libgccdir="$(dirname \
1204+
"$("${_CCPREFIX}gcc${_CCSUFFIX}" -print-libgcc-file-name)")"
1205+
1206+
if [ -d "${libgccdir}/include-fixed" ]; then
1207+
# dump SDK major version used while building Homebrew gcc:
1208+
grep -a -h -r -E -o '.+[0-9.]+\.sdk/' "${libgccdir}/include-fixed" | sed -E 's/^\t+//g' | tr -d '"' | sort -u || true
1209+
1210+
# Homebrew gcc (as of v14.1.0) ships with set of SDK header overrides.
1211+
# These are compatible with the specific SDK version the Homebrew build
1212+
# machines used at build-time. We only know the major version number of
1213+
# that SDK, and there is no guarantee that ours (or the CI machine) has
1214+
# the same versions installed or selected. To make it work anyway, we
1215+
# zap known to be incompatible/problematic parts of the gcc hacks.
1216+
1217+
# Unbreak Homebrew gcc builds by moving problematic SDK header overlay
1218+
# directories/files out of the way:
1219+
find "${libgccdir}/include-fixed" | sort
1220+
patch_out='dispatch os AvailabilityInternal.h'
1221+
patch_out+=' stdio.h' # for Xcode 16 error: unknown type name 'FILE'
1222+
for f in ${patch_out}; do
1223+
if [ -r "${libgccdir}/include-fixed/${f}" ]; then
1224+
echo "! Zap gcc hack: '${libgccdir}/include-fixed/${f}'"
1225+
mv "${libgccdir}/include-fixed/${f}" "${libgccdir}/include-fixed/${f}-BAK"
1226+
fi
1227+
done
12021228
fi
12031229
fi
12041230

0 commit comments

Comments
 (0)