diff --git a/.github/actions/setup-gdk/action.yml b/.github/actions/setup-gdk/action.yml new file mode 100644 index 000000000..9661f5483 --- /dev/null +++ b/.github/actions/setup-gdk/action.yml @@ -0,0 +1,44 @@ +name: Setup GDK +description: Installs Microsoft.Gaming.GDK using WinGet +inputs: + gdk-version: + description: GDK version to install (e.g. 2504.1.4046) + required: true + +runs: + using: composite + steps: + - name: Restore GDK + id: cache-gdk + uses: actions/cache/restore@v4 + with: + path: | + C:/Program Files (x86)/Microsoft GDK + C:/Program Files/Microsoft Visual Studio/2022/Enterprise/MSBuild/Microsoft/VC/v170/Platforms/Gaming.Desktop.x64 + ${{ runner.temp }}/gdk.reg + key: setup-gdk-${{ inputs.gdk-version }} + + - name: Setup GDK + if: ${{ steps.cache-gdk.outputs.cache-hit == 'true' }} + shell: pwsh + run: | + reg import "$env:RUNNER_TEMP\gdk.reg" + + - name: Install GDK + if: ${{ steps.cache-gdk.outputs.cache-hit != 'true' }} + shell: pwsh + env: + GDK_VERSION: ${{ inputs.gdk-version }} + run: | + winget install --accept-source-agreements --accept-package-agreements --silent --disable-interactivity --version "$env:GDK_VERSION" Microsoft.Gaming.GDK + reg export "HKLM\SOFTWARE\WOW6432Node\Microsoft\GDK" "$env:RUNNER_TEMP\gdk.reg" + + - name: Cache GDK + if: ${{ steps.cache-gdk.outputs.cache-hit != 'true' }} + uses: actions/cache/save@v4 + with: + path: | + C:/Program Files (x86)/Microsoft GDK + C:/Program Files/Microsoft Visual Studio/2022/Enterprise/MSBuild/Microsoft/VC/v170/Platforms/Gaming.Desktop.x64 + ${{ runner.temp }}/gdk.reg + key: setup-gdk-${{ inputs.gdk-version }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d47bbf2c6..c90821550 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -146,6 +146,11 @@ jobs: ANDROID_API: 35 ANDROID_NDK: 27.2.12479018 ANDROID_ARCH: x86_64 + - name: Windows (Gaming.Desktop.x64) + os: windows-2025 + GDK_VERSION: 2504.1.4046 + CMAKE_DEFINES: -DCMAKE_TOOLCHAIN_FILE="./toolchains/xbox/grdk_toolchain.cmake" -DGDK_VERSION=250401 + VS_GENERATOR_TOOLSET: GRDK name: ${{ matrix.name }} runs-on: ${{ matrix.os }} @@ -163,6 +168,7 @@ jobs: SYSTEM_VERSION_COMPAT: ${{ matrix.SYSTEM_VERSION_COMPAT }} VS_GENERATOR_TOOLSET: ${{ matrix.VS_GENERATOR_TOOLSET }} SYSTEM_PYTHON: ${{ matrix.SYSTEM_PYTHON }} + GDK_VERSION: ${{ matrix.GDK_VERSION }} steps: - uses: actions/checkout@v4 @@ -257,6 +263,12 @@ jobs: run: bash scripts/start-android.sh timeout-minutes: 20 + - name: Setup GDK + if: ${{ runner.os == 'Windows' && env['GDK_VERSION'] }} + uses: ./.github/actions/setup-gdk + with: + gdk-version: ${{ env['GDK_VERSION'] }} + - name: Add sentry.native.test hostname if: ${{ runner.os == 'Windows' }} # The path is usually C:\Windows\System32\drivers\etc\hosts diff --git a/CMakeLists.txt b/CMakeLists.txt index 98f30edff..07b1bcab6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,10 +12,16 @@ set(SENTRY_TOOLCHAINS_DIR "${CMAKE_CURRENT_LIST_DIR}/toolchains") if ("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "Gaming.Xbox.Scarlett.x64") include("${SENTRY_TOOLCHAINS_DIR}/xbox/CMakeGDKScarlett.cmake") set(XBOX TRUE) + set(GDK TRUE) endif() if ("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "Gaming.Xbox.XboxOne.x64") include("${SENTRY_TOOLCHAINS_DIR}/xbox/CMakeGDKXboxOne.cmake") set(XBOX TRUE) + set(GDK TRUE) +endif() +if ("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "Gaming.Desktop.x64") + include("${SENTRY_TOOLCHAINS_DIR}/xbox/CMakeGDKDesktop.cmake") + set(GDK TRUE) endif() #read sentry-native version @@ -81,7 +87,7 @@ option(SENTRY_BUILD_TESTS "Build sentry-native tests" "${SENTRY_MAIN_PROJECT}") option(SENTRY_BUILD_EXAMPLES "Build sentry-native example(s)" "${SENTRY_MAIN_PROJECT}") option(SENTRY_BUILD_BENCHMARKS "Build sentry-native benchmarks" OFF) -if(NOT XBOX) +if(NOT GDK) option(SENTRY_LINK_PTHREAD "Link platform threads library" ON) if(SENTRY_LINK_PTHREAD) set(THREADS_PREFER_PTHREAD_FLAG ON) @@ -171,7 +177,7 @@ option(SENTRY_ENABLE_INSTALL "Enable sentry installation" "${SENTRY_MAIN_PROJECT if(MSVC AND CMAKE_GENERATOR_TOOLSET MATCHES "_xp$") message(WARNING "Crashpad is not supported for MSVC with XP toolset. Default backend was switched to 'breakpad'") set(SENTRY_DEFAULT_BACKEND "breakpad") -elseif(MSVC AND XBOX) +elseif(MSVC AND GDK) set(SENTRY_DEFAULT_BACKEND "breakpad") elseif((APPLE AND NOT IOS) OR WIN32 OR LINUX) set(SENTRY_DEFAULT_BACKEND "crashpad") @@ -288,7 +294,7 @@ endfunction() # ===== sentry library ===== add_library(sentry ${SENTRY_LIBRARY_TYPE} "${PROJECT_SOURCE_DIR}/vendor/mpack.c") -if (XBOX) +if (GDK) set_target_properties(sentry PROPERTIES VS_USER_PROPS gdk_build.props) endif() target_sources(sentry PRIVATE "${PROJECT_SOURCE_DIR}/include/sentry.h") @@ -383,7 +389,7 @@ if(MSVC) # using `/Wall` is not feasible, as it spews tons of warnings from windows headers # supress C5105, introduced in VS 16.8, which breaks on the Windows SDKs own `winbase.h` header - if (XBOX) + if (GDK) target_compile_options(sentry PRIVATE $) else() target_compile_options(sentry PRIVATE $) @@ -500,7 +506,7 @@ if(SENTRY_TRANSPORT_WINHTTP) endif() # handle platform threads library -if(NOT XBOX) +if(NOT GDK) if(SENTRY_LINK_PTHREAD) list(APPEND _SENTRY_PLATFORM_LIBS "Threads::Threads") endif() @@ -705,7 +711,7 @@ endif() if(SENTRY_BUILD_EXAMPLES) add_executable(sentry_example examples/example.c) - if(XBOX) + if(GDK) set_target_properties(sentry_example PROPERTIES VS_USER_PROPS gdk_build.props) endif() target_link_libraries(sentry_example PRIVATE sentry) diff --git a/include/sentry.h b/include/sentry.h index 16d678bcc..1b0c816da 100644 --- a/include/sentry.h +++ b/include/sentry.h @@ -36,8 +36,12 @@ extern "C" { /* common platform detection */ #ifdef _WIN32 # define SENTRY_PLATFORM_WINDOWS -# ifdef _GAMING_XBOX +# if defined(_GAMING_XBOX) # define SENTRY_PLATFORM_XBOX +# define SENTRY_PLATFORM_GDK +# endif +# if defined(_GAMING_DESKTOP) +# define SENTRY_PLATFORM_GDK # endif #elif defined(__APPLE__) # include diff --git a/scripts/install-zlib.ps1 b/scripts/install-zlib.ps1 index c9b543638..52e09ad1a 100644 --- a/scripts/install-zlib.ps1 +++ b/scripts/install-zlib.ps1 @@ -39,6 +39,6 @@ if ($env:TEST_MINGW -eq 1) { $NEW_CMAKE_DEFINES="CMAKE_DEFINES=${env:CMAKE_DEFINES} -DZLIB_LIBRARY=${ZLIB_BUILD_PATH}\libzlibstatic.a -DZLIB_INCLUDE_DIR=${ZLIB_BUILD_PATH} -GNinja" } Else { - $NEW_CMAKE_DEFINES="CMAKE_DEFINES=-DZLIB_LIBRARY=${ZLIB_BUILD_PATH}\Debug\zlibstaticd.lib -DZLIB_INCLUDE_DIR=${ZLIB_BUILD_PATH}" + $NEW_CMAKE_DEFINES="CMAKE_DEFINES=${env:CMAKE_DEFINES} -DZLIB_LIBRARY=${ZLIB_BUILD_PATH}\Debug\zlibstaticd.lib -DZLIB_INCLUDE_DIR=${ZLIB_BUILD_PATH}" } $NEW_CMAKE_DEFINES | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append \ No newline at end of file diff --git a/tests/cmake.py b/tests/cmake.py index 0eb89c94f..d5b6fbbd2 100644 --- a/tests/cmake.py +++ b/tests/cmake.py @@ -140,6 +140,10 @@ def cmake(cwd, targets, options=None, cflags=[]): config_cmd.append("-A x64") config_cmd.append("-T ClangCL") + if os.environ.get("VS_GENERATOR_TOOLSET") == "GRDK": + config_cmd.append("-G Visual Studio 17 2022") + config_cmd.append("-A Gaming.Desktop.x64") + for key, value in options.items(): config_cmd.append("-D{}={}".format(key, value)) if sys.platform == "win32" and os.environ.get("TEST_X86"): diff --git a/tests/unit/test_symbolizer.c b/tests/unit/test_symbolizer.c index 4e04a2393..ca0835b72 100644 --- a/tests/unit/test_symbolizer.c +++ b/tests/unit/test_symbolizer.c @@ -31,7 +31,7 @@ asserter(const sentry_frame_info_t *info, void *data) SENTRY_TEST(symbolizer) { #if defined(SENTRY_PLATFORM_NX) || defined(SENTRY_PLATFORM_XBOX) - return SKIP_TEST(); + SKIP_TEST(); #endif int called = 0; #ifdef SENTRY_PLATFORM_AIX diff --git a/tests/unit/test_unwinder.c b/tests/unit/test_unwinder.c index d99179dc9..6ceb105df 100644 --- a/tests/unit/test_unwinder.c +++ b/tests/unit/test_unwinder.c @@ -39,7 +39,7 @@ find_frame(const sentry_frame_info_t *info, void *data) SENTRY_TEST(unwinder) { #if defined(SENTRY_PLATFORM_NX) || defined(SENTRY_PLATFORM_XBOX) - return SKIP_TEST(); + SKIP_TEST(); #endif void *backtrace1[MAX_FRAMES] = { 0 }; size_t frame_count1 = invoke_unwinder(backtrace1); diff --git a/toolchains/xbox/CMakeGDKDesktop.cmake b/toolchains/xbox/CMakeGDKDesktop.cmake new file mode 100644 index 000000000..ee9cd14a7 --- /dev/null +++ b/toolchains/xbox/CMakeGDKDesktop.cmake @@ -0,0 +1,40 @@ +# Adapted by Sentry from: +# https://github.com/microsoft/Xbox-GDK-Samples/blob/710f4bd9095d3796d07505249a7b383857e8a23f/Samples/Tools/CMakeExample/CMake/CMakeGDKDesktop.cmake +# +# CMakeGDKDesktop.cmake : CMake definitions for Microsoft GDK targeting PC +# +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +mark_as_advanced(CMAKE_TOOLCHAIN_FILE) + +if(_GDK_DESKTOP_TOOLCHAIN_) + return() +endif() + +#--- Microsoft Game Development Kit + +include("${CMAKE_CURRENT_LIST_DIR}/DetectGDK.cmake") + +set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES GDK_VERSION BUILD_USING_BWOI) + +set(CMAKE_SYSTEM_NAME WINDOWS) +set(CMAKE_SYSTEM_VERSION 10.0) + +#--- GameRuntime and Extension Libraries +include(${CMAKE_CURRENT_LIST_DIR}/GDK-targets.cmake) + +message("Microsoft GDK = ${Console_SdkRoot}/${GDK_VERSION}") + +#--- Tools +find_program(MAKEPKG_TOOL makepkg.exe + REQUIRED NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH NO_DEFAULT_PATH + HINTS "${Console_SdkRoot}/bin") + +message("MGC Tool = ${MAKEPKG_TOOL}") + +find_program(DIRECTX_DXC_TOOL dxc.exe) + +message("DXC Compiler = ${DIRECTX_DXC_TOOL}") + +set(_GDK_DESKTOP_TOOLCHAIN_ ON) diff --git a/toolchains/xbox/GDK-targets.cmake b/toolchains/xbox/GDK-targets.cmake index 6a23ddfaf..9d6f79866 100644 --- a/toolchains/xbox/GDK-targets.cmake +++ b/toolchains/xbox/GDK-targets.cmake @@ -36,7 +36,7 @@ else() endif() if(NOT EXISTS "${Console_SdkRoot}/${GDK_VERSION}") - message(FATAL_ERROR "ERROR: Cannot locate Microsoft Game Development Kit (GDK) - ${GDK_VERSION}") + message(FATAL_ERROR "ERROR: Cannot locate Microsoft Game Development Kit (GDK) - ${GDK_VERSION} in ${Console_SdkRoot}") endif() #--- GameRuntime Library (for Xbox these are included in the Console_Libs variable) diff --git a/toolchains/xbox/grdk_toolchain.cmake b/toolchains/xbox/grdk_toolchain.cmake new file mode 100644 index 000000000..ec31ae291 --- /dev/null +++ b/toolchains/xbox/grdk_toolchain.cmake @@ -0,0 +1,52 @@ +# Adapted by Sentry from: +# https://github.com/microsoft/Xbox-GDK-Samples/blob/710f4bd9095d3796d07505249a7b383857e8a23f/Samples/Tools/CMakeGDKExample/grdk_toolchain.cmake +# +# grdk_toolchain.cmake : CMake Toolchain file for Gaming.Desktop.x64 +# +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +mark_as_advanced(CMAKE_TOOLCHAIN_FILE) + +if(_GRDK_TOOLCHAIN_) + return() +endif() + +# Microsoft Game Development Kit + +include("${CMAKE_CURRENT_LIST_DIR}/DetectGDK.cmake") + +set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES GDK_VERSION) + +set(CMAKE_SYSTEM_NAME WINDOWS) +set(CMAKE_SYSTEM_VERSION 10.0) + +set(CMAKE_GENERATOR_PLATFORM "Gaming.Desktop.x64" CACHE STRING "" FORCE) +set(CMAKE_VS_PLATFORM_NAME "Gaming.Desktop.x64" CACHE STRING "" FORCE) + +# Ensure our platform toolset is x64 +set(CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE "x64" CACHE STRING "" FORCE) + +# Let the GDK MSBuild rules decide the WindowsTargetPlatformVersion +set(CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION "" CACHE STRING "" FORCE) + +if(${CMAKE_VERSION} GREATER_EQUAL "3.30") + set(CMAKE_VS_USE_DEBUG_LIBRARIES "$" CACHE STRING "" FORCE) +endif() + +# Sets platform defines +set(CMAKE_CXX_FLAGS_INIT "$ENV{CFLAGS} ${CMAKE_CXX_FLAGS_INIT} -D_GAMING_DESKTOP -DWINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP" CACHE STRING "" FORCE) + +# Add GDK props file +file(GENERATE OUTPUT gdk_build.props INPUT ${CMAKE_CURRENT_LIST_DIR}/gdk_build.props) + +# Find DXC compiler +if(NOT GDK_DXCTool) + set(GDK_DXCTool "dxc.exe") + mark_as_advanced(GDK_DXCTool) +endif() + +# The MicrosoftGame.Config file needs to be in the directory with the project to enable deploy for Gaming.Desktop.x64 +#file(GENERATE OUTPUT MicrosoftGame.Config INPUT ${CMAKE_CURRENT_LIST_DIR}/MicrosoftGameConfig.mgc) + +set(_GRDK_TOOLCHAIN_ ON)