windows.yml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. name: windows
  2. on:
  3. push:
  4. branches:
  5. - master
  6. tags:
  7. - '*'
  8. pull_request: {}
  9. workflow_dispatch:
  10. jobs:
  11. build:
  12. strategy:
  13. fail-fast: true
  14. matrix:
  15. arch: [i686, x86_64, armv7, aarch64]
  16. os: [windows-latest, ubuntu-latest]
  17. runs-on: ${{ matrix.os }}
  18. steps:
  19. - uses: actions/checkout@v2
  20. with:
  21. fetch-depth: 0
  22. submodules: false
  23. - name: Set up environment for windows-latest
  24. shell : bash
  25. if: ${{ matrix.os == 'windows-latest' }}
  26. run: |
  27. echo "wget=C:\msys64\usr\bin\wget.exe" >> $GITHUB_ENV
  28. echo "unzip=unzip" >> $GITHUB_ENV
  29. if [ ${{ matrix.arch }} = "i686" ]; then
  30. echo "cmake_arch=Win32" >> $GITHUB_ENV
  31. elif [ ${{ matrix.arch }} = "x86_64" ]; then
  32. echo "cmake_arch=x64" >> $GITHUB_ENV
  33. elif [ ${{ matrix.arch }} = "armv7" ]; then
  34. echo "cmake_arch=ARM" >> $GITHUB_ENV
  35. else
  36. echo "cmake_arch=ARM64" >> $GITHUB_ENV
  37. fi
  38. - name: Set up environment for ubuntu-latest
  39. if: ${{ matrix.os == 'ubuntu-latest' }}
  40. run: |
  41. echo "wget=wget" >> $GITHUB_ENV
  42. echo "unzip=unzip" >> $GITHUB_ENV
  43. - name: Restore timestamps
  44. run: |
  45. ${{ env.wget }} https://github.com/MestreLion/git-tools/archive/refs/heads/main.zip
  46. ${{ env.unzip }} main.zip
  47. python git-tools-main/git-restore-mtime
  48. - name: List build cache restore keys
  49. shell : bash
  50. run: |
  51. # Look for the last 9 build caches (GitHub supports max 10 including current one)
  52. for number in 1 2 3 4 5 6 7 8 9
  53. do
  54. id=$((${{ github.run_number }} - number))
  55. echo "cache_$number=windows-${{ github.ref }}-${{ matrix.arch }}-${{ matrix.os }}-$id" >> $GITHUB_ENV
  56. done
  57. - name: Handle build cache
  58. uses: actions/cache@v2
  59. with:
  60. path: |
  61. build
  62. key: windows-${{ github.ref }}-${{ matrix.arch }}-${{ matrix.os }}-${{ github.run_number }}
  63. restore-keys: |
  64. ${{ env.cache_1 }}
  65. ${{ env.cache_2 }}
  66. ${{ env.cache_3 }}
  67. ${{ env.cache_4 }}
  68. ${{ env.cache_5 }}
  69. ${{ env.cache_6 }}
  70. ${{ env.cache_7 }}
  71. ${{ env.cache_8 }}
  72. ${{ env.cache_9 }}
  73. - name: Download dependencies
  74. run: |
  75. ${{ env.wget }} https://github.com/supertuxkart/dependencies/releases/download/preview/dependencies-win-${{ matrix.arch }}.zip
  76. ${{ env.unzip }} dependencies-win-${{ matrix.arch }}.zip
  77. - name: Install MinGW for i686 or x86_64
  78. if: ${{ matrix.os == 'ubuntu-latest' && ( matrix.arch == 'i686' || matrix.arch == 'x86_64' ) }}
  79. run: |
  80. cd /
  81. sudo mkdir -p /data/mxe/usr
  82. cd /data/mxe/usr
  83. # It's compiled from https://github.com/mxe/mxe
  84. sudo wget https://github.com/supertuxkart/dependencies/releases/download/preview/mxe_static_mingw.zip
  85. sudo unzip mxe_static_mingw.zip
  86. sudo rm mxe_static_mingw.zip
  87. # For libfl.so.2
  88. sudo apt install -y libfl-dev
  89. - name: Install MinGW for armv7 or aarch64
  90. if: ${{ matrix.os == 'ubuntu-latest' && ( matrix.arch == 'armv7' || matrix.arch == 'aarch64' ) }}
  91. run: |
  92. cd /
  93. sudo wget https://github.com/mstorsjo/llvm-mingw/releases/download/20210423/llvm-mingw-20210423-msvcrt-ubuntu-18.04-x86_64.tar.xz
  94. sudo tar xf llvm-mingw-20210423-msvcrt-ubuntu-18.04-x86_64.tar.xz
  95. sudo mv llvm-mingw-20210423-msvcrt-ubuntu-18.04-x86_64 llvm-mingw
  96. - name: Set up MinGW Toolchain for i686
  97. if: ${{ matrix.os == 'ubuntu-latest' && matrix.arch == 'i686' }}
  98. run: |
  99. echo "SET(CMAKE_SYSTEM_NAME Windows)" > toolchain.cmake
  100. echo "SET(CMAKE_C_COMPILER /data/mxe/usr/bin/i686-w64-mingw32.static.posix.dw2-gcc)" >> toolchain.cmake
  101. echo "SET(CMAKE_CXX_COMPILER /data/mxe/usr/bin/i686-w64-mingw32.static.posix.dw2-g++)" >> toolchain.cmake
  102. echo "SET(CMAKE_RC_COMPILER /data/mxe/usr/bin/i686-w64-mingw32.static.posix.dw2-windres)" >> toolchain.cmake
  103. echo "SET(CMAKE_FIND_ROOT_PATH \${PROJECT_SOURCE_DIR}/dependencies-win-i686 /data/mxe/usr/i686-w64-mingw32.static.posix.dw2/ /data/mxe/usr/lib/gcc/i686-w64-mingw32.static.posix.dw2/5.5.0/)" >> toolchain.cmake
  104. echo "set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)" >> toolchain.cmake
  105. echo "set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ALWAYS)" >> toolchain.cmake
  106. echo "set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)" >> toolchain.cmake
  107. - name: Set up MinGW Toolchain for x86_64
  108. if: ${{ matrix.os == 'ubuntu-latest' && matrix.arch == 'x86_64' }}
  109. run: |
  110. echo "SET(CMAKE_SYSTEM_NAME Windows)" > toolchain.cmake
  111. echo "SET(CMAKE_C_COMPILER /data/mxe/usr/bin/x86_64-w64-mingw32.static.posix.seh-gcc)" >> toolchain.cmake
  112. echo "SET(CMAKE_CXX_COMPILER /data/mxe/usr/bin/x86_64-w64-mingw32.static.posix.seh-g++)" >> toolchain.cmake
  113. echo "SET(CMAKE_RC_COMPILER /data/mxe/usr/bin/x86_64-w64-mingw32.static.posix.seh-windres)" >> toolchain.cmake
  114. echo "SET(CMAKE_FIND_ROOT_PATH \${PROJECT_SOURCE_DIR}/dependencies-win-x86_64 /data/mxe/usr/x86_64-w64-mingw32.static.posix.seh/ /data/mxe/usr/lib/gcc/x86_64-w64-mingw32.static.posix.seh/5.5.0/)" >> toolchain.cmake
  115. echo "set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)" >> toolchain.cmake
  116. echo "set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ALWAYS)" >> toolchain.cmake
  117. echo "set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)" >> toolchain.cmake
  118. # Manually specify CMAKE_SYSTEM_PROCESSOR, it can only be set together with -DDCMAKE_SYSTEM_NAME
  119. - name: Configure bulid for MSVC
  120. if: ${{ matrix.os == 'windows-latest' }}
  121. run: |
  122. mkdir -Force build
  123. cd build
  124. cmake .. -G "Visual Studio 17 2022" -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_SYSTEM_PROCESSOR=${{ matrix.arch }} -A ${{ env.cmake_arch }} -DCHECK_ASSETS=OFF
  125. - name: Configure bulid for MinGW (i686 or x86_64)
  126. if: ${{ matrix.os == 'ubuntu-latest' && matrix.arch != 'armv7' && matrix.arch != 'aarch64' }}
  127. run: |
  128. mkdir -p build
  129. cd build
  130. cmake .. -DCMAKE_TOOLCHAIN_FILE=../toolchain.cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCHECK_ASSETS=OFF -DUSE_DIRECTX=ON
  131. - name: Configure bulid for MinGW (armv7 or aarch64)
  132. if: ${{ matrix.os == 'ubuntu-latest' && ( matrix.arch == 'armv7' || matrix.arch == 'aarch64' ) }}
  133. run: |
  134. mkdir -p build
  135. cd build
  136. cmake .. -DLLVM_ARCH=${{ matrix.arch }} -DLLVM_PREFIX=/llvm-mingw -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-llvm-mingw.cmake -DCHECK_ASSETS=OFF -DUSE_DIRECTX=ON
  137. - name: Build for MSVC
  138. if: ${{ matrix.os == 'windows-latest' }}
  139. working-directory: build
  140. run: |
  141. cmake --build . --config Debug
  142. - name: Build for MinGW
  143. if: ${{ matrix.os == 'ubuntu-latest' }}
  144. working-directory: build
  145. run: |
  146. make -j4
  147. cd ..
  148. mv COPYING tools
  149. - name: Upload binaries of MinGW
  150. if: ${{ matrix.os == 'ubuntu-latest' }}
  151. uses: actions/upload-artifact@v4
  152. with:
  153. name: ${{ matrix.arch }}
  154. path: build/bin/*
  155. - name: Upload stk-code/data
  156. # We only need to upload stk-code/data once
  157. if: ${{ matrix.os == 'ubuntu-latest' && matrix.arch == 'i686'}}
  158. uses: actions/upload-artifact@v4
  159. with:
  160. name: data
  161. path: data
  162. - name: Upload stk-code/tools
  163. # We only need to upload stk-code/tools once
  164. if: ${{ matrix.os == 'ubuntu-latest' && matrix.arch == 'i686'}}
  165. uses: actions/upload-artifact@v4
  166. with:
  167. name: tools
  168. path: tools
  169. - name: Remove built binaries for less cache size
  170. shell : bash
  171. run: |
  172. rm -rf build/Debug
  173. rm -rf build/bin
  174. packaging:
  175. name: Packaging STK
  176. needs: build
  177. runs-on: windows-latest
  178. steps:
  179. - name: Configure packaging name for git master branch
  180. shell : bash
  181. if: ${{ github.ref == 'refs/heads/master' }}
  182. run: |
  183. echo "release_tag=git`date +%Y%m%d`" >> $GITHUB_ENV
  184. echo "release_name=preview" >> $GITHUB_ENV
  185. - name: Configure packaging name for tag
  186. shell : bash
  187. if: ${{ startsWith(github.ref, 'refs/tags/') }}
  188. run: |
  189. echo "release_tag=`basename $GITHUB_REF`" >> $GITHUB_ENV
  190. echo "release_name=`basename $GITHUB_REF`" >> $GITHUB_ENV
  191. - name: Configure packaging name for non-releasing branch
  192. shell : bash
  193. if: ${{ (github.ref != 'refs/heads/master' && !startsWith(github.ref, 'refs/tags/')) || github.repository_owner != 'supertuxkart' }}
  194. run: |
  195. echo "release_tag=" >> $GITHUB_ENV
  196. echo "release_name=" >> $GITHUB_ENV
  197. - name: Check for prerelease
  198. shell : bash
  199. if: ${{ github.ref == 'refs/heads/master' || contains(github.ref, 'rc') || contains(github.ref, 'beta') }}
  200. run: |
  201. echo "release_pre=true" >> $GITHUB_ENV
  202. - name: Check for non-prerelease
  203. shell : bash
  204. if: ${{ github.ref != 'refs/heads/master' && !contains(github.ref, 'rc') && !contains(github.ref, 'beta') }}
  205. run: |
  206. echo "release_pre=false" >> $GITHUB_ENV
  207. - name: Show packaging name
  208. shell : bash
  209. run : |
  210. echo "${{ env.release_tag }}"
  211. echo "${{ env.release_name }}"
  212. echo "${{ env.release_pre }}"
  213. - name: Download MinGW binaries and data
  214. uses: actions/download-artifact@v4
  215. - name: Generate .pdb files
  216. if: ${{ env.release_tag != '' }}
  217. run: |
  218. C:\msys64\usr\bin\wget.exe https://github.com/rainers/cv2pdb/releases/download/v0.50/cv2pdb-0.50.zip
  219. unzip cv2pdb-0.50.zip
  220. cd i686
  221. ..\cv2pdb.exe supertuxkart.exe
  222. cd ..
  223. cd x86_64
  224. ..\cv2pdb.exe supertuxkart.exe
  225. - name: Downloading stk-assets
  226. if: ${{ env.release_tag != '' }}
  227. run: |
  228. C:\msys64\usr\bin\wget.exe https://github.com/supertuxkart/stk-assets-mobile/releases/download/git/stk-assets-full.zip
  229. mkdir stk-assets
  230. cd stk-assets
  231. unzip ..\stk-assets-full.zip
  232. - name: Move folders
  233. shell : bash
  234. if: ${{ env.release_tag != '' }}
  235. run: |
  236. mkdir SuperTuxKart-${{ env.release_tag }}-win
  237. mv stk-assets SuperTuxKart-${{ env.release_tag }}-win
  238. mkdir SuperTuxKart-${{ env.release_tag }}-win/stk-code
  239. mv data SuperTuxKart-${{ env.release_tag }}-win/stk-code
  240. mv tools/run_game.bat SuperTuxKart-${{ env.release_tag }}-win
  241. mkdir SuperTuxKart-${{ env.release_tag }}-win/stk-code/build-i686
  242. mkdir SuperTuxKart-${{ env.release_tag }}-win/stk-code/build-x86_64
  243. mkdir SuperTuxKart-${{ env.release_tag }}-win/stk-code/build-armv7
  244. mkdir SuperTuxKart-${{ env.release_tag }}-win/stk-code/build-aarch64
  245. mv i686 SuperTuxKart-${{ env.release_tag }}-win/stk-code/build-i686/bin
  246. mv x86_64 SuperTuxKart-${{ env.release_tag }}-win/stk-code/build-x86_64/bin
  247. mv armv7 SuperTuxKart-${{ env.release_tag }}-win/stk-code/build-armv7/bin
  248. mv aarch64 SuperTuxKart-${{ env.release_tag }}-win/stk-code/build-aarch64/bin
  249. # libwinpthread-1.dll is useless because we statically link
  250. rm -f SuperTuxKart-${{ env.release_tag }}-win/stk-code/build-armv7/bin/libwinpthread-1.dll
  251. rm -f SuperTuxKart-${{ env.release_tag }}-win/stk-code/build-aarch64/bin/libwinpthread-1.dll
  252. - name: Start packaging STK
  253. if: ${{ env.release_tag != '' }}
  254. run: |
  255. Compress-Archive -LiteralPath SuperTuxKart-${{ env.release_tag }}-win -DestinationPath SuperTuxKart-${{ env.release_tag }}-win.zip
  256. - name: Configure NSIS script
  257. shell : bash
  258. if: ${{ env.release_tag != '' && startsWith(github.ref, 'refs/tags/') }}
  259. run: |
  260. mv tools SuperTuxKart-${{ env.release_tag }}-win/stk-code
  261. cd SuperTuxKart-${{ env.release_tag }}-win/stk-code/tools/windows_installer
  262. for arch in i686 x86_64 aarch64
  263. do
  264. cp supertuxkart-github-actions.nsi $arch.nsi
  265. sed -i "s/define APPNAMEANDVERSION \"\"/define APPNAMEANDVERSION \"SuperTuxKart ${{ env.release_tag }}\"/g" $arch.nsi
  266. sed -i "s/define ARCH \"\"/define ARCH \"$arch\"/g" $arch.nsi
  267. sed -i "s/define VERSION \"\"/define VERSION \"${{ env.release_tag }}\"/g" $arch.nsi
  268. sed -i "s/OutFile \"\"/OutFile \"SuperTuxKart-${{ env.release_tag }}-installer-$arch.exe\"/g" $arch.nsi
  269. for filename in $(ls ../../build-$arch/bin)
  270. do
  271. file="\\\\$filename"
  272. sed -i "288a\ DELETE /REBOOTOK \"\$INSTDIR$file\"" $arch.nsi
  273. done
  274. # Print result
  275. #cat $arch.nsi
  276. done
  277. mv ../COPYING ../..
  278. - name: Run makensis.exe
  279. if: ${{ env.release_tag != '' && startsWith(github.ref, 'refs/tags/') }}
  280. run: |
  281. cd SuperTuxKart-${{ env.release_tag }}-win\stk-code\tools\windows_installer
  282. C:\msys64\usr\bin\wget.exe https://nsis.sourceforge.io/mediawiki/images/6/6c/Shelllink.zip
  283. unzip Shelllink.zip
  284. Move-Item Unicode\Plugins\ShellLink.dll .
  285. & "C:\Program Files (x86)\NSIS\makensis.exe" i686.nsi
  286. & "C:\Program Files (x86)\NSIS\makensis.exe" x86_64.nsi
  287. & "C:\Program Files (x86)\NSIS\makensis.exe" aarch64.nsi
  288. - name: Create release
  289. uses: ncipollo/release-action@v1.8.8
  290. if: ${{ env.release_tag != '' }}
  291. with:
  292. token: ${{ secrets.GITHUB_TOKEN }}
  293. artifacts: "SuperTuxKart-*.zip, SuperTuxKart-${{ env.release_tag }}-win/stk-code/tools/windows_installer/*.exe"
  294. tag: ${{ env.release_name }}
  295. omitBodyDuringUpdate: true
  296. omitNameDuringUpdate: true
  297. allowUpdates: true
  298. prerelease: ${{ env.release_pre }}