msvc.yml 5.6 KB

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