Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDL2] MSVC + UWP + ARM64EC related fixes #10312

Merged
merged 4 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions .github/actions/setup-ninja/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: 'Setup ninja'
description: 'Setup ninja'
inputs:
version:
description: 'Ninja version'
default: '1.12.1'
runs:
using: 'composite'
steps:
- name: 'Calculate variables'
id: calc
shell: sh
run: |
case "${{ runner.os }}-${{ runner.arch }}" in
"Linux-X86" | "Linux-X64")
archive="ninja-linux.zip"
;;
"Linux-ARM64")
archive="ninja-linux-aarch64.zip"
;;
"macOS-X86" | "macOS-X64" | "macOS-ARM64")
archive="ninja-mac.zip"
;;
"Windows-X86" | "Windows-X64")
archive="ninja-win.zip"
;;
"Windows-ARM64")
archive="ninja-winarm64.zip"
;;
*)
echo "Unsupported ${{ runner.os }}-${{ runner.arch }}"
exit 1;
;;
esac
echo "archive=${archive}" >> ${GITHUB_OUTPUT}
echo "cache-key=${archive}-${{ inputs.version }}-${{ runner.os }}-${{ runner.arch }}" >> ${GITHUB_OUTPUT}
- name: 'Restore cached ${{ steps.calc.outputs.archive }}'
id: cache-restore
uses: actions/cache/restore@main
with:
path: '${{ runner.temp }}/${{ steps.calc.outputs.archive }}'
key: ${{ steps.calc.outputs.cache-key }}
- name: 'Download ninja ${{ inputs.version }} for ${{ runner.os }} (${{ runner.arch }})'
if: ${{ !steps.cache-restore.outputs.cache-hit }}
shell: pwsh
run: |
Invoke-WebRequest "https://github.com/ninja-build/ninja/releases/download/v${{ inputs.version }}/${{ steps.calc.outputs.archive }}" -OutFile "${{ runner.temp }}/${{ steps.calc.outputs.archive }}"
- name: 'Cache ${{ steps.calc.outputs.archive }}'
if: ${{ !steps.cache-restore.outputs.cache-hit }}
uses: actions/cache/save@main
with:
path: '${{ runner.temp }}/${{ steps.calc.outputs.archive }}'
key: ${{ steps.calc.outputs.cache-key }}
- name: 'Extract libusb'
shell: pwsh
run: |
7z "-o${{ runner.temp }}/ninja-${{ inputs.version }}-${{ runner.arch }}" x "${{ runner.temp }}/${{ steps.calc.outputs.archive }}"
- name: 'Set output variables'
id: final
shell: pwsh
run: |
echo "${{ runner.temp }}/ninja-${{ inputs.version }}-${{ runner.arch }}" >> $env:GITHUB_PATH
54 changes: 36 additions & 18 deletions .github/workflows/msvc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,24 @@ jobs:
fail-fast: false
matrix:
platform:
- { name: Windows (x64), flags: -A x64, project: VisualC/SDL.sln, projectflags: '/p:Platform=x64', artifact: 'SDL-VC-x64' }
- { name: Windows (x86), flags: -A Win32, project: VisualC/SDL.sln, projectflags: '/p:Platform=Win32', artifact: 'SDL-VC-x86' }
- { name: Windows static VCRT (x64), flags: -A x64 -DSDL_FORCE_STATIC_VCRT=ON, artifact: 'SDL-static-crt-x64' }
- { name: Windows static VCRT (x86), flags: -A Win32 -DSDL_FORCE_STATIC_VCRT=ON, artifact: 'SDL-static-crt-x86' }
- { name: Windows (clang-cl x64), flags: -T ClangCL -A x64, artifact: 'SDL-clang-cl-x64' }
- { name: Windows (clang-cl x86), flags: -T ClangCL -A Win32, artifact: 'SDL-clang-cl-x86' }
- { name: Windows (ARM), flags: -A ARM, artifact: 'SDL-VC-arm32' }
- { name: Windows (ARM64), flags: -A ARM64, artifact: 'SDL-VC-arm64' }
- { name: UWP (x64), flags: -A x64 -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION="10.0" -DSDL_TESTS=OFF, nowerror: true,
project: VisualC-WinRT/SDL-UWP.sln, projectflags: '/p:Platform=x64 /p:WindowsTargetPlatformVersion=10.0.17763.0', artifact: 'SDL-VC-UWP' }
- { name: 'Windows (x64)', vcvars: 'x64', artifact: 'SDL-VC-x64', project: 'VisualC/SDL.sln', projectflags: '/p:Platform=x64', }
- { name: 'Windows (x86)', vcvars: 'x64_x86', artifact: 'SDL-VC-x86', project: 'VisualC/SDL.sln', projectflags: '/p:Platform=Win32', }
- { name: 'Windows static VCRT (x64)', vcvars: 'x64', artifact: 'SDL-static-crt-x64', cmake-args: '-DSDL_FORCE_STATIC_VCRT=ON', }
- { name: 'Windows static VCRT (x86)', vcvars: 'x64_x86', artifact: 'SDL-static-crt-x86', cmake-args: '-DSDL_FORCE_STATIC_VCRT=ON', }
- { 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', }
- { 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', }
- { name: 'Windows (ARM)', vcvars: 'x64_arm', artifact: 'SDL-VC-arm32', }
- { name: 'Windows (ARM64)', vcvars: 'x64_arm64', artifact: 'SDL-VC-arm64', }
- { name: 'UWP (x64)', vcvars: 'x64', artifact: 'SDL-VC-UWP', cmake-args: '-DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION="10.0" -DSDL_TESTS=OFF',
project: 'VisualC-WinRT/SDL-UWP.sln', projectflags: '/p:Platform=x64 /p:WindowsTargetPlatformVersion=10.0.17763.0', }

steps:
- uses: actions/checkout@v4
- name: Set up ninja
uses: ./.github/actions/setup-ninja
- uses: ilammy/msvc-dev-cmd@v1
with:
arch: ${{ matrix.platform.vcvars }}
- name: Create CMake project using SDL as a subproject
shell: python
run: |
Expand All @@ -45,20 +50,27 @@ jobs:
add_subdirectory("{ srcdir }" SDL)
"""))
- name: Configure (CMake)
run: cmake -S build -B build `
-DSDL_WERROR=${{ !matrix.platform.nowerror }} `
run: cmake -S build -B build -GNinja `
-DCMAKE_BUILD_TYPE=Release `
-DSDL_WERROR=ON `
-DSDL_TESTS=ON `
-DCMAKE_C_FLAGS="${{ matrix.platform.cppflags }}" `
-DCMAKE_CXX_FLAGS="${{ matrix.platform.cppflags }}" `
-DCMAKE_EXE_LINKER_FLAGS="${{ matrix.platform.ldflags }}" `
-DCMAKE_SHARED_LINKER_FLAGS="${{ matrix.platform.ldflags }}" `
-DCMAKE_STATIC_LINKER_FLAGS="${{ matrix.platform.ldflags }}" `
-DSDL_INSTALL_TESTS=ON `
-DSDL_VENDOR_INFO="Github Workflow" `
-DSDL2_DISABLE_INSTALL=OFF `
-DSDLTEST_PROCDUMP=ON `
${{ matrix.platform.flags }} `
${{ matrix.platform.cmake-args }} `
-DCMAKE_INSTALL_PREFIX=prefix
- name: Build (CMake)
run: cmake --build build/ --config Release --parallel
run: |
cmake --build build/ --config Release --verbose --parallel -- -k0
- name: Run build-time tests
id: tests
if: "! contains(matrix.platform.name, 'ARM')"
if: ${{ !contains(matrix.platform.name, 'ARM') && !contains(matrix.platform.name, 'UWP') }}
run: |
$env:SDL_TESTS_QUICK=1
ctest -VV --test-dir build/ -C Release -j2
Expand All @@ -67,11 +79,17 @@ jobs:
echo "SDL2_DIR=$Env:GITHUB_WORKSPACE/prefix" >> $Env:GITHUB_ENV
cmake --install build/
- name: Verify CMake configuration files
if: ${{ !contains(matrix.platform.name, 'UWP') }} # FIXME: cmake/test/CMakeLists.txt should support UWP
if: ${{ !contains(matrix.platform.name, 'UWP') }}
run: |
cmake -S cmake/test -B cmake_config_build `
cmake -S cmake/test -B cmake_config_build -GNinja `
-DCMAKE_BUILD_TYPE=Release `
-DCMAKE_PREFIX_PATH=${{ env.SDL2_DIR }} `
${{ matrix.platform.flags }}
-DCMAKE_C_FLAGS="${{ matrix.platform.cppflags }}" `
-DCMAKE_CXX_FLAGS="${{ matrix.platform.cppflags }}" `
-DCMAKE_EXE_LINKER_FLAGS="${{ matrix.platform.ldflags }}" `
-DCMAKE_SHARED_LINKER_FLAGS="${{ matrix.platform.ldflags }}" `
-DCMAKE_STATIC_LINKER_FLAGS="${{ matrix.platform.ldflags }}" `
${{ matrix.platform.cmake-args }}
cmake --build cmake_config_build --config Release
- name: Add msbuild to PATH
if: ${{ matrix.platform.project != '' }}
Expand Down
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ set(PKGCONFIG_DEPENDS)
add_library(sdl-build-options INTERFACE)

if(WINDOWS_STORE)
target_compile_definitions(sdl-build-options INTERFACE "-DSDL_BUILDING_WINRT=1")
target_compile_options(sdl-build-options INTERFACE "-ZW")
target_compile_definitions(sdl-build-options INTERFACE "-DSDL_BUILDING_WINRT=1" "WINAPI_FAMILY=WINAPI_FAMILY_APP")
target_compile_options(sdl-build-options INTERFACE "$<$<COMPILE_LANGUAGE:CXX>:-ZW>" "$<$<COMPILE_LANGUAGE:CXX>:-EHsc>")
endif()

# CMake 3.0 expands the "if(${A})" in "set(OFF 1);set(A OFF);if(${A})" to "if(1)"
Expand Down Expand Up @@ -141,6 +141,7 @@ check_cpu_architecture(x86 SDL_CPU_X86)
check_cpu_architecture(x64 SDL_CPU_X64)
check_cpu_architecture(arm32 SDL_CPU_ARM32)
check_cpu_architecture(arm64 SDL_CPU_ARM64)
check_cpu_architecture(arm64ec SDL_CPU_ARM64EC)
check_cpu_architecture(loongarch64 SDL_CPU_LOONGARCH64)

# Check for 64 or 32 bit
Expand Down Expand Up @@ -239,7 +240,7 @@ if(USE_GCC OR USE_CLANG OR USE_INTELCC OR USE_QCC)
endif()

# Default option knobs
if(UNIX OR MINGW OR MSYS OR (USE_CLANG AND NOT WINDOWS) OR VITA OR PSP OR PS2 OR N3DS)
if(UNIX OR MINGW OR MSYS OR (USE_CLANG AND NOT WINDOWS) OR VITA OR PSP OR PS2 OR N3DS OR SDL_CPU_ARM64EC)
set(OPT_DEF_LIBC ON)
endif()
if(WINDOWS OR DARWIN OR MACOSX OR IOS OR TVOS)
Expand Down
4 changes: 3 additions & 1 deletion cmake/CheckCPUArchitecture.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ function(check_cpu_architecture ARCH VARIABLE)
if(ARCH STREQUAL "x86")
_internal_check_cpu_architecture("defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) ||defined( __i386) || defined(_M_IX86)" x86 ${VARIABLE})
elseif(ARCH STREQUAL "x64")
_internal_check_cpu_architecture("defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64)" x64 ${VARIABLE})
_internal_check_cpu_architecture("(defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64)) && !defined(_M_ARM64EC)" x64 ${VARIABLE})
elseif(ARCH STREQUAL "arm32")
_internal_check_cpu_architecture("defined(__arm__) || defined(_M_ARM)" arm32 ${VARIABLE})
elseif(ARCH STREQUAL "arm64")
_internal_check_cpu_architecture("defined(__aarch64__) || defined(_M_ARM64)" arm64 ${VARIABLE})
elseif(ARCH STREQUAL "arm64ec")
_internal_check_cpu_architecture("defined(_M_ARM64EC)" arm64ec ${VARIABLE})
elseif(ARCH STREQUAL "loongarch64")
_internal_check_cpu_architecture("defined(__loongarch64)" loongarch64 ${VARIABLE})
else()
Expand Down
2 changes: 1 addition & 1 deletion src/audio/wasapi/SDL_wasapi_winrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ SDL_WasapiDeviceEventHandler::~SDL_WasapiDeviceEventHandler()
void SDL_WasapiDeviceEventHandler::OnDeviceAdded(DeviceWatcher ^ sender, DeviceInformation ^ info)
{
SDL_assert(sender == this->watcher);
char *utf8dev = WIN_StringToUTF8(info->Name->Data());
char *utf8dev = WIN_StringToUTF8W(info->Name->Data());
if (utf8dev) {
WAVEFORMATEXTENSIBLE fmt;
Platform::Object ^ obj = info->Properties->Lookup(SDL_PKEY_AudioEngine_DeviceFormat);
Expand Down
2 changes: 1 addition & 1 deletion src/core/windows/SDL_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ WASAPI doesn't need this. This is just for DirectSound/WinMM.
char *WIN_LookupAudioDeviceName(const WCHAR *name, const GUID *guid)
{
#if defined(__WINRT__) || defined(__XBOXONE__) || defined(__XBOXSERIES__)
return WIN_StringToUTF8(name); /* No registry access on WinRT/UWP and Xbox, go with what we've got. */
return WIN_StringToUTF8W(name); /* No registry access on WinRT/UWP and Xbox, go with what we've got. */
#else
static const GUID nullguid = { 0 };
const unsigned char *ptr;
Expand Down
8 changes: 4 additions & 4 deletions src/filesystem/winrt/SDL_sysfilesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType)
return NULL;
}

char *utf8Path = WIN_StringToUTF8(ucs2Path);
char *utf8Path = WIN_StringToUTF8W(ucs2Path);
utf8Paths[pathType] = utf8Path;
SDL_free(utf8Path);
return utf8Paths[pathType].c_str();
Expand Down Expand Up @@ -181,13 +181,13 @@ SDL_GetPrefPath(const char *org, const char *app)
}
SDL_wcslcpy(path, srcPath, SDL_arraysize(path));

worg = WIN_UTF8ToString(org);
worg = WIN_UTF8ToStringW(org);
if (!worg) {
SDL_OutOfMemory();
return NULL;
}

wapp = WIN_UTF8ToString(app);
wapp = WIN_UTF8ToStringW(app);
if (!wapp) {
SDL_free(worg);
SDL_OutOfMemory();
Expand Down Expand Up @@ -232,7 +232,7 @@ SDL_GetPrefPath(const char *org, const char *app)

SDL_wcslcat(path, L"\\", new_wpath_len + 1);

retval = WIN_StringToUTF8(path);
retval = WIN_StringToUTF8W(path);

return retval;
}
Expand Down
10 changes: 5 additions & 5 deletions src/loadso/windows/SDL_sysloadso.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@
void *SDL_LoadObject(const char *sofile)
{
void *handle;
LPTSTR tstr;
LPWSTR wstr;

if (!sofile) {
SDL_InvalidParamError("sofile");
return NULL;
}
tstr = WIN_UTF8ToString(sofile);
wstr = WIN_UTF8ToStringW(sofile);
#ifdef __WINRT__
/* WinRT only publicly supports LoadPackagedLibrary() for loading .dll
files. LoadLibrary() is a private API, and not available for apps
(that can be published to MS' Windows Store.)
*/
handle = (void *)LoadPackagedLibrary(tstr, 0);
handle = (void *)LoadPackagedLibrary(wstr, 0);
#else
handle = (void *)LoadLibrary(tstr);
handle = (void *)LoadLibraryW(wstr);
#endif
SDL_free(tstr);
SDL_free(wstr);

/* Generate an error message if all loads failed */
if (!handle) {
Expand Down
2 changes: 1 addition & 1 deletion src/video/winrt/SDL_winrtmessagebox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ using namespace Windows::Foundation;
using namespace Windows::UI::Popups;

static String ^ WINRT_UTF8ToPlatformString(const char *str) {
wchar_t *wstr = WIN_UTF8ToString(str);
wchar_t *wstr = WIN_UTF8ToStringW(str);
String ^ rtstr = ref new String(wstr);
SDL_free(wstr);
return rtstr;
Expand Down
2 changes: 1 addition & 1 deletion src/video/winrt/SDL_winrtvideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ static int WINRT_AddDisplaysForOutput(_THIS, IDXGIAdapter1 *dxgiAdapter1, int ou
WIN_SetErrorFromHRESULT(__FUNCTION__ ", IDXGIOutput::FindClosestMatchingMode failed", hr);
goto done;
} else {
displayName = WIN_StringToUTF8(dxgiOutputDesc.DeviceName);
displayName = WIN_StringToUTF8W(dxgiOutputDesc.DeviceName);
display.name = displayName;
WINRT_DXGIModeToSDLDisplayMode(&closestMatch, &display.desktop_mode);
display.current_mode = display.desktop_mode;
Expand Down
Loading