generic.yml 16 KB

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