generic.yml 17 KB

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