generic.yml 15 KB

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