From e41d2ef39127108834b93aa93847fdbe4eeef004 Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Sat, 4 May 2024 14:46:40 -0500 Subject: [PATCH] Fix build warnings and errors with GDKX using Clang (#228) --- Audio/SoundCommon.cpp | 4 +- CMakePresets.json | 15 +- build/CompilerAndLinker.cmake | 2 +- build/DirectXTK12-GitHub-CMake-Dev17.yml | 2 + build/DirectXTK12-GitHub-CMake.yml | 2 + build/DirectXTK12-GitHub-GDK-Dev17.yml | 217 +++++++++++++++++++++++ build/DirectXTK12-GitHub-MinGW.yml | 2 + build/DirectXTK12-GitHub-Test.yml | 2 + build/DirectXTK12-GitHub.yml | 2 + build/DirectXTK12-OneFuzz-Coverage.yml | 4 +- build/SetupBWOI.cmd | 76 ++++++++ build/SetupBWOI.targets | 5 + 12 files changed, 322 insertions(+), 11 deletions(-) create mode 100644 build/SetupBWOI.cmd diff --git a/Audio/SoundCommon.cpp b/Audio/SoundCommon.cpp index 9b59a36..ca46259 100644 --- a/Audio/SoundCommon.cpp +++ b/Audio/SoundCommon.cpp @@ -644,12 +644,12 @@ void DirectX::CreateXMA2( throw std::invalid_argument("XMA2WAVEFORMATEX"); } - int blockAlign = (channels * XMA_OUTPUT_SAMPLE_BITS) / 8; + unsigned int blockAlign = (static_cast(channels) * XMA_OUTPUT_SAMPLE_BITS) / 8u; wfx->wFormatTag = WAVE_FORMAT_XMA2; wfx->nChannels = static_cast(channels); wfx->nSamplesPerSec = static_cast(sampleRate); - wfx->nAvgBytesPerSec = static_cast(blockAlign * sampleRate); + wfx->nAvgBytesPerSec = static_cast(blockAlign * static_cast(sampleRate)); wfx->nBlockAlign = static_cast(blockAlign); wfx->wBitsPerSample = XMA_OUTPUT_SAMPLE_BITS; wfx->cbSize = sizeof(XMA2WAVEFORMATEX) - sizeof(WAVEFORMATEX); diff --git a/CMakePresets.json b/CMakePresets.json index 6dfb160..ef35e7f 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -107,24 +107,21 @@ { "name": "Scarlett", "cacheVariables": { - "XBOX_CONSOLE_TARGET": "scarlett", - "BUILD_TESTING": false + "XBOX_CONSOLE_TARGET": "scarlett" }, "hidden": true }, { "name": "XboxOne", "cacheVariables": { - "XBOX_CONSOLE_TARGET": "xboxone", - "BUILD_TESTING": false + "XBOX_CONSOLE_TARGET": "xboxone" }, "hidden": true }, { "name": "Durango", "cacheVariables": { - "XBOX_CONSOLE_TARGET": "durango", - "BUILD_TESTING": false + "XBOX_CONSOLE_TARGET": "durango" }, "hidden": true }, @@ -286,6 +283,12 @@ { "name": "arm64-Debug-UWP-Clang" , "description": "Clang/LLVM for AArch64 (Debug) for UWP", "inherits": [ "base", "ARM64", "Debug", "Clang", "UWP" ], "environment": { "CXXFLAGS": "--target=arm64-pc-windows-msvc" } }, { "name": "arm64-Release-UWP-Clang", "description": "Clang/LLVM for AArch64 (Release) for UWP", "inherits": [ "base", "ARM64", "Release", "Clang", "UWP" ], "environment": { "CXXFLAGS": "--target=arm64-pc-windows-msvc" } }, + { "name": "x64-Debug-Scarlett-Clang" , "description": "Clang/LLVM for x64 (Debug) for Xbox Series X|S", "inherits": [ "base", "x64", "Debug", "Clang", "Scarlett" ] }, + { "name": "x64-Release-Scarlett-Clang", "description": "Clang/LLVM for x64 (Release) for Xbox Series X|S", "inherits": [ "base", "x64", "Release", "Clang", "Scarlett" ] }, + + { "name": "x64-Debug-XboxOne-Clang" , "description": "Clang/LLVM for x64 (Debug) for Xbox One", "inherits": [ "base", "x64", "Debug", "Clang", "XboxOne" ] }, + { "name": "x64-Release-XboxOne-Clang" , "description": "Clang/LLVM for x64 (Release) for Xbox One", "inherits": [ "base", "x64", "Release", "Clang", "XboxOne" ] }, + { "name": "x64-Debug-MinGW" , "description": "MinG-W64 (Debug)", "inherits": [ "base", "x64", "Debug", "GNUC", "VCPKG", "XAudio2Redist", "MinGW64" ] }, { "name": "x64-Release-MinGW", "description": "MinG-W64 (Release)", "inherits": [ "base", "x64", "Release", "GNUC", "VCPKG", "XAudio2Redist", "MinGW64" ] }, { "name": "x86-Debug-MinGW" , "description": "MinG-W32 (Debug)", "inherits": [ "base", "x86", "Debug", "GNUC", "VCPKG", "XAudio2Redist", "MinGW32" ] }, diff --git a/build/CompilerAndLinker.cmake b/build/CompilerAndLinker.cmake index 759491f..2a6e864 100644 --- a/build/CompilerAndLinker.cmake +++ b/build/CompilerAndLinker.cmake @@ -57,7 +57,7 @@ endif() #--- Target architecture switches if(XBOX_CONSOLE_TARGET STREQUAL "scarlett") list(APPEND COMPILER_SWITCHES $,/favor:AMD64 /arch:AVX2,-march=znver2>) -elseif(XBOX_CONSOLE_TARGET STREQUAL "xboxone|durago") +elseif(XBOX_CONSOLE_TARGET MATCHES "xboxone|durango") list(APPEND COMPILER_SWITCHES $,/favor:AMD64 /arch:AVX,-march=btver2>) elseif(NOT (${DIRECTX_ARCH} MATCHES "^arm")) if((${DIRECTX_ARCH} MATCHES "x86") OR (CMAKE_SIZEOF_VOID_P EQUAL 4)) diff --git a/build/DirectXTK12-GitHub-CMake-Dev17.yml b/build/DirectXTK12-GitHub-CMake-Dev17.yml index c4c9fa8..0a3ed60 100644 --- a/build/DirectXTK12-GitHub-CMake-Dev17.yml +++ b/build/DirectXTK12-GitHub-CMake-Dev17.yml @@ -21,6 +21,7 @@ trigger: - '*.md' - LICENSE - '.nuget/*' + - build/*.cmd - build/*.json - build/*.props - build/*.ps1 @@ -36,6 +37,7 @@ pr: - '*.md' - LICENSE - '.nuget/*' + - build/*.cmd - build/*.json - build/*.props - build/*.ps1 diff --git a/build/DirectXTK12-GitHub-CMake.yml b/build/DirectXTK12-GitHub-CMake.yml index 9f8110a..79591a0 100644 --- a/build/DirectXTK12-GitHub-CMake.yml +++ b/build/DirectXTK12-GitHub-CMake.yml @@ -21,6 +21,7 @@ trigger: - '*.md' - LICENSE - '.nuget/*' + - build/*.cmd - build/*.json - build/*.props - build/*.ps1 @@ -36,6 +37,7 @@ pr: - '*.md' - LICENSE - '.nuget/*' + - build/*.cmd - build/*.json - build/*.props - build/*.ps1 diff --git a/build/DirectXTK12-GitHub-GDK-Dev17.yml b/build/DirectXTK12-GitHub-GDK-Dev17.yml index 2b860f3..14286f8 100644 --- a/build/DirectXTK12-GitHub-GDK-Dev17.yml +++ b/build/DirectXTK12-GitHub-GDK-Dev17.yml @@ -20,7 +20,11 @@ pr: - main paths: include: + - CMakeList.txt - build/DirectXTK12-GitHub-GDK-Dev17.yml + - build/*.in + - build/*.cmake + - build/SetupBWOI.* resources: repositories: @@ -39,6 +43,7 @@ variables: GDK_EDITION: $(GDKEditionNumber) GDKEnableBWOI: true URL_FEED: $(ADOFeedURL) + VC_PATH: 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC' skipNugetSecurityAnalysis: true # We explicitly call this task so we don't need it to be auto-injected jobs: @@ -153,3 +158,215 @@ jobs: platform: Gaming.Xbox.Scarlett.x64 configuration: Release msbuildArchitecture: x64 + +- job: BUILD_GDK_CMAKE_SCAR + displayName: 'Microsoft Game Development Kit (GDK) using CMake (Scarlett)' + timeoutInMinutes: 120 + cancelTimeoutInMinutes: 1 + steps: + - checkout: self + clean: true + fetchTags: false + - task: NuGetToolInstaller@1 + displayName: 'Use NuGet' + inputs: + versionSpec: '6.5.x' + - task: PowerShell@2 + displayName: 'Create nuget.config with single source' + inputs: + targetType: inline + script: | + $xml = @' + + + + + + + '@ + $xml | Set-Content -Path "$(Build.SourcesDirectory)\NuGet.config" + + - task: NuGetCommand@2 + # We have to use a nuget.config to provide the feed for the 'nuget install' option. + displayName: 'NuGet set package source to ADO feed' + inputs: + command: custom + arguments: sources add -Name xboxgdk -Source $(URL_FEED) -ConfigFile $(Build.SourcesDirectory)\NuGet.config + - task: nuget-security-analysis@0 + displayName: 'Secure Supply Chain Analysis' + - task: NuGetCommand@2 + displayName: NuGet install PGDK + inputs: + command: custom + arguments: install -prerelease Microsoft.GDK.PC.$(GDK_EDITION) -ExcludeVersion -OutputDirectory $(EXTRACTED_FOLDER)\GDK + - task: NuGetCommand@2 + displayName: NuGet install GDKX + inputs: + command: custom + arguments: install -prerelease Microsoft.GDK.Xbox.$(GDK_EDITION) -ExcludeVersion -OutputDirectory $(EXTRACTED_FOLDER)\GDK + - task: CmdLine@2 + displayName: Setup BWOI for GDK command-line + inputs: + script: | + call "$(VC_PATH)\Auxiliary\Build\vcvars64.bat" + echo ##vso[task.setvariable variable=WindowsSdkVerBinPath;]%WindowsSdkVerBinPath% + echo ##vso[task.prependpath]%VSINSTALLDIR%Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja + echo ##vso[task.prependpath]%VCINSTALLDIR%Tools\Llvm\x64\bin + echo ##vso[task.prependpath]%WindowsSdkBinPath%x64 + echo ##vso[task.prependpath]%WindowsSdkVerBinPath%x64 + echo ##vso[task.prependpath]%VCToolsInstallDir%bin\HostX64\x64 + call $(Build.SourcesDirectory)\build\SetupBWOI.cmd $(EXTRACTED_FOLDER)\GDK $(GDK_EDITION) Scarlett + echo ##vso[task.setvariable variable=GameDKLatest;]%GameDKLatest% + echo ##vso[task.setvariable variable=GRDKLatest;]%GRDKLatest% + echo ##vso[task.setvariable variable=GXDKLatest;]%GXDKLatest% + echo ##vso[task.setvariable variable=INCLUDE;]%INCLUDE% + echo ##vso[task.setvariable variable=LIB;]%LIB% + echo ##vso[task.prependpath]%ADDBIN% + + failOnStderr: true + - task: CMake@1 + displayName: 'CMake (MSVC): Config Scarlett Debug' + inputs: + cwd: '$(Build.SourcesDirectory)' + cmakeArgs: --preset=x64-Debug-Scarlett + - task: CMake@1 + displayName: 'CMake (MSVC): Build Scarlett Debug' + inputs: + cwd: '$(Build.SourcesDirectory)' + cmakeArgs: --build out\build\x64-Debug-Scarlett + - task: CMake@1 + displayName: 'CMake (MSVC): Config Scarlett Release' + inputs: + cwd: '$(Build.SourcesDirectory)' + cmakeArgs: --preset=x64-Release-Scarlett + - task: CMake@1 + displayName: 'CMake (MSVC): Build Scarlett Release' + inputs: + cwd: '$(Build.SourcesDirectory)' + cmakeArgs: --build out\build\x64-Release-Scarlett + - task: CMake@1 + displayName: 'CMake (Clang): Config Scarlett Debug' + inputs: + cwd: '$(Build.SourcesDirectory)' + cmakeArgs: --preset=x64-Debug-Scarlett-Clang + - task: CMake@1 + displayName: 'CMake (Clang): Build Scarlett Debug' + inputs: + cwd: '$(Build.SourcesDirectory)' + cmakeArgs: --build out\build\x64-Debug-Scarlett-Clang + - task: CMake@1 + displayName: 'CMake (Clang): Config Scarlett Release' + inputs: + cwd: '$(Build.SourcesDirectory)' + cmakeArgs: --preset=x64-Release-Scarlett-Clang + - task: CMake@1 + displayName: 'CMake (Clang): Build Scarlett Release' + inputs: + cwd: '$(Build.SourcesDirectory)' + cmakeArgs: --build out\build\x64-Release-Scarlett-Clang + +- job: BUILD_GDK_CMAKE_XBONE + displayName: 'Microsoft Game Development Kit (GDK) using CMake (XboxOne)' + timeoutInMinutes: 120 + cancelTimeoutInMinutes: 1 + steps: + - checkout: self + clean: true + fetchTags: false + - task: NuGetToolInstaller@1 + displayName: 'Use NuGet' + inputs: + versionSpec: '6.5.x' + - task: PowerShell@2 + displayName: 'Create nuget.config with single source' + inputs: + targetType: inline + script: | + $xml = @' + + + + + + + '@ + $xml | Set-Content -Path "$(Build.SourcesDirectory)\NuGet.config" + + - task: NuGetCommand@2 + # We have to use a nuget.config to provide the feed for the 'nuget install' option. + displayName: 'NuGet set package source to ADO feed' + inputs: + command: custom + arguments: sources add -Name xboxgdk -Source $(URL_FEED) -ConfigFile $(Build.SourcesDirectory)\NuGet.config + - task: nuget-security-analysis@0 + displayName: 'Secure Supply Chain Analysis' + - task: NuGetCommand@2 + displayName: NuGet install PGDK + inputs: + command: custom + arguments: install -prerelease Microsoft.GDK.PC.$(GDK_EDITION) -ExcludeVersion -OutputDirectory $(EXTRACTED_FOLDER)\GDK + - task: NuGetCommand@2 + displayName: NuGet install GDKX + inputs: + command: custom + arguments: install -prerelease Microsoft.GDK.Xbox.$(GDK_EDITION) -ExcludeVersion -OutputDirectory $(EXTRACTED_FOLDER)\GDK + - task: CmdLine@2 + displayName: Setup BWOI for GDK command-line + inputs: + script: | + call "$(VC_PATH)\Auxiliary\Build\vcvars64.bat" + echo ##vso[task.setvariable variable=WindowsSdkVerBinPath;]%WindowsSdkVerBinPath% + echo ##vso[task.prependpath]%VSINSTALLDIR%Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja + echo ##vso[task.prependpath]%VCINSTALLDIR%Tools\Llvm\x64\bin + echo ##vso[task.prependpath]%WindowsSdkBinPath%x64 + echo ##vso[task.prependpath]%WindowsSdkVerBinPath%x64 + echo ##vso[task.prependpath]%VCToolsInstallDir%bin\HostX64\x64 + call $(Build.SourcesDirectory)\build\SetupBWOI.cmd $(EXTRACTED_FOLDER)\GDK $(GDK_EDITION) XboxOne + echo ##vso[task.setvariable variable=GameDKLatest;]%GameDKLatest% + echo ##vso[task.setvariable variable=GRDKLatest;]%GRDKLatest% + echo ##vso[task.setvariable variable=GXDKLatest;]%GXDKLatest% + echo ##vso[task.setvariable variable=INCLUDE;]%INCLUDE% + echo ##vso[task.setvariable variable=LIB;]%LIB% + echo ##vso[task.prependpath]%ADDBIN% + + failOnStderr: true + - task: CMake@1 + displayName: 'CMake (MSVC): Config XboxOne Debug' + inputs: + cwd: '$(Build.SourcesDirectory)' + cmakeArgs: --preset=x64-Debug-XboxOne + - task: CMake@1 + displayName: 'CMake (MSVC): Build XboxOne Debug' + inputs: + cwd: '$(Build.SourcesDirectory)' + cmakeArgs: --build out\build\x64-Debug-XboxOne + - task: CMake@1 + displayName: 'CMake (MSVC): Config XboxOne Release' + inputs: + cwd: '$(Build.SourcesDirectory)' + cmakeArgs: --preset=x64-Release-XboxOne + - task: CMake@1 + displayName: 'CMake (MSVC): Build XboxOne Release' + inputs: + cwd: '$(Build.SourcesDirectory)' + cmakeArgs: --build out\build\x64-Release-XboxOne + - task: CMake@1 + displayName: 'CMake (Clang): Config XboxOne Debug' + inputs: + cwd: '$(Build.SourcesDirectory)' + cmakeArgs: --preset=x64-Debug-XboxOne-Clang + - task: CMake@1 + displayName: 'CMake (Clang): Build XboxOne Debug' + inputs: + cwd: '$(Build.SourcesDirectory)' + cmakeArgs: --build out\build\x64-Debug-XboxOne-Clang + - task: CMake@1 + displayName: 'CMake (Clang): Config XboxOne Release' + inputs: + cwd: '$(Build.SourcesDirectory)' + cmakeArgs: --preset=x64-Release-XboxOne-Clang + - task: CMake@1 + displayName: 'CMake (Clang): Build XboxOne Release' + inputs: + cwd: '$(Build.SourcesDirectory)' + cmakeArgs: --build out\build\x64-Release-XboxOne-Clang diff --git a/build/DirectXTK12-GitHub-MinGW.yml b/build/DirectXTK12-GitHub-MinGW.yml index 3e8f119..df97f0b 100644 --- a/build/DirectXTK12-GitHub-MinGW.yml +++ b/build/DirectXTK12-GitHub-MinGW.yml @@ -21,6 +21,7 @@ trigger: - '*.md' - LICENSE - '.nuget/*' + - build/*.cmd - build/*.json - build/*.props - build/*.ps1 @@ -36,6 +37,7 @@ pr: - '*.md' - LICENSE - '.nuget/*' + - build/*.cmd - build/*.json - build/*.props - build/*.ps1 diff --git a/build/DirectXTK12-GitHub-Test.yml b/build/DirectXTK12-GitHub-Test.yml index 004f22b..19f77e2 100644 --- a/build/DirectXTK12-GitHub-Test.yml +++ b/build/DirectXTK12-GitHub-Test.yml @@ -23,6 +23,7 @@ trigger: - CMake* - '.nuget/*' - build/*.cmake + - build/*.cmd - build/*.in - build/*.json - build/*.props @@ -41,6 +42,7 @@ pr: - CMake* - '.nuget/*' - build/*.cmake + - build/*.cmd - build/*.in - build/*.json - build/*.props diff --git a/build/DirectXTK12-GitHub.yml b/build/DirectXTK12-GitHub.yml index 5912fac..8b30b17 100644 --- a/build/DirectXTK12-GitHub.yml +++ b/build/DirectXTK12-GitHub.yml @@ -23,6 +23,7 @@ trigger: - CMake* - '.nuget/*' - build/*.cmake + - build/*.cmd - build/*.in - build/*.json - build/*.props @@ -41,6 +42,7 @@ pr: - CMake* - '.nuget/*' - build/*.cmake + - build/*.cmd - build/*.in - build/*.json - build/*.props diff --git a/build/DirectXTK12-OneFuzz-Coverage.yml b/build/DirectXTK12-OneFuzz-Coverage.yml index 29d9ce8..88017b2 100644 --- a/build/DirectXTK12-OneFuzz-Coverage.yml +++ b/build/DirectXTK12-OneFuzz-Coverage.yml @@ -31,9 +31,9 @@ parameters: variables: - name: coverage-file value: cobertura-coverage.xml - - name: job-ID + - name: job-ID value: ${{ parameters.jobID }} - - name: build-date + - name: build-date value: ${{ parameters.buildDate }} - name: branch value: ${{ parameters.branch }} diff --git a/build/SetupBWOI.cmd b/build/SetupBWOI.cmd new file mode 100644 index 0000000..64ef0d4 --- /dev/null +++ b/build/SetupBWOI.cmd @@ -0,0 +1,76 @@ +@echo off +rem Copyright (c) Microsoft Corporation. +rem Licensed under the MIT License. + +if %1.==. goto needpackage +if %2.==. goto needgdk +if %3.==PC. goto haveparams +if %3.==XboxOne. goto haveparams +if %3.==Scarlett. goto haveparams +goto needconsole + +:haveparams +set GXDKEDITION=%2 +echo GXDKEDITION: %GXDKEDITION% + +set PCNUGET=%1\Microsoft.GDK.PC.%GXDKEDITION%\ +if NOT EXIST %PCNUGET% goto missingpcnuget + +set GRDKLatest=%PCNUGET%native\%GXDKEDITION%\GRDK\ +echo GRDKLatest: %GRDKLatest% + +if %3.==PC. goto grdkonly + +set XBOXNUGET=%1\Microsoft.gdk.xbox.%GXDKEDITION%\ +if NOT EXIST %XBOXNUGET% goto missingxboxnuget + +set GXDKLatest=%XBOXNUGET%native\%GXDKEDITION%\GXDK\ +echo GXDKLatest: %GXDKLatest% + +set GameDK=%XBOXNUGET%native\ +set GameDKLatest=%XBOXNUGET%native\%GXDKEDITION%\ + +set ADDBIN=%GXDKLatest%bin\%3;%PCNUGET%native\bin;%XBOXNUGET%native\bin +set ADDINCLUDE=%GXDKLatest%gamekit\include\%3;%GXDKLatest%gamekit\include;%GRDKLatest%gamekit\include +set ADDLIB=%GXDKLatest%gamekit\lib\amd64\%3;%GXDKLatest%gamekit\lib\amd64;%GRDKLatest%gamekit\lib\amd64 +goto continue + +:grdkonly +set GameDK=%PCNUGET%native\ +set GameDKLatest=%PCNUGET%native\%GXDKEDITION%\ + +set ADDBIN=%PCNUGET%native\bin +set ADDINCLUDE=%GRDKLatest%gamekit\include +set ADDLIB=%GRDKLatest%gamekit\lib\amd64 + +:continue +echo GameDK: %GameDK% +echo GameDKLatest: %GameDKLatest% +echo ADDBIN: %ADDBIN% +echo ADDINCLUDE: %ADDINCLUDE% +echo ADDLIB: %ADDLIB% + +set PATH=%ADDBIN%;%PATH% +set INCLUDE=%INCLUDE%;%ADDINCLUDE% +set LIB=%LIB%;%ADDLIB% +exit /b 0 + +:needpackage +echo Usage: This script requires the path to the installed NuGet packages as the first parameter. +exit /b 1 + +:needgdk +echo Usage: This script requires the GDK edition number in YYMMQQ format as the second parameter +exit /b 1 + +:needconsole +echo Usage: This script requires the target type of PC, Scarlett, or XboxOne in the third parameter +exit /b 1 + +:missingpcnuget +echo ERROR - Cannot find Microsoft.GDK.PC. installed at '%1' +exit /b 1 + +:missingxboxnuget +echo ERROR - Cannot find Microsoft.GDK.Xbox. installed at '%1' +exit /b 1 diff --git a/build/SetupBWOI.targets b/build/SetupBWOI.targets index 501a4fa..df94195 100644 --- a/build/SetupBWOI.targets +++ b/build/SetupBWOI.targets @@ -1,6 +1,11 @@ + + C:\xtracted\ $(ExtractedFolder)\