msvc.yml 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. name: Build (MSVC)
  2. on: [push, pull_request]
  3. jobs:
  4. Build:
  5. name: ${{ matrix.platform.name }}
  6. runs-on: windows-latest
  7. strategy:
  8. fail-fast: false
  9. matrix:
  10. platform:
  11. - { name: 'Windows (x64)', vcvars: 'x64', artifact: 'SDL-VC-x64', project: 'VisualC/SDL.sln', projectflags: '/p:Platform=x64', }
  12. - { name: 'Windows (x86)', vcvars: 'x64_x86', artifact: 'SDL-VC-x86', project: 'VisualC/SDL.sln', projectflags: '/p:Platform=Win32', }
  13. - { name: 'Windows static VCRT (x64)', vcvars: 'x64', artifact: 'SDL-static-crt-x64', cmake-args: '-DSDL_FORCE_STATIC_VCRT=ON', }
  14. - { name: 'Windows static VCRT (x86)', vcvars: 'x64_x86', artifact: 'SDL-static-crt-x86', cmake-args: '-DSDL_FORCE_STATIC_VCRT=ON', }
  15. - { name: 'Windows (clang-cl x64)', vcvars: 'x64', artifact: 'SDL-clang-cl-x64', cmake-args: '-DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl', cppflags: '/clang:-m64', ldflags: '/MACHINE:X64', }
  16. - { name: 'Windows (clang-cl x86)', vcvars: 'x86', artifact: 'SDL-clang-cl-x86', cmake-args: '-DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl', cppflags: '/clang:-m32', ldflags: '/MACHINE:X86', }
  17. - { name: 'Windows (ARM)', vcvars: 'x64_arm', artifact: 'SDL-VC-arm32', }
  18. - { name: 'Windows (ARM64)', vcvars: 'x64_arm64', artifact: 'SDL-VC-arm64', }
  19. - { name: 'UWP (x64)', vcvars: 'x64', artifact: 'SDL-VC-UWP', cmake-args: '-DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION="10.0" -DSDL_TESTS=OFF',
  20. project: 'VisualC-WinRT/SDL-UWP.sln', projectflags: '/p:Platform=x64 /p:WindowsTargetPlatformVersion=10.0.17763.0', }
  21. - { name: 'GDK (x64)', vcvars: 'x64', artifact: '', no-cmake: true, gdk: true,
  22. project: 'VisualC-GDK/SDL.sln', projectflags: '/p:Platform=Gaming.Desktop.x64', }
  23. steps:
  24. - uses: actions/checkout@v4
  25. - name: Set up ninja
  26. if: ${{ !matrix.platform.no-cmake }}
  27. uses: ./.github/actions/setup-ninja
  28. - uses: ilammy/msvc-dev-cmd@v1
  29. with:
  30. arch: ${{ matrix.platform.vcvars }}
  31. - name: 'Set up Windows GDK Desktop'
  32. uses: ./.github/actions/setup-gdk-desktop
  33. if: ${{ matrix.platform.gdk }}
  34. with:
  35. folder: '${{ github.workspace }}/VisualC-GDK'
  36. - name: Create CMake project using SDL as a subproject
  37. shell: python
  38. if: ${{ !matrix.platform.no-cmake }}
  39. run: |
  40. import os
  41. import textwrap
  42. srcdir = r"${{ github.workspace }}".replace("\\", "/")
  43. builddir = f"{ srcdir }/build"
  44. os.makedirs(builddir)
  45. with open(f"{ builddir }/CMakeLists.txt", "w") as f:
  46. f.write(textwrap.dedent(f"""\
  47. # Always build .PDB symbol file
  48. set(CMAKE_POLICY_DEFAULT_CMP0141 "NEW" CACHE STRING "MSVC debug information format flags are selected by an abstraction")
  49. set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "ProgramDatabase" CACHE STRING "MSVC debug information format")
  50. set(CMAKE_EXE_LINKER_FLAGS "-DEBUG" CACHE STRING "Linker flags for executables")
  51. set(CMAKE_SHARED_LINKER_FLAGS "-DEBUG" CACHE STRING "Linker flag for shared libraries")
  52. cmake_minimum_required(VERSION 3.0...3.25)
  53. project(sdl_user)
  54. enable_testing()
  55. add_subdirectory("{ srcdir }" SDL)
  56. """))
  57. - name: Configure (CMake)
  58. id: cmake-configure
  59. if: ${{ !matrix.platform.no-cmake }}
  60. run: cmake -S build -B build -GNinja `
  61. -DCMAKE_BUILD_TYPE=RelWithDebInfo `
  62. -DSDL_WERROR=ON `
  63. -DSDL_TESTS=ON `
  64. -DCMAKE_C_FLAGS="${{ matrix.platform.cppflags }}" `
  65. -DCMAKE_CXX_FLAGS="${{ matrix.platform.cppflags }}" `
  66. -DCMAKE_EXE_LINKER_FLAGS="${{ matrix.platform.ldflags }}" `
  67. -DCMAKE_SHARED_LINKER_FLAGS="${{ matrix.platform.ldflags }}" `
  68. -DCMAKE_STATIC_LINKER_FLAGS="${{ matrix.platform.ldflags }}" `
  69. -DSDL_INSTALL_TESTS=ON `
  70. -DSDL_VENDOR_INFO="Github Workflow" `
  71. -DSDL2_DISABLE_INSTALL=OFF `
  72. -DSDLTEST_PROCDUMP=ON `
  73. ${{ matrix.platform.cmake-args }} `
  74. -DCMAKE_INSTALL_PREFIX=prefix
  75. - name: Build (CMake)
  76. id: cmake-build
  77. if: ${{ steps.cmake-configure.outcome == 'success' }}
  78. run: |
  79. cmake --build build/ --config RelWithDebInfo --verbose --parallel -- -k0
  80. - name: Run build-time tests
  81. id: cmake-test
  82. if: ${{ steps.cmake-build.outcome == 'success' && !contains(matrix.platform.name, 'ARM') && !contains(matrix.platform.name, 'UWP') }}
  83. run: |
  84. $env:SDL_TESTS_QUICK=1
  85. ctest -VV --test-dir build/ -C RelWithDebInfo -j2
  86. - name: Install (CMake)
  87. id: cmake-install
  88. if: ${{ steps.cmake-build.outcome == 'success' }}
  89. run: |
  90. echo "SDL2_DIR=$Env:GITHUB_WORKSPACE/prefix" >> $Env:GITHUB_ENV
  91. cmake --install build/
  92. - name: Verify CMake configuration files
  93. if: ${{ steps.cmake-install.outcome == 'success' && !contains(matrix.platform.name, 'UWP') }}
  94. run: |
  95. cmake -S cmake/test -B cmake_config_build -GNinja `
  96. -DCMAKE_BUILD_TYPE=RelWithDebInfo `
  97. -DCMAKE_PREFIX_PATH=${{ env.SDL2_DIR }} `
  98. -DCMAKE_C_FLAGS="${{ matrix.platform.cppflags }}" `
  99. -DCMAKE_CXX_FLAGS="${{ matrix.platform.cppflags }}" `
  100. -DCMAKE_EXE_LINKER_FLAGS="${{ matrix.platform.ldflags }}" `
  101. -DCMAKE_SHARED_LINKER_FLAGS="${{ matrix.platform.ldflags }}" `
  102. -DCMAKE_STATIC_LINKER_FLAGS="${{ matrix.platform.ldflags }}" `
  103. ${{ matrix.platform.cmake-args }}
  104. cmake --build cmake_config_build --config RelWithDebInfo
  105. - name: Add msbuild to PATH
  106. if: ${{ matrix.platform.project != '' }}
  107. uses: microsoft/setup-msbuild@v2
  108. - name: Build msbuild
  109. if: ${{ matrix.platform.project != '' }}
  110. run: |
  111. msbuild ${{ matrix.platform.project }} /m /p:BuildInParallel=true /p:Configuration=Release ${{ matrix.platform.projectflags }}
  112. - uses: actions/upload-artifact@v4
  113. if: ${{ always() && steps.cmake-test.outcome == 'failure' }}
  114. with:
  115. if-no-files-found: ignore
  116. name: '${{ matrix.platform.artifact }}-minidumps'
  117. path: |
  118. build/**/*.dmp
  119. build/**/*.exe
  120. build/**/*.dll
  121. build/**/*.pdb