generic.yml 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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: ${{ matrix.platform.msys2-packages }}
  29. - name: 'About this job'
  30. run: |
  31. echo "key=${{ matrix.platform.key }}"
  32. echo "name=${{ matrix.platform.name }}"
  33. echo "os=${{ matrix.platform.os }}"
  34. echo ""
  35. echo "Add [sdl-ci-filter ${{ matrix.platform.key }}] to your commit message to reduce the number of jobs."
  36. - uses: actions/checkout@v4
  37. - name: 'Set up ninja'
  38. if: ${{ matrix.platform.setup-ninja }}
  39. uses: ./.github/actions/setup-ninja
  40. - name: 'Set up libusb for MSVC'
  41. if: ${{ matrix.platform.setup-libusb-arch != '' }}
  42. uses: ./.github/actions/setup-msvc-libusb
  43. with:
  44. arch: ${{ matrix.platform.setup-libusb-arch }}
  45. - uses: mymindstorm/setup-emsdk@v14
  46. if: ${{ matrix.platform.platform == 'emscripten' }}
  47. with:
  48. version: 3.1.35
  49. - uses: browser-actions/setup-chrome@v1
  50. id: setup-chrome
  51. if: ${{ matrix.platform.platform == 'emscripten' }}
  52. with:
  53. install-chromedriver: true
  54. - name: 'Add chrome to PATH'
  55. if: ${{ matrix.platform.platform == 'emscripten' }}
  56. run: |
  57. chrome_dir="$(dirname "${{ steps.setup-chrome.outputs.chrome-path }}")"
  58. chromedriver_dir="$(dirname "${{ steps.setup-chrome.outputs.chromedriver-path }}")"
  59. echo "CHROME_BINARY=${{ steps.setup-chrome.outputs.chrome-path }}" >>$GITHUB_ENV
  60. echo "CHROMEDRIVER_BINARY=${{ steps.setup-chrome.outputs.chromedriver-path }}" >>$GITHUB_ENV
  61. echo "chrome_dir=${chrome_dir}"
  62. echo "chromedriver_dir=${chromedriver_dir}"
  63. echo "${chrome_dir}" >>${GITHUB_PATH}
  64. echo "${chromedriver_dir}" >>${GITHUB_PATH}
  65. - uses: nttld/setup-ndk@v1
  66. if: ${{ matrix.platform.android-ndk }}
  67. id: setup-ndk
  68. with:
  69. local-cache: false
  70. ndk-version: r28c
  71. - name: 'Configure Android NDK variables'
  72. if: ${{ matrix.platform.android-ndk }}
  73. shell: sh
  74. run: |
  75. # We cannot use GitHub expressions in the controller job
  76. echo "ANDROID_NDK_HOME=${{ steps.setup-ndk.outputs.ndk-path }}" >>$GITHUB_ENV
  77. - uses: actions/setup-java@v4
  78. if: ${{ matrix.platform.java }}
  79. with:
  80. distribution: 'temurin'
  81. java-version: '17'
  82. - uses: ilammy/msvc-dev-cmd@v1
  83. if: ${{ matrix.platform.platform == 'msvc' }}
  84. with:
  85. arch: ${{ matrix.platform.msvc-vcvars-arch }}
  86. sdk: ${{ matrix.platform.msvc-vcvars-sdk }}
  87. - name: 'Set up Windows GDK Desktop'
  88. uses: ./.github/actions/setup-gdk-desktop
  89. if: ${{ matrix.platform.setup-gdk-folder != '' }}
  90. with:
  91. folder: '${{ matrix.platform.setup-gdk-folder }}'
  92. - name: 'Set up LoongArch64 toolchain'
  93. uses: ./.github/actions/setup-loongarch64-toolchain
  94. id: setup-loongarch64-toolchain
  95. if: ${{ matrix.platform.platform == 'loongarch64' }}
  96. - name: 'Setup Intel oneAPI toolchain'
  97. id: intel
  98. if: ${{ matrix.platform.intel }}
  99. run: |
  100. # Download the key to system keyring
  101. wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB \
  102. | gpg --dearmor | sudo tee /usr/share/keyrings/oneapi-archive-keyring.gpg > /dev/null
  103. # Add signed entry to apt sources and configure the APT client to use Intel repository:
  104. 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
  105. # Update package list
  106. sudo apt-get update -y
  107. # Install oneAPI
  108. sudo apt-get install -y intel-oneapi-compiler-dpcpp-cpp-and-cpp-classic
  109. - name: 'Install apk packages'
  110. if: ${{ matrix.platform.apk-packages != '' }}
  111. run: |
  112. ${{ matrix.platform.sudo }} apk update
  113. ${{ matrix.platform.sudo }} apk add ${{ matrix.platform.apk-packages }}
  114. - name: 'Install apt packages'
  115. if: ${{ matrix.platform.apt-packages != '' }}
  116. run: |
  117. ${{ matrix.platform.sudo }} apt-get update
  118. ${{ matrix.platform.sudo }} apt-get install -y ${{ matrix.platform.apt-packages }}
  119. - name: 'Install brew packages'
  120. if: ${{ matrix.platform.brew-packages != '' }}
  121. run: |
  122. export HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1
  123. brew update
  124. brew install ${{ matrix.platform.brew-packages }}
  125. - name: 'Setup Python'
  126. uses: 'actions/setup-python@main'
  127. if: ${{ matrix.platform.setup-python }}
  128. with:
  129. python-version: '3.x'
  130. - name: 'Install PyPI packages'
  131. if: ${{ matrix.platform.pypi-packages != '' }}
  132. run: |
  133. python -m pip install --user ${{ matrix.platform.pypi-packages }}
  134. - name: 'Set up GLES for VITA' # Must be after apk
  135. if: ${{ matrix.platform.setup-vita-gles-type != '' }}
  136. uses: ./.github/actions/setup-vita-gles
  137. with:
  138. type: ${{ matrix.platform.setup-vita-gles-type }}
  139. - name: 'Pollute toolchain with "bad" SDL headers'
  140. if: ${{ matrix.platform.pollute-directories != '' }}
  141. #shell: ${{ matrix.platform.shell }}
  142. run: |
  143. # Create "bad" SDL headers in the toolchain.
  144. # SDL sources should not use these.
  145. for include in ${{ matrix.platform.pollute-directories }}; do
  146. toolchain_directory="${include}/SDL3"
  147. echo "Creating directory ${toolchain_directory}"
  148. mkdir -p "${toolchain_directory}/SDL3"
  149. for header in include/SDL3/*.h; do
  150. dest="${toolchain_directory}/SDL3/$(basename "${header}")"
  151. echo "Creating ${dest}"
  152. echo '#error "System SDL headers must not be used by build system"' >"$dest"
  153. done
  154. done
  155. - name: 'Calculate ccache key'
  156. if: ${{ matrix.platform.ccache }}
  157. id: prepare-restore-ccache
  158. run: |
  159. echo "timestamp=$(date -u "+%Y%m%d%H%M_%S")" >> "$GITHUB_OUTPUT"
  160. - name: 'Restore ccache'
  161. if: ${{ matrix.platform.ccache }}
  162. uses: actions/cache/restore@v4
  163. id: restore-ccache
  164. with:
  165. path: ${{ runner.temp }}/ccache
  166. key: ccache-${{ matrix.platform.key }}-${{ steps.prepare-restore-ccache.outputs.timestamp }}
  167. restore-keys: |
  168. ccache-${{matrix.platform.key}}
  169. - name: 'Configure ccache'
  170. if: ${{ matrix.platform.ccache }}
  171. run: |
  172. echo 'CCACHE_DIR=${{ runner.temp }}/ccache' >>${GITHUB_ENV}
  173. - name: 'Prepare ccache'
  174. if: ${{ matrix.platform.ccache && steps.restore-ccache.outputs.cache-hit }}
  175. run: |
  176. if [ "x${{ runner.os }}" = "xmacOS" ]; then
  177. touch_date="2025-02-01T12:00:00Z"
  178. else
  179. touch_date="2025-02-01"
  180. fi
  181. find "${CCACHE_DIR}" -type f -exec touch -a -m -d "$touch_date" {} +
  182. ccache -s
  183. ccache -z
  184. - name: 'Configure (CMake)'
  185. if: ${{ !matrix.platform.no-cmake }}
  186. #shell: ${{ matrix.platform.shell }}
  187. run: |
  188. ${{ matrix.platform.source-cmd }}
  189. ${{ matrix.platform.cmake-config-emulator }} cmake -S . -B build -G "${{ matrix.platform.cmake-generator }}" \
  190. -Wdeprecated -Wdev -Werror \
  191. ${{ matrix.platform.cmake-toolchain-file != '' && format('-DCMAKE_TOOLCHAIN_FILE={0}', matrix.platform.cmake-toolchain-file) || '' }} \
  192. -DSDL_WERROR=${{ matrix.platform.werror }} \
  193. -DSDL_EXAMPLES=${{ matrix.platform.build-tests }} \
  194. -DSDL_TESTS=${{ matrix.platform.build-tests }} \
  195. -DSDLTEST_TRACKMEM=ON \
  196. -DSDL_INSTALL_TESTS=${{ matrix.platform.build-tests }} \
  197. -DSDL_CLANG_TIDY=${{ matrix.platform.clang-tidy }} \
  198. -DSDL_INSTALL_DOCS=ON \
  199. -DSDL_INSTALL_CPACK=ON \
  200. -DSDL_INSTALL_DOCS=ON \
  201. ${{ matrix.platform.cmake-arguments }} \
  202. -DSDL_SHARED=${{ matrix.platform.shared }} \
  203. -DSDL_STATIC=${{ matrix.platform.static }} \
  204. -DSDL_VENDOR_INFO="Github Workflow" \
  205. -DCMAKE_INSTALL_PREFIX=prefix \
  206. -DCMAKE_INSTALL_LIBDIR=lib \
  207. -DCMAKE_BUILD_TYPE=${{ matrix.platform.cmake-build-type }}
  208. - name: 'Build (CMake)'
  209. id: build
  210. if: ${{ !matrix.platform.no-cmake }}
  211. # shell: ${{ matrix.platform.shell }}
  212. run: |
  213. ${{ matrix.platform.source-cmd }}
  214. cmake --build build --config ${{ matrix.platform.cmake-build-type }} --verbose -- ${{ matrix.platform.cmake-build-arguments }}
  215. - name: 'Verify SDL_REVISION'
  216. if: ${{ !matrix.platform.no-cmake }}
  217. run: |
  218. echo "This should show us the SDL_REVISION"
  219. echo "Shared library:"
  220. ${{ (matrix.platform.shared-lib && format('{0} build/{1} | grep "Github Workflow"', matrix.platform.binutils-strings, matrix.platform.shared-lib)) || 'echo "<Shared library not supported by platform>"' }}
  221. echo "Static library:"
  222. ${{ (matrix.platform.static-lib && format('{0} build/{1} | grep "Github Workflow"', matrix.platform.binutils-strings, matrix.platform.static-lib)) || 'echo "<Static library not supported by platform>"' }}
  223. - name: 'Run build-time tests (CMake)'
  224. id: tests
  225. if: ${{ !matrix.platform.no-cmake && matrix.platform.run-tests }}
  226. # shell: ${{ matrix.platform.shell }}
  227. run: |
  228. ${{ matrix.platform.source-cmd }}
  229. ${{ matrix.platform.pretest-cmd }}
  230. set -eu
  231. export SDL_TESTS_QUICK=1
  232. ctest -VV --test-dir build/ -j2
  233. - name: "Build test apk's (CMake)"
  234. id: apks
  235. if: ${{ always() && steps.build.outcome == 'success' && matrix.platform.android-apks != '' }}
  236. # shell: ${{ matrix.platform.shell }}
  237. run: |
  238. ${{ matrix.platform.source-cmd }}
  239. cmake --build build --config ${{ matrix.platform.cmake-build-type }} \
  240. --target \
  241. ${{ matrix.platform.android-apks }} \
  242. --verbose \
  243. -- ${{ matrix.platform.cmake-build-arguments }}
  244. - name: 'Install (CMake)'
  245. id: install
  246. if: ${{ always() && steps.build.outcome == 'success' }}
  247. # shell: ${{ matrix.platform.shell }}
  248. run: |
  249. ${{ matrix.platform.source-cmd }}
  250. cmake --install build --config ${{ matrix.platform.cmake-build-type }}
  251. echo "prefix=$(pwd)/prefix" >> $GITHUB_OUTPUT
  252. ( cd prefix; find . ) | LC_ALL=C sort -u
  253. - name: 'Package (CPack)'
  254. id: package
  255. if: ${{ always() && steps.build.outcome == 'success' }}
  256. # shell: ${{ matrix.platform.shell }}
  257. run: |
  258. # DMG creation on macOS occasionally fails, so try multiple times
  259. # https://gitlab.kitware.com/cmake/cmake/-/issues/25671
  260. success=0
  261. max_tries=10
  262. for i in $(seq $max_tries); do
  263. cmake --build build/ --config ${{ matrix.platform.cmake-build-type }} --target package -- ${{ matrix.platform.cmake-build-arguments }} && success=1
  264. if test $success = 1; then
  265. break
  266. fi
  267. echo "Package creation failed. Sleep 1 second and try again."
  268. sleep 1
  269. done
  270. if test $success = 0; then
  271. echo "Package creation failed after $max_tries attempts."
  272. exit 1
  273. fi
  274. - name: 'Verify CMake configuration files'
  275. if: ${{ steps.install.outcome == 'success' }}
  276. # shell: ${{ matrix.platform.shell }}
  277. run: |
  278. ${{ matrix.platform.source-cmd }}
  279. ${{ matrix.platform.cmake-config-emulator }} cmake -S cmake/test -B cmake_test_build -GNinja \
  280. ${{ matrix.platform.cmake-toolchain-file != '' && format('-DCMAKE_TOOLCHAIN_FILE={0}', matrix.platform.cmake-toolchain-file) || '' }} \
  281. -DTEST_SHARED=${{ matrix.platform.shared }} \
  282. -DTEST_STATIC=${{ matrix.platform.static }} \
  283. ${{ matrix.platform.cmake-arguments }} \
  284. -DCMAKE_BUILD_TYPE=${{ matrix.platform.cmake-build-type }} \
  285. -DCMAKE_PREFIX_PATH="${{ steps.install.outputs.prefix }}"
  286. cmake --build cmake_test_build --verbose --config ${{ matrix.platform.cmake-build-type }} -- ${{ matrix.platform.cmake-build-arguments }}
  287. - name: 'Extract CC/CXX/CFLAGS/CXXFLAGS from CMake toolchain'
  288. if: ${{ steps.install.outcome == 'success' && matrix.platform.cc-from-cmake }}
  289. # shell: ${{ matrix.platform.shell }}
  290. run: |
  291. cmake -S .github/cmake -B /tmp/cmake_extract \
  292. ${{ matrix.platform.cmake-toolchain-file != '' && format('-DCMAKE_TOOLCHAIN_FILE={0}', matrix.platform.cmake-toolchain-file) || '' }} \
  293. -DCMAKE_BUILD_TYPE=${{ matrix.platform.cmake-build-type }} \
  294. -DVAR_PATH=/tmp/env.txt
  295. cat /tmp/env.txt >> $GITHUB_ENV
  296. - name: 'Verify sdl3.pc'
  297. # shell: ${{ matrix.platform.shell }}
  298. if: ${{ steps.install.outcome == 'success' && matrix.platform.test-pkg-config }}
  299. run: |
  300. ${{ matrix.platform.source-cmd }}
  301. ${{ matrix.platform.cc && format('export CC="{0}"', matrix.platform.cc) || '' }}
  302. ${{ matrix.platform.cflags && format('export CFLAGS="{0}"', matrix.platform.cflags) || '' }}
  303. ${{ matrix.platform.ldflags && format('export LDFLAGS="{0}"', matrix.platform.ldflags) || '' }}
  304. export PKG_CONFIG_PATH=${{ steps.install.outputs.prefix }}/lib/pkgconfig
  305. cmake/test/test_pkgconfig.sh
  306. - name: 'Build (cross-platform-actions, BSD)'
  307. id: cpactions
  308. if: ${{ matrix.platform.cpactions }}
  309. uses: cross-platform-actions/action@v0.29.0
  310. with:
  311. operating_system: '${{ matrix.platform.cpactions-os }}'
  312. architecture: '${{ matrix.platform.cpactions-arch }}'
  313. version: '${{ matrix.platform.cpactions-version }}'
  314. run: |
  315. ${{ matrix.platform.cpactions-setup-cmd }}
  316. ${{ matrix.platform.cpactions-install-cmd }}
  317. cmake -S . -B build -GNinja \
  318. ${{ matrix.platform.cmake-toolchain-file != '' && format('-DCMAKE_TOOLCHAIN_FILE={0}', matrix.platform.cmake-toolchain-file) || '' }} \
  319. -Wdeprecated -Wdev -Werror \
  320. -DSDL_WERROR=${{ matrix.platform.werror }} \
  321. -DSDL_INSTALL_DOCS=ON \
  322. ${{ matrix.platform.cmake-arguments }} \
  323. -DSDL_SHARED=${{ matrix.platform.shared }} \
  324. -DSDL_STATIC=${{ matrix.platform.static }} \
  325. -DSDL_VENDOR_INFO="Github Workflow" \
  326. -DCMAKE_INSTALL_PREFIX=prefix \
  327. -DCMAKE_INSTALL_LIBDIR=lib \
  328. -DCMAKE_BUILD_TYPE=${{ matrix.platform.cmake-build-type }}
  329. cmake --build build/ --config ${{ matrix.platform.cmake-build-type }} --verbose
  330. cmake --build build/ --config ${{ matrix.platform.cmake-build-type }} --target package
  331. cmake --build build/ --config ${{ matrix.platform.cmake-build-type }} --target clean
  332. rm -rf build/dist/_CPack_Packages
  333. rm -rf build/CMakeFiles
  334. rm -rf build/docs
  335. - name: Add msbuild to PATH
  336. id: setup-msbuild
  337. if: ${{ matrix.platform.msvc-project != '' }}
  338. uses: microsoft/setup-msbuild@v2
  339. - name: Build msbuild
  340. if: ${{ matrix.platform.msvc-project != '' }}
  341. run: |
  342. "$(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 }}
  343. - name: 'Build (Android.mk)'
  344. if: ${{ matrix.platform.android-mk }}
  345. run: |
  346. ./build-scripts/androidbuildlibs.sh
  347. - name: 'Create Gradle project (Android)'
  348. if: ${{ matrix.platform.android-gradle }}
  349. run: |
  350. for folder in build-ndk-build build-cmake; do
  351. python build-scripts/create-android-project.py \
  352. --output "${folder}" \
  353. --variant copy \
  354. org.libsdl.testspriteminimal \
  355. test/testspriteminimal.c test/icon.h
  356. done
  357. echo ""
  358. echo "Project contents:"
  359. echo ""
  360. find "build-ndk-build/org.libsdl.testspriteminimal"
  361. - name: 'Build Android app (Gradle & ndk-build)'
  362. if: ${{ matrix.platform.android-gradle }}
  363. run: |
  364. cd build-ndk-build/org.libsdl.testspriteminimal
  365. ./gradlew -i assembleRelease
  366. - name: 'Build Android app (Gradle & CMake)'
  367. if: ${{ matrix.platform.android-gradle }}
  368. run: |
  369. cd build-cmake/org.libsdl.testspriteminimal
  370. ./gradlew -i assembleRelease -PBUILD_WITH_CMAKE=1
  371. - name: 'Build (xcode)'
  372. if: ${{ matrix.platform.xcode-sdk != '' }}
  373. run: |
  374. xcodebuild -project Xcode/SDL/SDL.xcodeproj -target SDL3 -configuration Release -sdk ${{ matrix.platform.xcode-sdk }} clean build
  375. - name: 'Prune old ccache files'
  376. if: ${{ matrix.platform.ccache }}
  377. run: |
  378. ccache --evict-older-than=1d
  379. ccache -s
  380. - name: 'Save ccache'
  381. if: ${{ matrix.platform.ccache }}
  382. uses: actions/cache/save@v4
  383. with:
  384. path: ${{ runner.temp }}/ccache
  385. key: ${{ steps.restore-ccache.outputs.cache-primary-key }}
  386. - name: 'Check Sources'
  387. if: ${{ matrix.platform.check-sources }}
  388. run: |
  389. set -e
  390. build-scripts/test-versioning.sh
  391. python build-scripts/check_android_jni.py
  392. python build-scripts/check_stdlib_usage.py
  393. - name: 'Verify alignment of Android test apks'
  394. if: ${{ matrix.platform.android-ndk && !matrix.platform.no-cmake }}
  395. run: |
  396. find ./ -iname '*.apk' | xargs -L1 ./build-scripts/check_elf_alignment.sh
  397. - name: 'Verify alignment of Android .so files'
  398. if: ${{ matrix.platform.android-ndk && !matrix.platform.no-cmake }}
  399. run: |
  400. find ./ -iname '*.so' | xargs -L1 ./build-scripts/check_elf_alignment.sh
  401. - name: 'Upload binary package'
  402. uses: actions/upload-artifact@v4
  403. if: ${{ always() && matrix.platform.artifact != '' && (steps.package.outcome == 'success' || steps.cpactions.outcome == 'success') && (matrix.platform.enable-artifacts || steps.tests.outcome == 'failure') }}
  404. with:
  405. if-no-files-found: error
  406. name: '${{ matrix.platform.artifact }}'
  407. path: |
  408. build/dist/SDL3*
  409. build/include*
  410. - name: 'Upload minidumps'
  411. uses: actions/upload-artifact@v4
  412. if: ${{ always() && steps.tests.outcome == 'failure' && (matrix.platform.platform == 'msvc' || matrix.platform.platform == 'msys2') }}
  413. with:
  414. if-no-files-found: ignore
  415. name: '${{ matrix.platform.artifact }}-minidumps'
  416. path: build/**/*.dmp
  417. - name: "Upload Android test apk's"
  418. uses: actions/upload-artifact@v4
  419. if: ${{ matrix.platform.enable-artifacts && always() && matrix.platform.artifact != '' && steps.apks.outcome == 'success' }}
  420. with:
  421. if-no-files-found: error
  422. name: '${{ matrix.platform.artifact }}-apks'
  423. path: build/test/*.apk