Skip to content

Commit a47fb2a

Browse files
authored
GHA macOS: Enable bootstrap stage again (#4912)
And the latest stable LDC release as first host compiler. Fixes #4899 for good.
1 parent da85ede commit a47fb2a

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ runs:
4949
sudo ln -sf $tool-19 /usr/bin/$tool
5050
$tool --version
5151
done
52+
- name: 'macOS arm64: Install Homebrew clang 19' # see mimalloc comment in ../3-build-native/action.yml
53+
if: runner.os == 'macOS' && inputs.arch == 'arm64'
54+
shell: bash
55+
run: brew install llvm@19
5256
- name: 'Windows: Install clang v19.1.3 from GitHub'
5357
if: runner.os == 'Windows'
5458
shell: bash
@@ -121,8 +125,7 @@ runs:
121125
- name: Install D host compiler
122126
uses: dlang-community/setup-dlang@v1
123127
with:
124-
# 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
125-
compiler: ${{ runner.os != 'macOS' && 'ldc-latest' || (inputs.arch == 'arm64' && 'ldc-1.39.0' || 'ldc-1.35.0') }}
128+
compiler: ldc-latest
126129
- name: 'Posix: Clear LD_LIBRARY_PATH env variable' # don't use host druntime/Phobos .so/.dylib etc.
127130
if: runner.os != 'Windows'
128131
shell: bash

.github/actions/3-build-native/action.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ inputs:
44
required: false
55
default: ''
66
arch:
7-
required: false # Windows only
7+
required: true
88
with_pgo:
99
required: false
1010
default: false
@@ -15,13 +15,23 @@ runs:
1515
- name: 'Posix: Build mimalloc'
1616
if: runner.os != 'Windows'
1717
uses: ./.github/actions/helper-mimalloc
18+
with:
19+
cmake_flags: ${{ inputs.cmake_flags }} # propagate C(++) compilers and ignored LDC-specific vars
1820

1921
- name: Build LDC & LDC D unittests & defaultlib unittest runners
2022
uses: ./.github/actions/helper-build-ldc
2123
with:
2224
build_dir: build
2325
host_dc: ../bootstrap-ldc/bin/ldmd2
2426
specify_install_dir: true
27+
# NOTE:
28+
# mimalloc on macOS is tricky - when mixing newer LLVM from bootstrap LDC with older LLVM from Xcode clang,
29+
# causing *sporadic* compiler crashes: `libc++abi: Pure virtual function called!`
30+
# What apparently makes it work with newer LLVM versions on both x86_64 and arm64 is using mixed LTO for both
31+
# C++ and D parts of ldc2 (with prebuilt non-LTO'd LLVM compiled with Xcode clang); the compiler used for
32+
# non-LTO'd mimalloc doesn't seem to play a role.
33+
# On macOS arm64, we need a matching Homebrew clang to get C++ LTO to work, otherwise hitting linker error
34+
# `LLVM ERROR: Unsupported stack probing method` with bitcode files produced by older Xcode clang.
2535
cmake_flags: >-
2636
${{ runner.os != 'Windows' && '-DALTERNATIVE_MALLOC_O="$PWD/../build-mimalloc/CMakeFiles/mimalloc-obj.dir/src/static.c.o"' || '' }}
2737
${{ inputs.cmake_flags }}

.github/workflows/main.yml

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,18 @@ jobs:
7676
# https://github.com/ldc-developers/ldc/issues/4462:
7777
# When using LTO, we need to explicitly export ~all symbols for plugin support via `ld64 -exported_symbol '__*'`.
7878
# Additionally `-w` to suppress resulting linker warnings.
79-
#
80-
# We also need to work around issues with the used LDC v1.35.0 host/bootstrap compiler:
81-
# * Specify a macOS triple with OS version. And exclude LTO-able host druntime/Phobos because precompiled without OS version.
82-
# * Manually specify the path to the bundled libLTO.dylib (broken for *universal* packages for LDC <= v1.40.0).
8379
extra_cmake_flags: >-
84-
-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"
80+
-DD_COMPILER_FLAGS="-O -flto=full -defaultlib=phobos2-ldc-lto,druntime-ldc-lto -L-exported_symbol '-L__*' -L-w"
8581
-DEXTRA_CXXFLAGS=-flto=full
8682
with_pgo: true
8783

8884
- job_name: macOS arm64
8985
os: macos-14
9086
arch: arm64
9187
extra_cmake_flags: >-
92-
-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"
88+
-DCMAKE_C_COMPILER=/opt/homebrew/opt/llvm@19/bin/clang
89+
-DCMAKE_CXX_COMPILER=/opt/homebrew/opt/llvm@19/bin/clang++
90+
-DD_COMPILER_FLAGS="-O -flto=full -defaultlib=phobos2-ldc-lto,druntime-ldc-lto -L-exported_symbol '-L__*' -L-w"
9391
-DEXTRA_CXXFLAGS=-flto=full
9492
with_pgo: true
9593

@@ -161,25 +159,14 @@ jobs:
161159
uses: ./.github/actions/helper-build-gdb
162160
with:
163161
arch: ${{ matrix.arch }}
162+
- name: 'macOS arm64: Switch to Xcode 16'
163+
if: runner.os == 'macOS' && matrix.arch == 'arm64'
164+
run: sudo xcode-select -switch /Applications/Xcode_16.1.app
164165
- name: Build bootstrap LDC
165-
if: runner.os != 'macOS'
166166
uses: ./.github/actions/2-build-bootstrap
167167
with:
168168
cmake_flags: -DBUILD_LTO_LIBS=ON ${{ matrix.base_cmake_flags }}
169169
arch: ${{ matrix.arch }}
170-
# FIXME: on macOS, mixing newer LLVM from bootstrap LDC with older LLVM from Xcode clang is problematic,
171-
# leading to sporadic 'libc++abi: Pure virtual function called!' compiler crashes etc.
172-
- name: 'macOS: Use host LDC (with Xcode-compatible LLVM version) as bootstrap LDC'
173-
if: runner.os == 'macOS'
174-
run: |
175-
ln -s $(dirname $(dirname $(which ldmd2))) ../bootstrap-ldc
176-
if [[ '${{ matrix.arch }}' == 'x86_64' ]]; then
177-
# work around a v1.35.0 bug - need to rename libLTO-ldc.dylib to make it loadable
178-
mv ../bootstrap-ldc/lib-x86_64/libLTO-ldc.dylib ../bootstrap-ldc/lib-x86_64/libLTO.dylib
179-
else
180-
# use Xcode v16 on arm64
181-
sudo xcode-select -switch /Applications/Xcode_16.1.app
182-
fi
183170
- name: Build LDC with PGO instrumentation & gather profile from compiling default libs
184171
if: matrix.with_pgo
185172
uses: ./.github/actions/2a-build-pgo

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ if(UNIX AND LDC_FULLY_STATIC)
317317
endif()
318318

319319
# Suppress superfluous randlib warnings about "*.a" having no symbols on MacOSX.
320-
if (APPLE)
320+
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang") # not supported by llvm-ranlib used with Homebrew clang
321321
set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
322322
set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
323323
set(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")

0 commit comments

Comments
 (0)