|
| 1 | +# Github action to test for C++ interoperability |
| 2 | +# |
| 3 | +# This file is modeled after DMD's Github action definition (`runnable_cxx.yml`). |
| 4 | +# Its goal is to test interaction with the C++ standard library on multiple platforms. |
| 5 | +# Look up the DMD file for more information about reasoning, patterns, caveats, etc... |
| 6 | +# |
| 7 | +# TODO: |
| 8 | +# - Implement Windows + MSVC 2017 support (investigate 2015) |
| 9 | +# - Implement Windows + clang support |
| 10 | +# - Implement Linux + Clang 32 bits support (if possible) |
| 11 | +name: stdcpp |
| 12 | + |
| 13 | +on: |
| 14 | + pull_request: |
| 15 | + branches: |
| 16 | + - master |
| 17 | + - stable |
| 18 | + push: |
| 19 | + branches: |
| 20 | + - master |
| 21 | + - stable |
| 22 | + # Use this branch name in your fork to test changes |
| 23 | + - github-actions |
| 24 | + |
| 25 | +jobs: |
| 26 | + main: |
| 27 | + name: Run |
| 28 | + strategy: |
| 29 | + fail-fast: false |
| 30 | + # Matches the matrix in DMD to support the same platforms |
| 31 | + matrix: |
| 32 | + os: [ macOS-10.15, ubuntu-16.04, windows-2019 ] |
| 33 | + target: [ |
| 34 | + clang-9.0.0, clang-8.0.0, clang-7.0.0, |
| 35 | + clang-6.0.0, clang-5.0.2, clang-4.0.0, clang-3.9.0, |
| 36 | + g++-9, g++-8, g++-7, g++-6, g++-5, |
| 37 | + msvc-2019, msvc-2017, msvc-2015 |
| 38 | + ] |
| 39 | + |
| 40 | + exclude: |
| 41 | + # Ubuntu supports clang and g++ |
| 42 | + - { os: ubuntu-16.04, target: msvc-2019 } |
| 43 | + - { os: ubuntu-16.04, target: msvc-2017 } |
| 44 | + - { os: ubuntu-16.04, target: msvc-2015 } |
| 45 | + # OSX only supports clang |
| 46 | + - { os: macOS-10.15, target: g++-9 } |
| 47 | + - { os: macOS-10.15, target: g++-8 } |
| 48 | + - { os: macOS-10.15, target: g++-7 } |
| 49 | + - { os: macOS-10.15, target: g++-6 } |
| 50 | + - { os: macOS-10.15, target: g++-5 } |
| 51 | + - { os: macOS-10.15, target: msvc-2019 } |
| 52 | + - { os: macOS-10.15, target: msvc-2017 } |
| 53 | + - { os: macOS-10.15, target: msvc-2015 } |
| 54 | + # We don't test g++ on Windows as DMD only mangles for MSVC |
| 55 | + - { os: windows-2019, target: g++-9 } |
| 56 | + - { os: windows-2019, target: g++-8 } |
| 57 | + - { os: windows-2019, target: g++-7 } |
| 58 | + - { os: windows-2019, target: g++-6 } |
| 59 | + - { os: windows-2019, target: g++-5 } |
| 60 | + |
| 61 | + # TODO: Implement support for clang and MSVC2017 on Windows |
| 62 | + # Currently those are still being run by the auto-tester |
| 63 | + # We can hardly test below 2017 in the CI because there's |
| 64 | + # no way to install it via command line |
| 65 | + # (TODO: Test with 2015 as the blog post is slightly ambiguous) |
| 66 | + # https://devblogs.microsoft.com/cppblog/introducing-the-visual-studio-build-tools/ |
| 67 | + - { os: windows-2019, target: msvc-2017 } |
| 68 | + - { os: windows-2019, target: msvc-2015 } |
| 69 | + - { os: windows-2019, target: clang-9.0.0 } |
| 70 | + - { os: windows-2019, target: clang-8.0.0 } |
| 71 | + - { os: windows-2019, target: clang-7.0.0 } |
| 72 | + - { os: windows-2019, target: clang-6.0.0 } |
| 73 | + - { os: windows-2019, target: clang-5.0.2 } |
| 74 | + - { os: windows-2019, target: clang-4.0.0 } |
| 75 | + - { os: windows-2019, target: clang-3.9.0 } |
| 76 | + |
| 77 | + include: |
| 78 | + # Clang boilerplate |
| 79 | + - { target: clang-9.0.0, compiler: clang, cxx-version: 9.0.0 } |
| 80 | + - { target: clang-8.0.0, compiler: clang, cxx-version: 8.0.0 } |
| 81 | + - { target: clang-7.0.0, compiler: clang, cxx-version: 7.0.0 } |
| 82 | + - { target: clang-6.0.0, compiler: clang, cxx-version: 6.0.0 } |
| 83 | + - { target: clang-5.0.2, compiler: clang, cxx-version: 5.0.2 } |
| 84 | + - { target: clang-4.0.0, compiler: clang, cxx-version: 4.0.0 } |
| 85 | + - { target: clang-3.9.0, compiler: clang, cxx-version: 3.9.0 } |
| 86 | + # g++ boilerplace |
| 87 | + - { target: g++-9, compiler: g++, cxx-version: 9.3.0 } |
| 88 | + - { target: g++-8, compiler: g++, cxx-version: 8.4.0 } |
| 89 | + - { target: g++-7, compiler: g++, cxx-version: 7.5.0 } |
| 90 | + - { target: g++-6, compiler: g++, cxx-version: 6.5.0 } |
| 91 | + - { target: g++-5, compiler: g++, cxx-version: 5.5.0 } |
| 92 | + # Platform boilerplate |
| 93 | + - { os: ubuntu-16.04, arch: x86_64-linux-gnu-ubuntu-16.04 } |
| 94 | + - { os: macOS-10.15, arch: x86_64-apple-darwin } |
| 95 | + # Clang 9.0.0 have a different arch for OSX |
| 96 | + - { os: macOS-10.15, target: clang-9.0.0, arch: x86_64-darwin-apple } |
| 97 | + |
| 98 | + runs-on: ${{ matrix.os }} |
| 99 | + steps: |
| 100 | + |
| 101 | + ######################################## |
| 102 | + # Setting up the host D compiler # |
| 103 | + ######################################## |
| 104 | + - name: Prepare compiler |
| 105 | + uses: mihails-strasuns/setup-dlang@v0.5.0 |
| 106 | + with: |
| 107 | + compiler: dmd-2.091.0 |
| 108 | + gh_token: ${{ secrets.GITHUB_TOKEN }} |
| 109 | + |
| 110 | + ######################################### |
| 111 | + # Checking out up DMD, druntime, Phobos # |
| 112 | + ######################################### |
| 113 | + - name: Checkout DMD |
| 114 | + uses: actions/checkout@v2 |
| 115 | + with: |
| 116 | + path: dmd |
| 117 | + repository: dlang/dmd |
| 118 | + ref: ${{ github.base_ref }} |
| 119 | + persist-credentials: false |
| 120 | + - name: Checkout druntime |
| 121 | + uses: actions/checkout@v2 |
| 122 | + with: |
| 123 | + path: druntime |
| 124 | + persist-credentials: false |
| 125 | + - name: Checkout Phobos |
| 126 | + uses: actions/checkout@v2 |
| 127 | + with: |
| 128 | + path: phobos |
| 129 | + repository: dlang/phobos |
| 130 | + ref: ${{ github.base_ref }} |
| 131 | + persist-credentials: false |
| 132 | + |
| 133 | + |
| 134 | + ######################################## |
| 135 | + # Setting up the host C++ compiler # |
| 136 | + ######################################## |
| 137 | + - name: '[Posix] Setting up clang ${{ matrix.cxx-version }}' |
| 138 | + if: matrix.compiler == 'clang' && runner.os != 'Windows' |
| 139 | + run: | |
| 140 | + wget --quiet --directory-prefix=${{ github.workspace }} https://releases.llvm.org/${{ matrix.cxx-version }}/clang+llvm-${{ matrix.cxx-version }}-${{ matrix.arch }}.tar.xz |
| 141 | + tar -x -C ${{ github.workspace }} -f ${{ github.workspace }}/clang+llvm-${{ matrix.cxx-version }}-${{ matrix.arch }}.tar.xz |
| 142 | + TMP_CC='${{ github.workspace }}/clang+llvm-${{ matrix.cxx-version }}-${{ matrix.arch }}/bin/clang' |
| 143 | + # On OSX, the system header are installed via `xcode-select` and not distributed with clang |
| 144 | + # Since some part of the testsuite rely on CC being only a binary (not a command), |
| 145 | + # and config files where only introduced from 6.0.0, use a wrapper script. |
| 146 | + if [ "${{ matrix.os }}" == "macOS-10.15" ]; then |
| 147 | + # Note: heredoc shouldn't be indented |
| 148 | + cat <<EOF > ${TMP_CC}-wrapper |
| 149 | + #!/bin/bash |
| 150 | + ${TMP_CC} -isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/ \$@ |
| 151 | + EOF |
| 152 | + # Invoking clang with `clang++` will link the C++ standard library |
| 153 | + # Make sure we got two separate wrapper for this |
| 154 | + cat <<EOF > ${TMP_CC}++-wrapper |
| 155 | + #!/bin/bash |
| 156 | + ${TMP_CC}++ -isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/ \$@ |
| 157 | + EOF |
| 158 | + chmod +x ${TMP_CC}-wrapper ${TMP_CC}++-wrapper |
| 159 | + echo ::set-env name=CC::${TMP_CC}-wrapper |
| 160 | + echo ::set-env name=CXX::${TMP_CC}++-wrapper |
| 161 | + else |
| 162 | + # Note: druntime's tests use `CXX` and DMD uses `CC` |
| 163 | + echo ::set-env name=CC::${TMP_CC} |
| 164 | + echo ::set-env name=CXX::${TMP_CC}++ |
| 165 | + fi |
| 166 | +
|
| 167 | + # On OSX and Linux, clang is installed by default and in the path, |
| 168 | + # so make sure ${CC} works |
| 169 | + - name: '[Posix] Verifying installed clang version' |
| 170 | + if: matrix.compiler == 'clang' && runner.os != 'Windows' |
| 171 | + run: | |
| 172 | + set -e |
| 173 | + if ${CXX} --version | grep -q 'version ${{ matrix.cxx-version }}'; then |
| 174 | + ${CXX} --version |
| 175 | + ${CXX} -print-search-dirs -print-libgcc-file-name |
| 176 | + else |
| 177 | + echo "Expected version ${{ matrix.cxx-version }}, from '${CC}', got:" |
| 178 | + ${CXX} --version |
| 179 | + exit 1 |
| 180 | + fi |
| 181 | +
|
| 182 | + # G++ is only supported on Linux |
| 183 | + - name: '[Linux] Setting up g++ ${{ matrix.cxx-version }}' |
| 184 | + if: matrix.compiler == 'g++' |
| 185 | + run: | |
| 186 | + # Workaround bug in Github actions |
| 187 | + curl https://cli-assets.heroku.com/apt/release.key | sudo apt-key add - |
| 188 | + # Make sure we have the essentials |
| 189 | + sudo apt-get update |
| 190 | + sudo apt-get install build-essential software-properties-common -y |
| 191 | + # This ppa provides multiple versions of g++ |
| 192 | + sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y |
| 193 | + sudo apt-get update |
| 194 | + sudo apt-get install ${{ matrix.target }} ${{ matrix.target }}-multilib |
| 195 | + echo ::set-env name=CC::${{ matrix.target }} |
| 196 | + echo ::set-env name=CXX::${{ matrix.target }} |
| 197 | +
|
| 198 | + # Make sure ${CC} works and we don't use the $PATH one |
| 199 | + - name: '[Linux] Verifying installed g++ version' |
| 200 | + if: matrix.compiler == 'g++' |
| 201 | + run: | |
| 202 | + set -e |
| 203 | + if ${CXX} --version | grep -q '${{ matrix.target }} (Ubuntu '; then |
| 204 | + ${CXX} --version |
| 205 | + else |
| 206 | + echo "Expected version ${{ matrix.target }}, from '${CXX}', got:" |
| 207 | + ${CXX} --version |
| 208 | + exit 1 |
| 209 | + fi |
| 210 | +
|
| 211 | + # Restore or install dmc (and DM make) |
| 212 | + - name: '[Windows] Restore dmc from cache' |
| 213 | + id: cache-dmc |
| 214 | + if: runner.os == 'Windows' |
| 215 | + uses: actions/cache@v1 |
| 216 | + with: |
| 217 | + path: ${{ github.workspace }}/tools/ |
| 218 | + key: ${{ matrix.os }}-dmc857 |
| 219 | + |
| 220 | + - name: '[Windows] Install dmc' |
| 221 | + if: runner.os == 'Windows' && steps.cache-dmc.outputs.cache-hit != 'true' |
| 222 | + shell: powershell |
| 223 | + run: | |
| 224 | + $url = "http://ftp.digitalmars.com/Digital_Mars_C++/Patch/dm857c.zip" |
| 225 | + $sha256hash = "3034016E02057618F1C6E33B9B3EACAE5F5BE25B203025BCC08F1C5D9340AE38" |
| 226 | + Write-Host ('Downloading {0} ...' -f $url) |
| 227 | + [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 |
| 228 | + $ProgressPreference = 'SilentlyContinue' |
| 229 | + New-Item -ItemType directory -Path ${{ github.workspace }}\tools\ |
| 230 | + Invoke-WebRequest -Uri $url -OutFile '${{ github.workspace }}\tools\dmc.zip' |
| 231 | + if ((Get-FileHash '${{ github.workspace }}\tools\dmc.zip' -Algorithm "SHA256").Hash -ne $sha256hash) { |
| 232 | + exit 1 |
| 233 | + } |
| 234 | + Expand-Archive '${{ github.workspace }}\tools\dmc.zip' -DestinationPath ${{ github.workspace }}\tools\ |
| 235 | +
|
| 236 | + - name: '[Windows] Set environment variables' |
| 237 | + if: runner.os == 'Windows' |
| 238 | + run: | |
| 239 | + echo ::add-path::${{ github.workspace }}\tools\dm\bin\ |
| 240 | +
|
| 241 | + ######################################## |
| 242 | + # Building DMD, druntime, Phobos # |
| 243 | + ######################################## |
| 244 | + - name: '[Posix] Build compiler & standard library' |
| 245 | + if: runner.os != 'Windows' |
| 246 | + run: | |
| 247 | + # All hosts are 64 bits but let's be explicit |
| 248 | + ./dmd/src/build.d -j2 MODEL=64 |
| 249 | + make -C druntime -f posix.mak -j2 MODEL=64 |
| 250 | + make -C phobos -f posix.mak -j2 MODEL=64 |
| 251 | + # Both version can live side by side (they end up in a different directory) |
| 252 | + # However, since clang does not provide a multilib package, only test 32 bits with g++ |
| 253 | + if [ ${{ matrix.compiler }} == "g++" ]; then |
| 254 | + ./dmd/src/build.d -j2 MODEL=32 |
| 255 | + make -C druntime -f posix.mak -j2 MODEL=32 |
| 256 | + make -C phobos -f posix.mak -j2 MODEL=32 |
| 257 | + fi |
| 258 | +
|
| 259 | + - name: '[Windows] Build compiler & standard library' |
| 260 | + if: runner.os == 'Windows' |
| 261 | + shell: cmd |
| 262 | + env: |
| 263 | + HOST_DC: ${{ env.DC }} |
| 264 | + run: | |
| 265 | + call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat" |
| 266 | + dmd -run ./dmd/src/build.d -j2 MODEL=64 |
| 267 | + if %errorlevel% neq 0 exit /b %errorlevel% |
| 268 | + # Note: Only CC for druntime and AR for Phobos are required ATM, |
| 269 | + # but providing all three to avoid surprise for future contributors |
| 270 | + # Those should really be in the path, though. |
| 271 | + cd druntime |
| 272 | + make -f win64.mak CC=cl LD=link AR=lib |
| 273 | + if %errorlevel% neq 0 exit /b %errorlevel% |
| 274 | + cd ..\phobos\ |
| 275 | + make -f win64.mak CC=cl LD=link AR=lib |
| 276 | + if %errorlevel% neq 0 exit /b %errorlevel% |
| 277 | + cd ..\ |
| 278 | +
|
| 279 | + ######################################## |
| 280 | + # Running the test suite # |
| 281 | + ######################################## |
| 282 | + - name: '[Posix] Run C++ test suite' |
| 283 | + if: runner.os != 'Windows' |
| 284 | + run: | |
| 285 | + make -C druntime -f posix.mak test/stdcpp/.run MODEL=64 |
| 286 | + if [ ${{ matrix.compiler }} == "g++" ]; then |
| 287 | + make -C druntime -f posix.mak test/stdcpp/.run MODEL=32 |
| 288 | + fi |
| 289 | +
|
| 290 | + - name: '[Windows] Run C++ test suite' |
| 291 | + if: runner.os == 'Windows' |
| 292 | + shell: cmd |
| 293 | + env: |
| 294 | + HOST_DC: ${{ env.DC }} |
| 295 | + run: | |
| 296 | + call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat" |
| 297 | + cd druntime |
| 298 | + make -f win64.mak test_stdcpp CC=cl LD=link AR=lib |
| 299 | + if %errorlevel% neq 0 exit /b %errorlevel% |
| 300 | +
|
| 301 | + ######################################## |
| 302 | + # Dump symbols on link failure # |
| 303 | + ######################################## |
| 304 | + - name: '[Posix,Fail] Dump C++ / D binary symbols' |
| 305 | + if: failure() && runner.os != 'Windows' |
| 306 | + run: | |
| 307 | + ls -l druntime/generated/*/release/*/ |
| 308 | + for file in druntime/generated/*/release/*/*.o*; do |
| 309 | + echo "========== Symbols for '$file' ==========" |
| 310 | + nm $file |
| 311 | + done |
0 commit comments