main.yml 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. name: Build
  2. on: [push, pull_request]
  3. concurrency:
  4. group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
  5. cancel-in-progress: true
  6. jobs:
  7. Build:
  8. name: ${{ matrix.platform.name }}
  9. runs-on: ${{ matrix.platform.os }}
  10. defaults:
  11. run:
  12. shell: ${{ matrix.platform.shell }}
  13. strategy:
  14. fail-fast: false
  15. matrix:
  16. platform:
  17. - { name: Windows (mingw32), os: windows-latest, shell: 'msys2 {0}', msystem: mingw32, msys-env: mingw-w64-i686, artifact: 'SDL-mingw32', no-perl: true }
  18. - { name: Windows (mingw64), os: windows-latest, shell: 'msys2 {0}', msystem: mingw64, msys-env: mingw-w64-x86_64, artifact: 'SDL-mingw64' }
  19. - { name: Windows (clang32), os: windows-latest, shell: 'msys2 {0}', msystem: clang32, msys-env: mingw-w64-clang-i686, artifact: 'SDL-msys2-clang32', no-perl: true }
  20. - { name: Windows (clang64), os: windows-latest, shell: 'msys2 {0}', msystem: clang64, msys-env: mingw-w64-clang-x86_64, artifact: 'SDL-msys2-clang64' }
  21. - { name: Windows (ucrt64), os: windows-latest, shell: 'msys2 {0}', msystem: ucrt64, msys-env: mingw-w64-ucrt-x86_64, artifact: 'SDL-msys2-ucrt64' }
  22. - { name: Ubuntu 20.04, os: ubuntu-20.04, shell: sh, artifact: 'SDL-ubuntu20.04' }
  23. - { name: Intel oneAPI (Ubuntu 20.04), os: ubuntu-20.04, shell: bash, artifact: 'SDL-ubuntu20.04-oneapi', intel: true,
  24. source_cmd: 'source /opt/intel/oneapi/setvars.sh; export CC=icx; export CXX=icx;'}
  25. - { name: Intel Compiler (Ubuntu 20.04), os: ubuntu-20.04, shell: bash, artifact: 'SDL-ubuntu20.04-icc', intel: true, cmake: '-DSDL_CLANG_TIDY=OFF',
  26. source_cmd: 'source /opt/intel/oneapi/setvars.sh; export CC=icc; export CXX=icpc; export CFLAGS=-diag-disable=10441; export CXXFLAGS=-diag-disable=10441; '}
  27. - { name: Ubuntu 22.04, os: ubuntu-22.04, shell: sh, artifact: 'SDL-ubuntu22.04' }
  28. - { name: MacOS (Framework) (x86_64), os: macos-12, shell: sh, cmake-platform: '-DCMAKE_OSX_ARCHITECTURES="x86_64;arm64"', cmake: '-DSDL_FRAMEWORK=ON -DSDL_CLANG_TIDY=OFF', skip_test_pkgconfig: true, artifact: 'SDL-macos-framework', no-static: true }
  29. - { name: MacOS (Framework) (arm64), os: macos-latest, shell: sh, cmake-platform: '-DCMAKE_OSX_ARCHITECTURES="x86_64;arm64"', cmake: '-DSDL_FRAMEWORK=ON -DSDL_CLANG_TIDY=OFF', skip_test_pkgconfig: true, no-static: true }
  30. - { name: MacOS (GNU prefix), os: macos-latest, shell: sh, cmake-platform: '-DCMAKE_OSX_ARCHITECTURES="arm64"', cmake: '-DCLANG_TIDY_BINARY="$(brew --prefix llvm)/bin/clang-tidy"', artifact: 'SDL-macos-arm64-gnu' }
  31. - { name: iOS (GNU prefix), os: macos-latest, shell: sh, cmake-platform: '-DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64"', cross-build: true, skip_test_pkgconfig: true, artifact: 'SDL-ios-gnu' }
  32. - { name: tvOS (GNU prefix), os: macos-latest, shell: sh, cmake-platform: '-DCMAKE_SYSTEM_NAME=tvOS -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64"', cross-build: true, skip_test_pkgconfig: true, artifact: 'SDL-tvos-gnu' }
  33. steps:
  34. - name: Set up MSYS2
  35. if: matrix.platform.shell == 'msys2 {0}'
  36. uses: msys2/setup-msys2@v2
  37. with:
  38. msystem: ${{ matrix.platform.msystem }}
  39. install: >-
  40. ${{ matrix.platform.msys-env }}-cc
  41. ${{ matrix.platform.msys-env }}-cmake
  42. ${{ matrix.platform.msys-env }}-ninja
  43. ${{ (!matrix.platform.no-perl && format('{0}-perl', matrix.platform.msys-env)) || '' }}
  44. ${{ matrix.platform.msys-env }}-pkg-config
  45. ${{ matrix.platform.msys-env }}-clang-tools-extra
  46. - name: Setup Linux dependencies
  47. if: runner.os == 'Linux'
  48. run: |
  49. sudo apt-get update
  50. sudo apt-get install build-essential git \
  51. pkg-config cmake ninja-build gnome-desktop-testing libasound2-dev libpulse-dev \
  52. libaudio-dev libjack-dev libsndio-dev libusb-1.0-0-dev libx11-dev libxext-dev \
  53. libxrandr-dev libxcursor-dev libxfixes-dev libxi-dev libxss-dev libwayland-dev \
  54. libxkbcommon-dev libdrm-dev libgbm-dev libgl1-mesa-dev libgles2-mesa-dev \
  55. libegl1-mesa-dev libdbus-1-dev libibus-1.0-dev libudev-dev fcitx-libs-dev
  56. - name: Setup extra Ubuntu 22.04 dependencies
  57. if: matrix.platform.os == 'ubuntu-22.04'
  58. run: |
  59. sudo apt-get install libpipewire-0.3-dev libdecor-0-dev
  60. - name: Setup Macos dependencies
  61. if: runner.os == 'macOS'
  62. run: |
  63. export HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1
  64. brew update
  65. brew install \
  66. ninja \
  67. pkg-config \
  68. llvm
  69. - name: Setup Intel oneAPI
  70. if: matrix.platform.intel
  71. run: |
  72. # Download the key to system keyring
  73. wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB \
  74. | gpg --dearmor | sudo tee /usr/share/keyrings/oneapi-archive-keyring.gpg > /dev/null
  75. # Add signed entry to apt sources and configure the APT client to use Intel repository:
  76. echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" | sudo tee /etc/apt/sources.list.d/oneAPI.list
  77. # Update package list
  78. sudo apt-get update -y
  79. # Install oneAPI
  80. sudo apt-get install -y intel-oneapi-compiler-dpcpp-cpp-and-cpp-classic
  81. - uses: actions/checkout@v4
  82. - name: Check that versioning is consistent
  83. # We only need to run this once: arbitrarily use the Linux/CMake build
  84. if: "runner.os == 'Linux'"
  85. run: ./build-scripts/test-versioning.sh
  86. - name: Configure (CMake)
  87. run: |
  88. ${{ matrix.platform.source_cmd }}
  89. cmake -S . -B build -G Ninja \
  90. -Wdeprecated -Wdev -Werror \
  91. -DSDL_SHARED=ON \
  92. -DSDL_STATIC=ON \
  93. -DSDL_TESTS=ON \
  94. -DSDL_WERROR=ON \
  95. -DSDL_INSTALL_TESTS=ON \
  96. -DSDL_VENDOR_INFO="Github Workflow" \
  97. -DSDL_CLANG_TIDY=ON \
  98. -DSDL_DISABLE_INSTALL_DOCS=${{ !matrix.platform.no-perl }} \
  99. -DCMAKE_INSTALL_PREFIX=cmake_prefix \
  100. -DCMAKE_BUILD_TYPE=Release \
  101. ${{ matrix.platform.cmake-platform }} \
  102. ${{ matrix.platform.cmake }}
  103. - name: Build (CMake)
  104. id: build
  105. run: |
  106. ${{ matrix.platform.source_cmd }}
  107. cmake --build build/ --config Release --verbose --parallel
  108. - name: Run build-time tests (CMake)
  109. if: ${{ !matrix.platform.cross-build }}
  110. run: |
  111. ${{ matrix.platform.source_cmd }}
  112. set -eu
  113. export SDL_TESTS_QUICK=1
  114. ctest -VV --test-dir build/ -j2
  115. if test "${{ runner.os }}" = "Linux"; then
  116. # This should show us the SDL_REVISION
  117. strings build/libSDL3.so.0 | grep SDL-
  118. fi
  119. - name: Install (CMake)
  120. run: |
  121. ${{ matrix.platform.source_cmd }}
  122. set -eu
  123. cmake --install build/ --config Release
  124. ( cd cmake_prefix; find . ) | LC_ALL=C sort -u
  125. - name: Package (CPack)
  126. if: ${{ always() && steps.build.outcome == 'success' }}
  127. run: |
  128. # DMG creation on macOS occasionally fails, so try multiple times
  129. # https://gitlab.kitware.com/cmake/cmake/-/issues/25671
  130. success=0
  131. max_tries=10
  132. for i in $(seq $max_tries); do
  133. cmake --build build/ --config Release --target package && success=1
  134. if test $success = 1; then
  135. break
  136. fi
  137. echo "Package creation failed. Sleep 1 second and try again."
  138. sleep 1
  139. done
  140. if test $success = 0; then
  141. echo "Package creation failed after $max_tries attempts."
  142. exit 1
  143. fi
  144. - name: Verify CMake configuration files
  145. run: |
  146. ${{ matrix.platform.source_cmd }}
  147. cmake -S cmake/test -B cmake_config_build -G Ninja \
  148. ${{ matrix.platform.cmake-platform }} \
  149. -DTEST_SHARED=ON \
  150. -DTEST_STATIC=${{ !matrix.platform.no-static }} \
  151. -DCMAKE_BUILD_TYPE=Release \
  152. -DCMAKE_PREFIX_PATH=$(echo "${{ github.workspace }}/cmake_prefix" | sed -e 's#\\#/#g')
  153. cmake --build cmake_config_build --verbose
  154. - name: Verify sdl3.pc
  155. if: ${{ !matrix.platform.skip_test_pkgconfig }}
  156. run: |
  157. ${{ matrix.platform.source_cmd }}
  158. export PKG_CONFIG_PATH=$(echo "${{ github.workspace }}/cmake_prefix/lib/pkgconfig" | sed -e 's#\\#/#g')
  159. cmake/test/test_pkgconfig.sh
  160. - uses: actions/upload-artifact@v4
  161. if: ${{ always() && matrix.platform.artifact != '' && steps.build.outcome == 'success' }}
  162. with:
  163. if-no-files-found: error
  164. name: ${{ matrix.platform.artifact }}
  165. path: build/dist/SDL3*