msvc.yml 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. name: Build (MSVC)
  2. on: [push, pull_request]
  3. concurrency:
  4. group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
  5. cancel-in-progress: true
  6. jobs:
  7. Build:
  8. name: ${{ matrix.platform.name }}
  9. runs-on: windows-latest
  10. strategy:
  11. fail-fast: false
  12. matrix:
  13. platform:
  14. - { name: 'Windows (x64)', vcvars: 'x64', artifact: 'SDL-VC-x64', project: 'VisualC/SDL.sln', projectflags: '/p:Platform=x64', }
  15. - { name: 'Windows (x86)', vcvars: 'x64_x86', artifact: 'SDL-VC-x86', project: 'VisualC/SDL.sln', projectflags: '/p:Platform=Win32', }
  16. - { 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', }
  17. - { 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', }
  18. - { name: 'Windows (ARM)', vcvars: 'x64_arm', artifact: 'SDL-VC-arm32', notests: true, }
  19. - { name: 'Windows (ARM64)', vcvars: 'x64_arm64', artifact: 'SDL-VC-arm64', notests: true, }
  20. - { name: 'UWP (x64)', vcvars: 'x64', artifact: 'SDL-VC-UWP', notests: true, cmake-args: '-DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION="10.0" -DSDL_TESTS=OFF',
  21. project: 'VisualC-WinRT/SDL-UWP.sln', projectflags: '/p:Platform=x64 /p:WindowsTargetPlatformVersion=10.0.17763.0', }
  22. steps:
  23. - uses: actions/checkout@v4
  24. - name: Set up ninja
  25. uses: ./.github/actions/setup-ninja
  26. - uses: ilammy/msvc-dev-cmd@v1
  27. with:
  28. arch: ${{ matrix.platform.vcvars }}
  29. - name: Set up libusb
  30. uses: ./.github/actions/setup-msvc-libusb-action
  31. if: ${{ matrix.platform.libusb-arch != '' }}
  32. id: libusb
  33. with:
  34. arch: ${{ matrix.platform.libusb-arch }}
  35. - name: Create CMake project using SDL as a subproject
  36. shell: python
  37. run: |
  38. import os
  39. import textwrap
  40. srcdir = r"${{ github.workspace }}".replace("\\", "/")
  41. builddir = f"{ srcdir }/build"
  42. os.makedirs(builddir)
  43. cmakelists_txt = textwrap.dedent(f"""\
  44. # MSVC runtime library flags are selected by an abstraction
  45. set(CMAKE_POLICY_DEFAULT_CMP0091 "NEW" CACHE STRING "MSVC runtime library flags are selected by an abstraction")
  46. # MSVC debug information format flags are selected by an abstraction
  47. set(CMAKE_POLICY_DEFAULT_CMP0141 "NEW" CACHE STRING "MSVC debug information format flags are selected by an abstraction")
  48. cmake_minimum_required(VERSION 3.0...3.25)
  49. project(sdl_user)
  50. # Always build .PDB symbol file
  51. set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "ProgramDatabase" CACHE STRING "MSVC debug information format" FORCE)
  52. set(CMAKE_EXE_LINKER_FLAGS "-DEBUG" CACHE STRING "Linker flags for executables" FORCE)
  53. set(CMAKE_SHARED_LINKER_FLAGS "-DEBUG" CACHE STRING "Linker flag for shared libraries" FORCE)
  54. if(WINDOWS_STORE) # WINDOWS_STORE is available AFTER project()
  55. # UWP only supports dynamic runtime
  56. set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL" CACHE STRING "MSVC runtime libary" FORCE)
  57. else()
  58. # Use static runtime library
  59. set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>" CACHE STRING "MSVC runtime libary" FORCE)
  60. endif()
  61. enable_testing()
  62. add_subdirectory("{ srcdir }" SDL)
  63. """)
  64. print(cmakelists_txt)
  65. with open(f"{ builddir }/CMakeLists.txt", "w") as f:
  66. f.write(cmakelists_txt)
  67. - name: Configure (CMake)
  68. run: cmake -S build -B build -GNinja `
  69. -Wdeprecated -Wdev -Werror `
  70. -DCMAKE_BUILD_TYPE=Release `
  71. -DSDL_WERROR=ON `
  72. -DSDL_SHARED=ON `
  73. -DSDL_STATIC=ON `
  74. -DSDL_TESTS=ON `
  75. -DSDL_EXAMPLES=ON \
  76. -DCMAKE_C_FLAGS="${{ matrix.platform.cppflags }}" `
  77. -DCMAKE_CXX_FLAGS="${{ matrix.platform.cppflags }}" `
  78. -DCMAKE_EXE_LINKER_FLAGS="${{ matrix.platform.ldflags }}" `
  79. -DCMAKE_SHARED_LINKER_FLAGS="${{ matrix.platform.ldflags }}" `
  80. -DCMAKE_STATIC_LINKER_FLAGS="${{ matrix.platform.ldflags }}" `
  81. -DSDL_INSTALL_TESTS=ON `
  82. -DSDL_VENDOR_INFO="Github Workflow" `
  83. -DSDL_DISABLE_INSTALL=OFF `
  84. -DSDL_DISABLE_INSTALL_CPACK=OFF `
  85. -DSDL_DISABLE_INSTALL_DOCS=OFF `
  86. -DSDLTEST_PROCDUMP=ON `
  87. -DLibUSB_ROOT="${{ steps.libusb.outputs.root }}" `
  88. ${{ matrix.platform.cmake-args }} `
  89. -DCMAKE_INSTALL_PREFIX=prefix
  90. - name: Build (CMake)
  91. id: build
  92. run: |
  93. cmake --build build/ --config Release --verbose --parallel
  94. - name: Run build-time tests
  95. id: tests
  96. if: ${{ !matrix.platform.notests }}
  97. run: |
  98. $env:SDL_TESTS_QUICK=1
  99. ctest -VV --test-dir build/ -C Release -j2
  100. - name: Install (CMake)
  101. run: |
  102. echo "SDL3_DIR=$Env:GITHUB_WORKSPACE/prefix" >> $Env:GITHUB_ENV
  103. cmake --install build/
  104. - name: Package (CPack)
  105. if: ${{ always() && steps.build.outcome == 'success' }}
  106. run: |
  107. cmake --build build/ --config Release --target package
  108. - name: Verify CMake configuration files
  109. run: |
  110. cmake -S cmake/test -B cmake_config_build -GNinja `
  111. -DCMAKE_BUILD_TYPE=Release `
  112. -DCMAKE_PREFIX_PATH=${{ env.SDL3_DIR }} `
  113. -DCMAKE_C_FLAGS="${{ matrix.platform.cppflags }}" `
  114. -DCMAKE_CXX_FLAGS="${{ matrix.platform.cppflags }}" `
  115. -DCMAKE_EXE_LINKER_FLAGS="${{ matrix.platform.ldflags }}" `
  116. -DCMAKE_SHARED_LINKER_FLAGS="${{ matrix.platform.ldflags }}" `
  117. -DCMAKE_STATIC_LINKER_FLAGS="${{ matrix.platform.ldflags }}" `
  118. ${{ matrix.platform.cmake-args }}
  119. cmake --build cmake_config_build --config Release
  120. - name: Add msbuild to PATH
  121. if: ${{ matrix.platform.project != '' }}
  122. uses: microsoft/setup-msbuild@v2
  123. - name: Build msbuild
  124. if: ${{ matrix.platform.project != '' }}
  125. run: msbuild ${{ matrix.platform.project }} /m /p:BuildInParallel=true /p:Configuration=Release ${{ matrix.platform.projectflags }}
  126. - uses: actions/upload-artifact@v4
  127. if: ${{ always() && steps.tests.outcome == 'failure' }}
  128. with:
  129. if-no-files-found: ignore
  130. name: '${{ matrix.platform.artifact }}-minidumps'
  131. path: build/**/*.dmp
  132. - uses: actions/upload-artifact@v4
  133. if: ${{ always() && steps.build.outcome == 'success' }}
  134. with:
  135. if-no-files-found: error
  136. name: ${{ matrix.platform.artifact }}
  137. path: build/dist/SDL3*