generic.yml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. name: 'Build'
  2. run-name: 'Configure, Build and Test SDL'
  3. on:
  4. workflow_call:
  5. inputs:
  6. platforms:
  7. description: 'JSON-encoded test properties'
  8. type: string
  9. required: true
  10. jobs:
  11. build:
  12. name: ${{ matrix.platform.name }}
  13. runs-on: ${{ matrix.platform.os }}
  14. container: ${{ matrix.platform.container }}
  15. defaults:
  16. run:
  17. shell: ${{ matrix.platform.shell }}
  18. strategy:
  19. fail-fast: false
  20. matrix:
  21. platform: ${{ fromJSON(inputs.platforms) }}
  22. steps:
  23. - name: 'Set up MSYS2'
  24. if: ${{ matrix.platform.platform == 'msys2' }}
  25. uses: msys2/setup-msys2@v2
  26. with:
  27. msystem: ${{ matrix.platform.msys2-msystem }}
  28. install: >-
  29. ${{ matrix.platform.msys2-env }}-cc
  30. ${{ matrix.platform.msys2-env }}-cmake
  31. ${{ matrix.platform.msys2-env }}-ninja
  32. ${{ (!matrix.platform.msys2-no-perl && format('{0}-perl', matrix.platform.msys2-env)) || '' }}
  33. ${{ matrix.platform.msys2-env }}-pkg-config
  34. ${{ matrix.platform.msys2-env }}-clang-tools-extra
  35. - uses: actions/checkout@v4
  36. - name: 'Set up ninja'
  37. if: ${{ matrix.platform.setup-ninja }}
  38. uses: ./.github/actions/setup-ninja
  39. - name: 'Set up libusb'
  40. id: libusb
  41. if: ${{ matrix.platform.setup-libusb-arch != '' }}
  42. uses: ./.github/actions/setup-msvc-libusb
  43. with:
  44. arch: ${{ matrix.platform.setup-libusb-arch }}
  45. - uses: mymindstorm/setup-emsdk@v14
  46. if: ${{ matrix.platform.platform == 'emscripten' }}
  47. with:
  48. version: 3.1.35
  49. - uses: nttld/setup-ndk@v1
  50. if: ${{ matrix.platform.android-ndk }}
  51. id: setup-ndk
  52. with:
  53. local-cache: true
  54. ndk-version: r21e
  55. - name: 'Configure Android NDK variables'
  56. if: ${{ matrix.platform.android-ndk }}
  57. shell: sh
  58. run: |
  59. # We cannot use GitHub expressions in the controller job
  60. echo "ANDROID_NDK_HOME=${{ steps.setup-ndk.outputs.ndk-path }}" >>$GITHUB_ENV
  61. - uses: actions/setup-java@v4
  62. if: ${{ matrix.platform.java }}
  63. with:
  64. distribution: 'temurin'
  65. java-version: '17'
  66. - uses: ilammy/msvc-dev-cmd@v1
  67. if: ${{ matrix.platform.platform == 'msvc' }}
  68. with:
  69. arch: ${{ matrix.platform.msvc-vcvars }}
  70. - name: 'Set up LoongArch64 toolchain'
  71. uses: ./.github/actions/setup-loongarch64-toolchain
  72. id: setup-loongarch64-toolchain
  73. if: ${{ matrix.platform.platform == 'loongarch64' }}
  74. with:
  75. version: '2022.09.0'
  76. - name: 'Configure LoongArch64 variables'
  77. if: ${{ matrix.platform.platform == 'loongarch64' }}
  78. shell: sh
  79. run: |
  80. # We cannot use GitHub expressions in the controller job
  81. echo "LOONGARCH64_CC=${{ steps.setup-loongarch64-toolchain.outputs.cc }}" >>$GITHUB_ENV
  82. echo "LOONGARCH64_CXX=${{ steps.setup-loongarch64-toolchain.outputs.cxx }}" >>$GITHUB_ENV
  83. - name: 'Setup Intel oneAPI toolchain'
  84. id: intel
  85. if: ${{ matrix.platform.intel }}
  86. run: |
  87. # Download the key to system keyring
  88. wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB \
  89. | gpg --dearmor | sudo tee /usr/share/keyrings/oneapi-archive-keyring.gpg > /dev/null
  90. # Add signed entry to apt sources and configure the APT client to use Intel repository:
  91. 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
  92. # Update package list
  93. sudo apt-get update -y
  94. # Install oneAPI
  95. sudo apt-get install -y intel-oneapi-compiler-dpcpp-cpp-and-cpp-classic
  96. - name: 'Install apk packages'
  97. if: ${{ matrix.platform.apk-packages != '' }}
  98. run: |
  99. ${{ matrix.platform.sudo }} apk update
  100. ${{ matrix.platform.sudo }} apk add ${{ matrix.platform.apk-packages }}
  101. - name: 'Install apt packages'
  102. if: ${{ matrix.platform.apt-packages != '' }}
  103. run: |
  104. ${{ matrix.platform.sudo }} apt-get update
  105. ${{ matrix.platform.sudo }} apt-get install -y ${{ matrix.platform.apt-packages }}
  106. - name: 'Install brew packages'
  107. if: ${{ matrix.platform.brew-packages != '' }}
  108. run: |
  109. export HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1
  110. brew update
  111. brew install ${{ matrix.platform.brew-packages }}
  112. - name: 'Pollute toolchain with "bad SDL headers'
  113. if: ${{ matrix.platform.pollute-directories != '' }}
  114. #shell: ${{ matrix.platform.shell }}
  115. run: |
  116. # Create "bad" SDL headers in the toolchain.
  117. # SDL sources should not use these.
  118. for include in ${{ matrix.platform.pollute-directories }}; do
  119. toolchain_directory="${include}/SDL3"
  120. echo "Creating directory ${toolchain_directory}"
  121. mkdir -p "${toolchain_directory}/SDL3"
  122. for header in include/SDL3/*.h; do
  123. dest="${toolchain_directory}/SDL3/$(basename "${header}")"
  124. echo "Creating ${dest}"
  125. echo '#error "System SDL headers must not be used by build system"' >"$dest"
  126. done
  127. done
  128. - name: 'Configure (CMake)'
  129. if: ${{ !matrix.platform.no-cmake }}
  130. #shell: ${{ matrix.platform.shell }}
  131. run: |
  132. ${{ matrix.platform.source-cmd }}
  133. ${{ matrix.platform.cmake-config-emulator }} cmake -S . -B build -GNinja \
  134. -Wdeprecated -Wdev -Werror \
  135. ${{ matrix.platform.cmake-toolchain-file != '' && format('-DCMAKE_TOOLCHAIN_FILE={0}', matrix.platform.cmake-toolchain-file) || '' }} \
  136. -DSDL_WERROR=${{ matrix.platform.werror }} \
  137. -DSDL_EXAMPLES=${{ matrix.platform.build-tests }} \
  138. -DSDL_TESTS=${{ matrix.platform.build-tests }} \
  139. -DSDL_INSTALL_TESTS=${{ matrix.platform.build-tests }} \
  140. -DSDL_CLANG_TIDY=${{ matrix.platform.clang-tidy }} \
  141. -DSDL_DISABLE_INSTALL_DOCS=OFF \
  142. -DSDL_DISABLE_INSTALL_CPACK=OFF \
  143. -DSDL_DISABLE_INSTALL_DOCS=OFF \
  144. ${{ matrix.platform.cmake-arguments }} \
  145. -DSDL_SHARED=${{ matrix.platform.shared }} \
  146. -DSDL_STATIC=${{ matrix.platform.static }} \
  147. -DSDL_VENDOR_INFO="Github Workflow" \
  148. -DCMAKE_INSTALL_PREFIX=prefix \
  149. -DCMAKE_INSTALL_LIBDIR=lib \
  150. -DCMAKE_BUILD_TYPE=${{ matrix.platform.cmake-build-type }}
  151. - name: 'Build (CMake)'
  152. id: build
  153. if: ${{ !matrix.platform.no-cmake }}
  154. # shell: ${{ matrix.platform.shell }}
  155. run: |
  156. ${{ matrix.platform.source-cmd }}
  157. cmake --build build --config ${{ matrix.platform.cmake-build-type }} --verbose -- ${{ matrix.platform.cmake-build-arguments }}
  158. - name: 'Run build-time tests (CMake)'
  159. id: tests
  160. if: ${{ !matrix.platform.no-cmake && matrix.platform.run-tests }}
  161. # shell: ${{ matrix.platform.shell }}
  162. run: |
  163. ${{ matrix.platform.source-cmd }}
  164. set -eu
  165. export SDL_TESTS_QUICK=1
  166. ctest -VV --test-dir build/ -j2
  167. if test "${{ runner.os }}" = "Linux"; then
  168. # This should show us the SDL_REVISION
  169. strings build/libSDL3.so.0 | grep SDL-
  170. fi
  171. - name: "Build test apk's (CMake)"
  172. id: apks
  173. if: ${{ steps.build.outcome == 'success' && matrix.platform.android-apks != '' }}
  174. # shell: ${{ matrix.platform.shell }}
  175. run: |
  176. ${{ matrix.platform.source-cmd }}
  177. cmake --build build --config ${{ matrix.platform.cmake-build-type }} \
  178. --target \
  179. ${{ matrix.platform.android-apks }} \
  180. --verbose \
  181. -- ${{ matrix.platform.cmake-build-arguments }}
  182. - name: 'Install (CMake)'
  183. id: install
  184. if: ${{ steps.build.outcome == 'success' }}
  185. # shell: ${{ matrix.platform.shell }}
  186. run: |
  187. ${{ matrix.platform.source-cmd }}
  188. cmake --install build --config ${{ matrix.platform.cmake-build-type }}
  189. echo "prefix=$(pwd)/prefix" >> $GITHUB_OUTPUT
  190. ( cd prefix; find . ) | LC_ALL=C sort -u
  191. - name: 'Package (CPack)'
  192. id: package
  193. if: ${{ steps.build.outcome == 'success' }}
  194. # shell: ${{ matrix.platform.shell }}
  195. run: |
  196. # DMG creation on macOS occasionally fails, so try multiple times
  197. # https://gitlab.kitware.com/cmake/cmake/-/issues/25671
  198. success=0
  199. max_tries=10
  200. for i in $(seq $max_tries); do
  201. cmake --build build/ --config ${{ matrix.platform.cmake-build-type }} --target package -- ${{ matrix.platform.cmake-build-arguments }} && success=1
  202. if test $success = 1; then
  203. break
  204. fi
  205. echo "Package creation failed. Sleep 1 second and try again."
  206. sleep 1
  207. done
  208. if test $success = 0; then
  209. echo "Package creation failed after $max_tries attempts."
  210. exit 1
  211. fi
  212. - name: 'Verify CMake configuration files'
  213. if: ${{ steps.install.outcome == 'success' }}
  214. # shell: ${{ matrix.platform.shell }}
  215. run: |
  216. ${{ matrix.platform.source-cmd }}
  217. ${{ matrix.platform.cmake-config-emulator }} cmake -S cmake/test -B cmake_test_build -GNinja \
  218. ${{ matrix.platform.cmake-toolchain-file != '' && format('-DCMAKE_TOOLCHAIN_FILE={0}', matrix.platform.cmake-toolchain-file) || '' }} \
  219. -DTEST_SHARED=${{ matrix.platform.shared }} \
  220. -DTEST_STATIC=${{ matrix.platform.static }} \
  221. ${{ matrix.platform.cmake-arguments }} \
  222. -DCMAKE_BUILD_TYPE=${{ matrix.platform.cmake-build-type }} \
  223. -DCMAKE_PREFIX_PATH="${{ steps.install.outputs.prefix }}"
  224. cmake --build cmake_test_build --verbose --config ${{ matrix.platform.cmake-build-type }} -- ${{ matrix.platform.cmake-build-arguments }}
  225. - name: 'Extract CC/CXX/CFLAGS/CXXFLAGS from CMake toolchain'
  226. if: ${{ steps.install.outcome == 'success' && matrix.platform.cc-from-cmake }}
  227. # shell: ${{ matrix.platform.shell }}
  228. run: |
  229. cmake -S .github/cmake -B /tmp/cmake_extract \
  230. ${{ matrix.platform.cmake-toolchain-file != '' && format('-DCMAKE_TOOLCHAIN_FILE={0}', matrix.platform.cmake-toolchain-file) || '' }} \
  231. -DCMAKE_BUILD_TYPE=${{ matrix.platform.cmake-build-type }} \
  232. -DVAR_PATH=/tmp/env.txt
  233. cat /tmp/env.txt >> $GITHUB_ENV
  234. - name: 'Verify sdl3.pc'
  235. # shell: ${{ matrix.platform.shell }}
  236. if: ${{ steps.install.outcome == 'success' && matrix.platform.test-pkg-config }}
  237. run: |
  238. ${{ matrix.platform.source-cmd }}
  239. ${{ matrix.platform.cc && format('export CC="{0}"', matrix.platform.cc) || '' }}
  240. ${{ matrix.platform.cflags && format('export CFLAGS="{0}"', matrix.platform.cflags) || '' }}
  241. ${{ matrix.platform.ldflags && format('export LDFLAGS="{0}"', matrix.platform.ldflags) || '' }}
  242. export PKG_CONFIG_PATH=${{ steps.install.outputs.prefix }}/lib/pkgconfig
  243. cmake/test/test_pkgconfig.sh
  244. - name: 'Build (cross-platform-actions, BSD)'
  245. id: cpactions
  246. if: ${{ matrix.platform.cpactions }}
  247. uses: cross-platform-actions/action@v0.25.0
  248. with:
  249. operating_system: ${{ matrix.platform.cpactions-os }}
  250. architecture: ${{ matrix.platform.cpactions-arch }}
  251. version: ${{ matrix.platform.cpactions-version }}
  252. run: |
  253. ${{ matrix.platform.cpactions-setup-cmd }}
  254. ${{ matrix.platform.cpactions-install-cmd }}
  255. cmake -S . -B build -GNinja \
  256. ${{ matrix.platform.cmake-toolchain-file != '' && format('-DCMAKE_TOOLCHAIN_FILE={0}', matrix.platform.cmake-toolchain-file) || '' }} \
  257. -Wdeprecated -Wdev -Werror \
  258. -DSDL_WERROR=${{ matrix.platform.werror }} \
  259. -DSDL_DISABLE_INSTALL_DOCS=OFF \
  260. ${{ matrix.platform.cmake-arguments }} \
  261. -DSDL_SHARED=${{ matrix.platform.shared }} \
  262. -DSDL_STATIC=${{ matrix.platform.static }} \
  263. -DSDL_VENDOR_INFO="Github Workflow" \
  264. -DCMAKE_INSTALL_PREFIX=prefix \
  265. -DCMAKE_INSTALL_LIBDIR=lib \
  266. -DCMAKE_BUILD_TYPE=${{ matrix.platform.cmake-build-type }}
  267. cmake --build build/ --config ${{ matrix.platform.cmake-build-type }} --verbose
  268. cmake --build build/ --config ${{ matrix.platform.cmake-build-type }} --target package
  269. cmake --build build/ --config ${{ matrix.platform.cmake-build-type }} --target clean
  270. rm -rf build/dist/_CPack_Packages
  271. rm -rf build/CMakeFiles
  272. rm -rf build/docs
  273. - name: "Upload Android test apk's"
  274. uses: actions/upload-artifact@v4
  275. if: ${{ always() && matrix.platform.artifact != '' && steps.apks.outcome == 'success' }}
  276. with:
  277. if-no-files-found: error
  278. name: '${{ matrix.platform.artifact }}-apks'
  279. path: build/test/*.apk
  280. - name: Add msbuild to PATH
  281. id: setup-msbuild
  282. if: ${{ matrix.platform.msvc-project != '' }}
  283. uses: microsoft/setup-msbuild@v2
  284. - name: Build msbuild
  285. if: ${{ matrix.platform.msvc-project != '' }}
  286. run: |
  287. "$(cygpath -u '${{ steps.setup-msbuild.outputs.msbuildPath }}\msbuild.exe')" ${{ matrix.platform.msvc-project }} -m -p:BuildInParallel=true -p:Configuration=Release ${{ matrix.platform.msvc-project-flags }}
  288. - name: 'Build (Android.mk)'
  289. if: ${{ matrix.platform.android-mk }}
  290. run: |
  291. ./build-scripts/androidbuildlibs.sh
  292. - name: 'Create Gradle project (Android)'
  293. if: ${{ matrix.platform.android-gradle }}
  294. run: |
  295. for folder in build-ndk-build build-cmake; do
  296. python build-scripts/create-android-project.py \
  297. --output "${folder}" \
  298. --variant copy \
  299. org.libsdl.testspriteminimal \
  300. test/testspriteminimal.c test/icon.h
  301. done
  302. echo ""
  303. echo "Project contents:"
  304. echo ""
  305. find "build-ndk-build/org.libsdl.testspriteminimal"
  306. - name: 'Build Android app (Gradle & ndk-build)'
  307. if: ${{ matrix.platform.android-gradle }}
  308. run: |
  309. cd build-ndk-build/org.libsdl.testspriteminimal
  310. ./gradlew -i assembleRelease
  311. - name: 'Build Android app (Gradle & CMake)'
  312. if: ${{ matrix.platform.android-gradle }}
  313. run: |
  314. cd build-cmake/org.libsdl.testspriteminimal
  315. ./gradlew -i assembleRelease -PBUILD_WITH_CMAKE=1
  316. - name: 'Build (xcode)'
  317. if: ${{ matrix.platform.xcode-sdk != '' }}
  318. run: |
  319. xcodebuild -project Xcode/SDL/SDL.xcodeproj -target SDL3 -configuration Release -sdk ${{ matrix.platform.xcode-sdk }} clean build
  320. - name: 'Upload binary package'
  321. uses: actions/upload-artifact@v4
  322. if: ${{ always() && matrix.platform.artifact != '' && (steps.package.outcome == 'success' || steps.cpactions.outcome == 'success') }}
  323. with:
  324. if-no-files-found: error
  325. name: '${{ matrix.platform.artifact }}'
  326. path: build/dist/SDL3*
  327. - name: 'Upload minidumps'
  328. uses: actions/upload-artifact@v4
  329. if: ${{ always() && steps.tests.outcome == 'failure' && (matrix.platform.platform == 'msvc' || matrix.platform.platform == 'msys2') }}
  330. with:
  331. if-no-files-found: ignore
  332. name: '${{ matrix.platform.artifact }}-minidumps'
  333. path: build/**/*.dmp