Fix UWP builds on MSVC2017

This commit is contained in:
Michael Lelli 2020-01-07 17:59:56 -06:00
parent be9cc7e96f
commit 7baa7a6ea7
4 changed files with 97 additions and 8 deletions

1
.gitignore vendored
View File

@ -13,6 +13,7 @@ sdl/build_sdl
sdl/build_sdl2 sdl/build_sdl2
/libretro/msvc/msvc-2017/msvc-2017.vcxproj.user /libretro/msvc/msvc-2017/msvc-2017.vcxproj.user
genesis_plus_gx_libretro.*
*.o *.o
*.a *.a

View File

@ -425,13 +425,14 @@ else ifneq (,$(findstring windows_msvc2017,$(platform)))
HAVE_CDROM = 1 HAVE_CDROM = 1
else ifneq (,$(findstring uwp,$(PlatformSuffix))) else ifneq (,$(findstring uwp,$(PlatformSuffix)))
WinPartition = uwp WinPartition = uwp
MSVC2017CompileFlags = -DWINAPI_FAMILY=WINAPI_FAMILY_APP -D_WINDLL -D_UNICODE -DUNICODE -D__WRL_NO_DEFAULT_LIB__ -EHsc -FS MSVC2017CompileFlags = -DWINAPI_FAMILY=WINAPI_FAMILY_APP -D_WINDLL -D_UNICODE -DUNICODE -D__WRL_NO_DEFAULT_LIB__ -FS
LDFLAGS += -APPCONTAINER -NXCOMPAT -DYNAMICBASE -MANIFEST:NO -LTCG -OPT:REF -SUBSYSTEM:CONSOLE -MANIFESTUAC:NO -OPT:ICF -ERRORREPORT:PROMPT -NOLOGO -TLBID:1 -DEBUG:FULL -WINMD:NO MSVC2017CxxFlags = -EHsc -ZW
LDFLAGS += -APPCONTAINER -NXCOMPAT -DYNAMICBASE -MANIFEST:NO -LTCG -OPT:REF -SUBSYSTEM:CONSOLE -OPT:ICF -ERRORREPORT:PROMPT -NOLOGO -TLBID:1 -DEBUG:FULL -WINMD:NO /nodefaultlib:vccorlib /nodefaultlib:msvcrt vccorlib.lib msvcrt.lib
LIBS := WindowsApp.lib LIBS := WindowsApp.lib
endif endif
CFLAGS += $(MSVC2017CompileFlags) CFLAGS += $(MSVC2017CompileFlags)
CXXFLAGS += $(MSVC2017CompileFlags) CXXFLAGS += $(MSVC2017CompileFlags) $(MSVC2017CxxFlags)
TargetArchMoniker = $(subst $(WinPartition)_,,$(PlatformSuffix)) TargetArchMoniker = $(subst $(WinPartition)_,,$(PlatformSuffix))
@ -441,7 +442,7 @@ else ifneq (,$(findstring windows_msvc2017,$(platform)))
HAVE_SYS_PARAM = 0 HAVE_SYS_PARAM = 0
reg_query = $(call filter_out2,$(subst $2,,$(shell reg query "$2" -v "$1" 2>nul))) reg_query = $(call filter_out2,$(subst $2,,$(shell reg query "$2" -v "$1")))
fix_path = $(subst $(SPACE),\ ,$(subst \,/,$1)) fix_path = $(subst $(SPACE),\ ,$(subst \,/,$1))
ProgramFiles86w := $(shell cmd //c "echo %PROGRAMFILES(x86)%") ProgramFiles86w := $(shell cmd //c "echo %PROGRAMFILES(x86)%")
@ -453,7 +454,7 @@ else ifneq (,$(findstring windows_msvc2017,$(platform)))
WindowsSdkDir ?= $(call reg_query,InstallationFolder,HKEY_CURRENT_USER\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0) WindowsSdkDir ?= $(call reg_query,InstallationFolder,HKEY_CURRENT_USER\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0)
WindowsSdkDir := $(WindowsSdkDir) WindowsSdkDir := $(WindowsSdkDir)
WindowsSDKVersion ?= $(firstword $(foreach folder,$(subst $(subst \,/,$(WindowsSdkDir)Include/),,$(wildcard $(call fix_path,$(WindowsSdkDir)Include\*))),$(if $(wildcard $(call fix_path,$(WindowsSdkDir)Include/$(folder)/um/Windows.h)),$(folder),)))$(BACKSLASH) WindowsSDKVersion ?= $(firstword $(foreach folder,$(subst $(subst \,/,$(WindowsSdkDir)Include/),,$(wildcard $(call fix_path,$(WindowsSdkDir)Include\*))),$(if $(wildcard $(call fix_path,$(WindowsSdkDir)Include/$(folder)/um/Windows.h)),$(folder),)))
WindowsSDKVersion := $(WindowsSDKVersion) WindowsSDKVersion := $(WindowsSDKVersion)
VsInstallBuildTools = $(ProgramFiles86)/Microsoft Visual Studio/2017/BuildTools VsInstallBuildTools = $(ProgramFiles86)/Microsoft Visual Studio/2017/BuildTools
@ -475,12 +476,16 @@ else ifneq (,$(findstring windows_msvc2017,$(platform)))
VcCompilerToolsVer := $(shell cat "$(VsInstallRoot)/VC/Auxiliary/Build/Microsoft.VCToolsVersion.default.txt" | grep -o '[0-9\.]*') VcCompilerToolsVer := $(shell cat "$(VsInstallRoot)/VC/Auxiliary/Build/Microsoft.VCToolsVersion.default.txt" | grep -o '[0-9\.]*')
VcCompilerToolsDir := $(VsInstallRoot)/VC/Tools/MSVC/$(VcCompilerToolsVer) VcCompilerToolsDir := $(VsInstallRoot)/VC/Tools/MSVC/$(VcCompilerToolsVer)
# platform.winmd seems to be platform independent but only lives in the x86 lib directory
VcCompilerToolsStoreReferencesDir := $(shell IFS=$$'\n'; cygpath -w "$(VcCompilerToolsDir)/lib/x86/store/references")
WindowsSDKSharedIncludeDir := $(shell cygpath -w "$(WindowsSdkDir)\Include\$(WindowsSDKVersion)\shared") WindowsSDKSharedIncludeDir := $(shell cygpath -w "$(WindowsSdkDir)\Include\$(WindowsSDKVersion)\shared")
WindowsSDKUCRTIncludeDir := $(shell cygpath -w "$(WindowsSdkDir)\Include\$(WindowsSDKVersion)\ucrt") WindowsSDKUCRTIncludeDir := $(shell cygpath -w "$(WindowsSdkDir)\Include\$(WindowsSDKVersion)\ucrt")
WindowsSDKUMIncludeDir := $(shell cygpath -w "$(WindowsSdkDir)\Include\$(WindowsSDKVersion)\um") WindowsSDKUMIncludeDir := $(shell cygpath -w "$(WindowsSdkDir)\Include\$(WindowsSDKVersion)\um")
WindowsSDKWinRTIncludeDir := $(shell cygpath -w "$(WindowsSdkDir)\Include\$(WindowsSDKVersion)\winrt")
WindowsSDKUCRTLibDir := $(shell cygpath -w "$(WindowsSdkDir)\Lib\$(WindowsSDKVersion)\ucrt\$(TargetArchMoniker)") WindowsSDKUCRTLibDir := $(shell cygpath -w "$(WindowsSdkDir)\Lib\$(WindowsSDKVersion)\ucrt\$(TargetArchMoniker)")
WindowsSDKUMLibDir := $(shell cygpath -w "$(WindowsSdkDir)\Lib\$(WindowsSDKVersion)\um\$(TargetArchMoniker)") WindowsSDKUMLibDir := $(shell cygpath -w "$(WindowsSdkDir)\Lib\$(WindowsSDKVersion)\um\$(TargetArchMoniker)")
WindowsSDKUnionMetadataDir := $(shell cygpath -w "$(WindowsSdkDir)\UnionMetadata\$(WindowsSDKVersion)")
# For some reason the HostX86 compiler doesn't like compiling for x64 # For some reason the HostX86 compiler doesn't like compiling for x64
# ("no such file" opening a shared library), and vice-versa. # ("no such file" opening a shared library), and vice-versa.
@ -500,8 +505,9 @@ else ifneq (,$(findstring windows_msvc2017,$(platform)))
LIB := $(shell IFS=$$'\n'; cygpath -w "$(LIB)/store") LIB := $(shell IFS=$$'\n'; cygpath -w "$(LIB)/store")
endif endif
export INCLUDE := $(INCLUDE);$(WindowsSDKSharedIncludeDir);$(WindowsSDKUCRTIncludeDir);$(WindowsSDKUMIncludeDir) export INCLUDE := $(INCLUDE);$(WindowsSDKSharedIncludeDir);$(WindowsSDKUCRTIncludeDir);$(WindowsSDKUMIncludeDir);$(WindowsSDKWinRTIncludeDir)
export LIB := $(LIB);$(WindowsSDKUCRTLibDir);$(WindowsSDKUMLibDir) export LIB := $(LIB);$(WindowsSDKUCRTLibDir);$(WindowsSDKUMLibDir)
export LIBPATH := $(LIBPATH);$(VcCompilerToolsStoreReferencesDir);$(WindowsSDKUnionMetadataDir)
TARGET := $(TARGET_NAME)_libretro.dll TARGET := $(TARGET_NAME)_libretro.dll
PSS_STYLE :=2 PSS_STYLE :=2
LDFLAGS += -DLL LDFLAGS += -DLL
@ -596,7 +602,6 @@ else
endif endif
LDFLAGS += $(LIBS)
ifeq ($(SHARED_LIBVORBIS), 1) ifeq ($(SHARED_LIBVORBIS), 1)
LDFLAGS += -lvorbisfile LDFLAGS += -lvorbisfile
endif endif

View File

@ -53,7 +53,6 @@ using namespace Windows::Storage::FileProperties;
#include <retro_assert.h> #include <retro_assert.h>
#include <string/stdstring.h> #include <string/stdstring.h>
#include <retro_environment.h> #include <retro_environment.h>
#include <uwp/uwp_func.h>
#include <uwp/uwp_async.h> #include <uwp/uwp_async.h>
namespace namespace

84
libretro/uwp/uwp_async.h Normal file
View File

@ -0,0 +1,84 @@
/* Copyright (C) 2018-2019 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (uwp_async.h).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <ppl.h>
#include <ppltasks.h>
#ifdef __cplusplus
#ifdef __cplusplus_winrt
namespace
{
/* Dear Microsoft
* I really appreciate all the effort you took to not provide any
* synchronous file APIs and block all attempts to synchronously
* wait for the results of async tasks for "smooth user experience",
* but I'm not going to run and rewrite all RetroArch cores for
* async I/O. I hope you like this hack I made instead.
*/
template<typename T>
T RunAsync(std::function<concurrency::task<T>()> func)
{
volatile bool finished = false;
Platform::Exception^ exception = nullptr;
T result;
func().then([&finished, &exception, &result](concurrency::task<T> t) {
try
{
result = t.get();
}
catch (Platform::Exception ^ exception_)
{
exception = exception_;
}
finished = true;
});
/* Don't stall the UI thread - prevents a deadlock */
Windows::UI::Core::CoreWindow^ corewindow = Windows::UI::Core::CoreWindow::GetForCurrentThread();
while (!finished)
{
if (corewindow) {
corewindow->Dispatcher->ProcessEvents(Windows::UI::Core::CoreProcessEventsOption::ProcessAllIfPresent);
}
}
if (exception != nullptr)
throw exception;
return result;
}
template<typename T>
T RunAsyncAndCatchErrors(std::function<concurrency::task<T>()> func, T valueOnError)
{
try
{
return RunAsync<T>(func);
}
catch (Platform::Exception ^ e)
{
return valueOnError;
}
}
}
#endif
#endif