generic.yml 17 KB

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