generic.yml 16 KB

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