Skip to content

Commit 6c52a64

Browse files
authored
GHA macOS x86_64: Use LDC v1.35.0 as host/bootstrap compiler with Xcode-matching LLVM (#4860)
To fix weird issues without LTO and/or with mimalloc, like the dreaded `libc++abi: Pure virtual function called!` errors and unwinding segfaults for the `driver/config_diag.d` lit-test.
1 parent c26e843 commit 6c52a64

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

.github/actions/1-setup/action.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ runs:
131131
- name: Install D host compiler
132132
uses: dlang-community/setup-dlang@v1
133133
with:
134-
# macOS arm64: use LDC v1.39.0 using LLVM v17, as Xcode v16
135-
compiler: ${{ inputs.arch == 'arm64' && 'ldc-1.39.0' || 'ldc-latest' }}
134+
# macOS: use LDC with LLVM version matching Xcode - v1.39.0 (LLVM 17) on arm64 with Xcode 16, v1.35.0 (LLVM 16) on x86_64 with Xcode 15
135+
compiler: ${{ runner.os != 'macOS' && 'ldc-latest' || (inputs.arch == 'arm64' && 'ldc-1.39.0' || 'ldc-1.35.0') }}
136136
- name: 'Posix: Clear LD_LIBRARY_PATH env variable' # don't use host druntime/Phobos .so/.dylib etc.
137137
if: runner.os != 'Windows'
138138
shell: bash

.github/actions/5a-ios/action.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ runs:
2222
sysroot='/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk'
2323
fi
2424
25-
# use bootstrap-ldc, which is guaranteed to be native
26-
bootstrap-ldc/bin/ldc-build-runtime --ninja \
25+
installed/bin/ldc-build-runtime --ninja \
2726
--buildDir=build-libs-ios \
2827
--dFlags="-mtriple=$triple" \
2928
--ldcSrcDir="$PWD/ldc" \

.github/workflows/main.yml

+17-8
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,13 @@ jobs:
8282
# https://github.com/ldc-developers/ldc/issues/4462:
8383
# When using LTO, we need to explicitly export ~all symbols for plugin support via `ld64 -exported_symbol '__*'`.
8484
# Additionally `-w` to suppress resulting linker warnings.
85+
#
86+
# We also need to work around issues with the used LDC v1.35.0 host/bootstrap compiler:
87+
# * Specify a macOS triple with OS version. And exclude LTO-able host druntime/Phobos because precompiled without OS version.
88+
# * Manually specify the path to the bundled libLTO.dylib (broken for *universal* packages for LDC <= v1.40.0).
8589
extra_cmake_flags: >-
8690
-DBUILD_LTO_LIBS=ON
87-
-DD_COMPILER_FLAGS="-O -flto=full -defaultlib=phobos2-ldc-lto,druntime-ldc-lto -L-exported_symbol '-L__*' -L-w"
91+
-DD_COMPILER_FLAGS="-O -flto=full -L-exported_symbol '-L__*' -L-w -flto-binary=$PWD/../bootstrap-ldc/lib-x86_64/libLTO.dylib -mtriple=x86_64-apple-macos$MACOSX_DEPLOYMENT_TARGET"
8892
-DEXTRA_CXXFLAGS=-flto=full
8993
with_pgo: true
9094

@@ -95,7 +99,7 @@ jobs:
9599
-DBUILD_LTO_LIBS=ON
96100
extra_cmake_flags: >-
97101
-DBUILD_LTO_LIBS=ON
98-
-DD_COMPILER_FLAGS="-O -flto=full -defaultlib=phobos2-ldc-lto,druntime-ldc-lto -L-exported_symbol '-L__*' -L-w"
102+
-DD_COMPILER_FLAGS="-O -flto=full -defaultlib=phobos2-ldc-lto,druntime-ldc-lto -L-exported_symbol '-L__*' -L-w -flto-binary=$PWD/../bootstrap-ldc/lib-arm64/libLTO.dylib"
99103
-DEXTRA_CXXFLAGS=-flto=full
100104
with_pgo: true
101105

@@ -161,16 +165,21 @@ jobs:
161165
llvm_version: ${{ matrix.llvm_version || env.LLVM_VERSION }}
162166
arch: ${{ matrix.arch }}
163167
- name: Build bootstrap LDC
164-
if: matrix.os != 'macos-15'
168+
if: runner.os != 'macOS'
165169
uses: ./.github/actions/2-build-bootstrap
166170
with:
167171
cmake_flags: ${{ matrix.bootstrap_cmake_flags }}
168172
arch: ${{ matrix.arch }}
169-
# FIXME: on macOS arm64, LLVM 18 (from LDC) and LLVM 17 (from Xcode 16) seem incompatible,
170-
# leading to sporadic 'libc++abi: Pure virtual function called!' compiler crashes
171-
- name: 'macOS 15: Use host LDC (with Xcode-compatible LLVM version) as bootstrap LDC'
172-
if: matrix.os == 'macos-15'
173-
run: ln -s $(dirname $(dirname $(which ldmd2))) ../bootstrap-ldc
173+
# FIXME: on macOS, mixing newer LLVM from bootstrap LDC with older LLVM from Xcode clang is problematic,
174+
# leading to sporadic 'libc++abi: Pure virtual function called!' compiler crashes etc.
175+
- name: 'macOS: Use host LDC (with Xcode-compatible LLVM version) as bootstrap LDC'
176+
if: runner.os == 'macOS'
177+
run: |
178+
ln -s $(dirname $(dirname $(which ldmd2))) ../bootstrap-ldc
179+
# work around a v1.35.0 bug - need to rename libLTO-ldc.dylib to make it loadable
180+
if [[ '${{ matrix.arch }}' == 'x86_64' ]]; then
181+
mv ../bootstrap-ldc/lib-x86_64/libLTO-ldc.dylib ../bootstrap-ldc/lib-x86_64/libLTO.dylib
182+
fi
174183
- name: Build LDC with PGO instrumentation & gather profile from compiling default libs
175184
if: matrix.with_pgo
176185
uses: ./.github/actions/2a-build-pgo

0 commit comments

Comments
 (0)