generic.yml 18 KB

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