generic.yml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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. -DSDL_INSTALL_TESTS=${{ matrix.platform.build-tests }} \
  135. -DSDL_CLANG_TIDY=${{ matrix.platform.clang-tidy }} \
  136. -DSDL_DISABLE_INSTALL_DOCS=OFF \
  137. -DSDL_DISABLE_INSTALL_CPACK=OFF \
  138. -DSDL_DISABLE_INSTALL_DOCS=OFF \
  139. ${{ matrix.platform.cmake-arguments }} \
  140. -DSDL_SHARED=${{ matrix.platform.shared }} \
  141. -DSDL_STATIC=${{ matrix.platform.static }} \
  142. -DSDL_VENDOR_INFO="Github Workflow" \
  143. -DCMAKE_INSTALL_PREFIX=prefix \
  144. -DCMAKE_INSTALL_LIBDIR=lib \
  145. -DCMAKE_BUILD_TYPE=${{ matrix.platform.cmake-build-type }}
  146. - name: 'Build (CMake)'
  147. id: build
  148. if: ${{ !matrix.platform.no-cmake }}
  149. # shell: ${{ matrix.platform.shell }}
  150. run: |
  151. ${{ matrix.platform.source-cmd }}
  152. cmake --build build --config ${{ matrix.platform.cmake-build-type }} --verbose -- ${{ matrix.platform.cmake-build-arguments }}
  153. - name: 'Run build-time tests (CMake)'
  154. id: tests
  155. if: ${{ !matrix.platform.no-cmake && matrix.platform.run-tests }}
  156. # shell: ${{ matrix.platform.shell }}
  157. run: |
  158. ${{ matrix.platform.source-cmd }}
  159. set -eu
  160. export SDL_TESTS_QUICK=1
  161. ctest -VV --test-dir build/ -j2
  162. if test "${{ runner.os }}" = "Linux"; then
  163. # This should show us the SDL_REVISION
  164. strings build/libSDL3.so.0 | grep SDL-
  165. fi
  166. - name: "Build test apk's (CMake)"
  167. id: apks
  168. if: ${{ steps.build.outcome == 'success' && matrix.platform.android-apks != '' }}
  169. # shell: ${{ matrix.platform.shell }}
  170. run: |
  171. ${{ matrix.platform.source-cmd }}
  172. cmake --build build --config ${{ matrix.platform.cmake-build-type }} \
  173. --target \
  174. ${{ matrix.platform.android-apks }} \
  175. --verbose \
  176. -- ${{ matrix.platform.cmake-build-arguments }}
  177. - name: 'Install (CMake)'
  178. id: install
  179. if: ${{ steps.build.outcome == 'success' }}
  180. # shell: ${{ matrix.platform.shell }}
  181. run: |
  182. ${{ matrix.platform.source-cmd }}
  183. cmake --install build --config ${{ matrix.platform.cmake-build-type }}
  184. echo "prefix=$(pwd)/prefix" >> $GITHUB_OUTPUT
  185. ( cd prefix; find . ) | LC_ALL=C sort -u
  186. - name: 'Package (CPack)'
  187. id: package
  188. if: ${{ steps.build.outcome == 'success' }}
  189. # shell: ${{ matrix.platform.shell }}
  190. run: |
  191. # DMG creation on macOS occasionally fails, so try multiple times
  192. # https://gitlab.kitware.com/cmake/cmake/-/issues/25671
  193. success=0
  194. max_tries=10
  195. for i in $(seq $max_tries); do
  196. cmake --build build/ --config ${{ matrix.platform.cmake-build-type }} --target package -- ${{ matrix.platform.cmake-build-arguments }} && success=1
  197. if test $success = 1; then
  198. break
  199. fi
  200. echo "Package creation failed. Sleep 1 second and try again."
  201. sleep 1
  202. done
  203. if test $success = 0; then
  204. echo "Package creation failed after $max_tries attempts."
  205. exit 1
  206. fi
  207. - name: 'Verify CMake configuration files'
  208. if: ${{ steps.install.outcome == 'success' }}
  209. # shell: ${{ matrix.platform.shell }}
  210. run: |
  211. ${{ matrix.platform.source-cmd }}
  212. ${{ matrix.platform.cmake-config-emulator }} cmake -S cmake/test -B cmake_test_build -GNinja \
  213. ${{ matrix.platform.cmake-toolchain-file != '' && format('-DCMAKE_TOOLCHAIN_FILE={0}', matrix.platform.cmake-toolchain-file) || '' }} \
  214. -DTEST_SHARED=${{ matrix.platform.shared }} \
  215. -DTEST_STATIC=${{ matrix.platform.static }} \
  216. ${{ matrix.platform.cmake-arguments }} \
  217. -DCMAKE_BUILD_TYPE=${{ matrix.platform.cmake-build-type }} \
  218. -DCMAKE_PREFIX_PATH="${{ steps.install.outputs.prefix }}"
  219. cmake --build cmake_test_build --verbose --config ${{ matrix.platform.cmake-build-type }} -- ${{ matrix.platform.cmake-build-arguments }}
  220. - name: 'Extract CC/CXX/CFLAGS/CXXFLAGS from CMake toolchain'
  221. if: ${{ steps.install.outcome == 'success' && matrix.platform.cc-from-cmake }}
  222. # shell: ${{ matrix.platform.shell }}
  223. run: |
  224. cmake -S .github/cmake -B /tmp/cmake_extract \
  225. ${{ matrix.platform.cmake-toolchain-file != '' && format('-DCMAKE_TOOLCHAIN_FILE={0}', matrix.platform.cmake-toolchain-file) || '' }} \
  226. -DCMAKE_BUILD_TYPE=${{ matrix.platform.cmake-build-type }} \
  227. -DVAR_PATH=/tmp/env.txt
  228. cat /tmp/env.txt >> $GITHUB_ENV
  229. - name: 'Verify sdl3.pc'
  230. # shell: ${{ matrix.platform.shell }}
  231. if: ${{ steps.install.outcome == 'success' && matrix.platform.test-pkg-config }}
  232. run: |
  233. ${{ matrix.platform.source-cmd }}
  234. ${{ matrix.platform.cc && format('export CC="{0}"', matrix.platform.cc) || '' }}
  235. ${{ matrix.platform.cflags && format('export CFLAGS="{0}"', matrix.platform.cflags) || '' }}
  236. ${{ matrix.platform.ldflags && format('export LDFLAGS="{0}"', matrix.platform.ldflags) || '' }}
  237. export PKG_CONFIG_PATH=${{ steps.install.outputs.prefix }}/lib/pkgconfig
  238. cmake/test/test_pkgconfig.sh
  239. - name: 'Build (cross-platform-actions, BSD)'
  240. id: cpactions
  241. if: ${{ matrix.platform.cpactions }}
  242. uses: cross-platform-actions/action@v0.25.0
  243. with:
  244. operating_system: ${{ matrix.platform.cpactions-os }}
  245. architecture: ${{ matrix.platform.cpactions-arch }}
  246. version: ${{ matrix.platform.cpactions-version }}
  247. run: |
  248. ${{ matrix.platform.cpactions-setup-cmd }}
  249. ${{ matrix.platform.cpactions-install-cmd }}
  250. cmake -S . -B build -GNinja \
  251. ${{ matrix.platform.cmake-toolchain-file != '' && format('-DCMAKE_TOOLCHAIN_FILE={0}', matrix.platform.cmake-toolchain-file) || '' }} \
  252. -Wdeprecated -Wdev -Werror \
  253. -DSDL_WERROR=${{ matrix.platform.werror }} \
  254. -DSDL_DISABLE_INSTALL_DOCS=OFF \
  255. ${{ matrix.platform.cmake-arguments }} \
  256. -DSDL_SHARED=${{ matrix.platform.shared }} \
  257. -DSDL_STATIC=${{ matrix.platform.static }} \
  258. -DSDL_VENDOR_INFO="Github Workflow" \
  259. -DCMAKE_INSTALL_PREFIX=prefix \
  260. -DCMAKE_INSTALL_LIBDIR=lib \
  261. -DCMAKE_BUILD_TYPE=${{ matrix.platform.cmake-build-type }}
  262. cmake --build build/ --config ${{ matrix.platform.cmake-build-type }} --verbose
  263. cmake --build build/ --config ${{ matrix.platform.cmake-build-type }} --target package
  264. cmake --build build/ --config ${{ matrix.platform.cmake-build-type }} --target clean
  265. rm -rf build/dist/_CPack_Packages
  266. rm -rf build/CMakeFiles
  267. rm -rf build/docs
  268. - name: "Upload Android test apk's"
  269. uses: actions/upload-artifact@v4
  270. if: ${{ always() && matrix.platform.artifact != '' && steps.apks.outcome == 'success' }}
  271. with:
  272. if-no-files-found: error
  273. name: '${{ matrix.platform.artifact }}-apks'
  274. path: build/test/*.apk
  275. - name: Add msbuild to PATH
  276. id: setup-msbuild
  277. if: ${{ matrix.platform.msvc-project != '' }}
  278. uses: microsoft/setup-msbuild@v2
  279. - name: Build msbuild
  280. if: ${{ matrix.platform.msvc-project != '' }}
  281. run: |
  282. "$(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 }}
  283. - name: 'Build (Android.mk)'
  284. if: ${{ matrix.platform.android-mk }}
  285. run: |
  286. ./build-scripts/androidbuildlibs.sh
  287. - name: 'Create Gradle project (Android)'
  288. if: ${{ matrix.platform.android-gradle }}
  289. run: |
  290. for folder in build-ndk-build build-cmake; do
  291. python build-scripts/create-android-project.py \
  292. --output "${folder}" \
  293. --variant copy \
  294. org.libsdl.testspriteminimal \
  295. test/testspriteminimal.c test/icon.h
  296. done
  297. echo ""
  298. echo "Project contents:"
  299. echo ""
  300. find "build-ndk-build/org.libsdl.testspriteminimal"
  301. - name: 'Build Android app (Gradle & ndk-build)'
  302. if: ${{ matrix.platform.android-gradle }}
  303. run: |
  304. cd build-ndk-build/org.libsdl.testspriteminimal
  305. ./gradlew -i assembleRelease
  306. - name: 'Build Android app (Gradle & CMake)'
  307. if: ${{ matrix.platform.android-gradle }}
  308. run: |
  309. cd build-cmake/org.libsdl.testspriteminimal
  310. ./gradlew -i assembleRelease -PBUILD_WITH_CMAKE=1
  311. - name: 'Build (xcode)'
  312. if: ${{ matrix.platform.xcode-sdk != '' }}
  313. run: |
  314. xcodebuild -project Xcode/SDL/SDL.xcodeproj -target SDL3 -configuration Release -sdk ${{ matrix.platform.xcode-sdk }} clean build
  315. - name: 'Upload binary package'
  316. uses: actions/upload-artifact@v4
  317. if: ${{ always() && matrix.platform.artifact != '' && (steps.package.outcome == 'success' || steps.cpactions.outcome == 'success') }}
  318. with:
  319. if-no-files-found: error
  320. name: '${{ matrix.platform.artifact }}'
  321. path: build/dist/SDL3*
  322. - name: 'Upload minidumps'
  323. uses: actions/upload-artifact@v4
  324. if: ${{ always() && steps.tests.outcome == 'failure' && (matrix.platform.platform == 'msvc' || matrix.platform.platform == 'msys2') }}
  325. with:
  326. if-no-files-found: ignore
  327. name: '${{ matrix.platform.artifact }}-minidumps'
  328. path: build/**/*.dmp