From ea91d324ccf8c19b3669533d8f381db0f5cb9734 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 15 Oct 2019 21:27:18 +0200 Subject: Arranging for VS2019 support --HG-- branch : vs2019_support --- release.cmd | 2 +- src/_manifest.lua | 1 + src/actions/vstudio/vs2010_vcxproj.lua | 2 +- src/actions/vstudio/vs2019.lua | 58 +++++++ src/host/keccak.c | 8 +- src/host/os_getversion.c | 192 ++++++++++++++------- src/host/os_is64bit.c | 25 ++- tests/actions/vstudio/sln2005/header.lua | 23 ++- tests/actions/vstudio/vc2010/test_config_props.lua | 13 ++ 9 files changed, 245 insertions(+), 79 deletions(-) create mode 100644 src/actions/vstudio/vs2019.lua diff --git a/release.cmd b/release.cmd index 3a2eff2..71fc201 100644 --- a/release.cmd +++ b/release.cmd @@ -33,7 +33,7 @@ vcbuild /rebuild /time "%SLNFILE%" "%SLNCFGNAME%|%SLNCFGPLTF%" set NEWNAME=%BASEPATH%%BASENAME%.rev-%HG_TIP_REVNO%-%HG_TIP_ID%.exe copy /y "%BASEPATH%%BINDIR%\%BASENAME%.exe" "%NEWNAME%" sigcheck -a "%NEWNAME%" -gpg2 --batch --yes -u 0xC779D8290E88590F -bao "%NEWNAME%.asc" "%NEWNAME%" +gpg --batch --yes -u 0xC779D8290E88590F -bao "%NEWNAME%.asc" "%NEWNAME%" copy /y "%BASEPATH%%BINDIR%\%BASENAME%.exe" "%BASEPATH%%BASENAME%.exe" endlocal goto :EOF diff --git a/src/_manifest.lua b/src/_manifest.lua index e8a6619..96225d1 100644 --- a/src/_manifest.lua +++ b/src/_manifest.lua @@ -67,6 +67,7 @@ "actions/vstudio/vs2013.lua", "actions/vstudio/vs2015.lua", "actions/vstudio/vs2017.lua", + "actions/vstudio/vs2019.lua", -- Xcode action "actions/xcode/_xcode.lua", diff --git a/src/actions/vstudio/vs2010_vcxproj.lua b/src/actions/vstudio/vs2010_vcxproj.lua index b4961c8..d888504 100644 --- a/src/actions/vstudio/vs2010_vcxproj.lua +++ b/src/actions/vstudio/vs2010_vcxproj.lua @@ -79,7 +79,7 @@ _p(2,'%s', iif(optimisation(cfg) == "Disabled","true","false")) _p(2,'%s',iif(cfg.flags.Unicode,"Unicode","MultiByte")) - local toolsets = { vs2012 = "v110", vs2013 = "v120", vs2015 = "v140", vs2017 = "v141" } + local toolsets = { vs2012 = "v110", vs2013 = "v120", vs2015 = "v140", vs2017 = "v141", vs2019 = "v142" } local toolset = toolsets[_ACTION] if toolset then _p(2,'%s', toolset) diff --git a/src/actions/vstudio/vs2019.lua b/src/actions/vstudio/vs2019.lua new file mode 100644 index 0000000..acfb924 --- /dev/null +++ b/src/actions/vstudio/vs2019.lua @@ -0,0 +1,58 @@ +-- +-- vs2019.lua +-- Baseline support for Visual Studio 2019. +-- Copyright (c) 2013 Jason Perkins and the Premake project +-- + + premake.vstudio.vc2019 = {} + local vc2019 = premake.vstudio.vc2019 + local vstudio = premake.vstudio + + +--- +-- Register a command-line action for Visual Studio 2019. +--- + + newaction + { + trigger = "vs2019", + shortname = "Visual Studio 2019", + description = "Generate Microsoft Visual Studio 2019 project files", + os = "windows", + + valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib" }, + + valid_languages = { "C", "C++", "C#"}, + + valid_tools = { + cc = { "msc" }, + dotnet = { "msnet" }, + }, + + onsolution = function(sln) + premake.generate(sln, "%%.sln", vstudio.sln2005.generate) + end, + + onproject = function(prj) + if premake.isdotnetproject(prj) then + premake.generate(prj, "%%.csproj", vstudio.cs2005.generate) + premake.generate(prj, "%%.csproj.user", vstudio.cs2005.generate_user) + else + premake.generate(prj, "%%.vcxproj", premake.vs2010_vcxproj) + premake.generate(prj, "%%.vcxproj.user", premake.vs2010_vcxproj_user) + premake.generate(prj, "%%.vcxproj.filters", vstudio.vc2010.generate_filters) + end + end, + + + oncleansolution = premake.vstudio.cleansolution, + oncleanproject = premake.vstudio.cleanproject, + oncleantarget = premake.vstudio.cleantarget, + + vstudio = { + solutionVersion = "12", + targetFramework = "4.7", + toolsVersion = "16.0", + shortSlnVersion = "16", + } + } diff --git a/src/host/keccak.c b/src/host/keccak.c index d4a3d70..6c97cf4 100644 --- a/src/host/keccak.c +++ b/src/host/keccak.c @@ -155,7 +155,7 @@ static void store64(UINT8 *x, UINT64 u) unsigned int i; for(i=0; i<8; ++i) { - x[i] = u; + x[i] = u & 0xFF; u >>= 8; } } @@ -285,8 +285,8 @@ that use the Keccak-f[1600] permutation. void Keccak(unsigned int rate, unsigned int capacity, const unsigned char *input, unsigned long long int inputByteLen, unsigned char delimitedSuffix, unsigned char *output, unsigned long long int outputByteLen) { UINT8 state[200]; - unsigned int rateInBytes = rate/8; - unsigned int blockSize = 0; + unsigned long long int rateInBytes = rate/8; + unsigned long long int blockSize = 0; unsigned int i; if (((rate + capacity) != 1600) || ((rate % 8) != 0)) @@ -323,7 +323,7 @@ void Keccak(unsigned int rate, unsigned int capacity, const unsigned char *input /* === Squeeze out all the output blocks === */ while(outputByteLen > 0) { blockSize = MIN(outputByteLen, rateInBytes); - memcpy(output, state, blockSize); + memcpy(output, state, (size_t)blockSize); output += blockSize; outputByteLen -= blockSize; diff --git a/src/host/os_getversion.c b/src/host/os_getversion.c index 446848f..609ca04 100755 --- a/src/host/os_getversion.c +++ b/src/host/os_getversion.c @@ -63,82 +63,148 @@ int os_getversion(lua_State* L) SYSTEM_INFO getsysteminfo() { - typedef void (WINAPI *GetNativeSystemInfoSig)(LPSYSTEM_INFO); - GetNativeSystemInfoSig nativeSystemInfo = (GetNativeSystemInfoSig) - GetProcAddress(GetModuleHandle(TEXT("kernel32")), "GetNativeSystemInfo"); + static SYSTEM_INFO systemInfo; + HMODULE hKrnl32 = GetModuleHandle(TEXT("kernel32")); + memset(&systemInfo, 0, sizeof(systemInfo)); + if (hKrnl32) + { + typedef void (WINAPI* GetNativeSystemInfoSig)(LPSYSTEM_INFO); + GetNativeSystemInfoSig nativeSystemInfo = (GetNativeSystemInfoSig)GetProcAddress(hKrnl32, "GetNativeSystemInfo"); - SYSTEM_INFO systemInfo = {{0}}; - if ( nativeSystemInfo ) nativeSystemInfo(&systemInfo); - else GetSystemInfo(&systemInfo); + if (nativeSystemInfo) + nativeSystemInfo(&systemInfo); + else + GetSystemInfo(&systemInfo); + } return systemInfo; } -void getversion(struct OsVersionInfo* info) -{ - OSVERSIONINFOEX versionInfo = {0}; - - versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); - GetVersionEx((OSVERSIONINFO*)&versionInfo); - - info->majorversion = versionInfo.dwMajorVersion; - info->minorversion = versionInfo.dwMinorVersion; - info->revision = versionInfo.wServicePackMajor; +#ifndef NT_SUCCESS +# define NT_SUCCESS(x) ((x) >= 0) +#endif - if (versionInfo.dwMajorVersion == 5 && versionInfo.dwMinorVersion == 0) - { - info->description = "Windows 2000"; - } - else if (versionInfo.dwMajorVersion == 5 && versionInfo.dwMinorVersion == 1) - { - info->description = "Windows XP"; - } - else if (versionInfo.dwMajorVersion == 5 && versionInfo.dwMinorVersion == 2) - { - SYSTEM_INFO systemInfo = getsysteminfo(); - if (versionInfo.wProductType == VER_NT_WORKSTATION && - systemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) - { - info->description = "Windows XP Professional x64"; - } - else if (versionInfo.wSuiteMask & VER_SUITE_WH_SERVER) - { - info->description = "Windows Home Server"; - } - else if (GetSystemMetrics(SM_SERVERR2) == 0) - { - info->description = "Windows Server 2003"; - } - else - { - info->description = "Windows Server 2003 R2"; - } - } - else if (versionInfo.dwMajorVersion == 6 && versionInfo.dwMinorVersion == 0) +OSVERSIONINFOEXW const * GetOSVersionInfo() +{ + static OSVERSIONINFOEXW* posvix = NULL; + if (!posvix) { - if (versionInfo.wProductType == VER_NT_WORKSTATION) + static OSVERSIONINFOEXW osvix = { sizeof(OSVERSIONINFOEXW), 0, 0, 0, 0,{ 0 } }; // not an error, this has to be the W variety! + static LONG(WINAPI * RtlGetVersion)(OSVERSIONINFOEXW*) = NULL; + static HMODULE hNtDll = NULL; + hNtDll = GetModuleHandle(TEXT("ntdll.dll")); + if (hNtDll) { - info->description = "Windows Vista"; - } - else - { - info->description = "Windows Server 2008"; + *(FARPROC*)&RtlGetVersion = GetProcAddress(hNtDll, "RtlGetVersion"); + if (NULL != RtlGetVersion) + { + if (NT_SUCCESS(RtlGetVersion(&osvix))) + { + posvix = &osvix; + } + } } } - else if (versionInfo.dwMajorVersion == 6 && versionInfo.dwMinorVersion == 1 ) + return posvix; +} + +void getversion(struct OsVersionInfo* info) +{ + static OSVERSIONINFOEXW const* posvix = NULL; + static struct OsVersionInfo s_info; + s_info.majorversion = 0; + s_info.minorversion = 0; + s_info.revision = 0; + s_info.description = "Windows"; + + if (!posvix) { - if (versionInfo.wProductType != VER_NT_WORKSTATION) + posvix = GetOSVersionInfo(); + if (posvix) { - info->description = "Windows Server 2008 R2"; + s_info.majorversion = posvix->dwMajorVersion; + s_info.minorversion = posvix->dwMinorVersion; + s_info.revision = posvix->wServicePackMajor; + switch (posvix->dwMajorVersion) + { + case 5: + switch (posvix->dwMinorVersion) + { + case 0: + s_info.description = "Windows 2000"; + break; + case 1: + s_info.description = "Windows XP"; + break; + case 2: + if (posvix->wProductType == VER_NT_WORKSTATION) + s_info.description = "Windows XP x64"; + else + if (posvix->wSuiteMask == VER_SUITE_WH_SERVER) + s_info.description = "Windows Home Server"; + else + { + if (GetSystemMetrics(SM_SERVERR2) == 0) + s_info.description = "Windows Server 2003"; + else + s_info.description = "Windows Server 2003 R2"; + } + break; + default: + s_info.description = "Windows [5.x]"; + break; + } + break; + case 6: + switch (posvix->dwMinorVersion) + { + case 0: + if (posvix->wProductType == VER_NT_WORKSTATION) + s_info.description = "Windows Vista"; + else + s_info.description = "Windows Server 2008"; + break; + case 1: + if (posvix->wProductType == VER_NT_WORKSTATION) + s_info.description = "Windows 7"; + else + s_info.description = "Windows Server 2008 R2"; + break; + case 2: + if (posvix->wProductType == VER_NT_WORKSTATION) + s_info.description = "Windows 8"; + else + s_info.description = "Windows Server 2012"; + break; + case 3: + if (posvix->wProductType == VER_NT_WORKSTATION) + s_info.description = "Windows 8.1"; + else + s_info.description = "Windows Server 2012 R2"; + break; + default: + s_info.description = "Windows [6.x]"; + break; + } + break; + case 10: + switch (posvix->dwMinorVersion) + { + case 0: + if (posvix->wProductType == VER_NT_WORKSTATION) + s_info.description = "Windows 10"; + else + s_info.description = "Windows Server 2016/2019"; + break; + default: + s_info.description = "Windows [10.x]"; + break; + } + break; + } } - else - { - info->description = "Windows 7"; - } - } - else - { - info->description = "Windows"; } + + memmove(info, &s_info, sizeof(struct OsVersionInfo)); } /*************************************************************/ diff --git a/src/host/os_is64bit.c b/src/host/os_is64bit.c index 3134751..2537c2e 100755 --- a/src/host/os_is64bit.c +++ b/src/host/os_is64bit.c @@ -8,19 +8,30 @@ int os_is64bit(lua_State* L) { +#if PLATFORM_WINDOWS + HMODULE hKrnl32 = GetModuleHandle(TEXT("kernel32")); +#endif + if (sizeof(void*) == 8) // our premake build is 64-bit, so the runtime environment must be also (at least) 64-bit ... + { + lua_pushboolean(L, 1); + return 1; + } // If this code returns true, then the platform is 64-bit. If it // returns false, the platform might still be 64-bit, but more // checking will need to be done on the Lua side of things. #if PLATFORM_WINDOWS - typedef BOOL (WINAPI* WowFuncSig)(HANDLE, PBOOL); - WowFuncSig func = (WowFuncSig)GetProcAddress(GetModuleHandle(TEXT("kernel32")), "IsWow64Process"); - if (func) + typedef BOOL(WINAPI* WowFuncSig)(HANDLE, PBOOL); + if (hKrnl32) { - BOOL isWow = FALSE; - if (func(GetCurrentProcess(), &isWow)) + WowFuncSig func = (WowFuncSig)GetProcAddress(hKrnl32, "IsWow64Process"); + if (func) { - lua_pushboolean(L, isWow); - return 1; + BOOL isWow = FALSE; + if (func(GetCurrentProcess(), &isWow)) + { + lua_pushboolean(L, isWow); + return 1; + } } } #endif diff --git a/tests/actions/vstudio/sln2005/header.lua b/tests/actions/vstudio/sln2005/header.lua index 2208b42..240889d 100755 --- a/tests/actions/vstudio/sln2005/header.lua +++ b/tests/actions/vstudio/sln2005/header.lua @@ -77,7 +77,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 ]] --[[ -VS 2013 seems to add: +VS 2013 seems to add something like: VisualStudioVersion = 12.0.31101.0 MinimumVisualStudioVersion = 10.0.40219.1 @@ -94,7 +94,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 ]] --[[ -VS 2015 seems to add: +VS 2015 seems to add something like: VisualStudioVersion = 14.0.23107.0 MinimumVisualStudioVersion = 10.0.40219.1 @@ -111,11 +111,28 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 ]] --[[ -VS 2017 seems to add: +VS 2017 seems to add something like: VisualStudioVersion = 15.0.26228.4 MinimumVisualStudioVersion = 10.0.40219.1 +which don't seem to be mandatory, though. +]] + end + + function suite.On2019() + _ACTION = "vs2019" + prepare() + test.capture [[ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 16 + ]] +--[[ +VS 2019 seems to add something like: + +VisualStudioVersion = 16.0.29411.108 +MinimumVisualStudioVersion = 10.0.40219.1 + which don't seem to be mandatory, though. ]] end diff --git a/tests/actions/vstudio/vc2010/test_config_props.lua b/tests/actions/vstudio/vc2010/test_config_props.lua index d2f18dd..b1b19ff 100644 --- a/tests/actions/vstudio/vc2010/test_config_props.lua +++ b/tests/actions/vstudio/vc2010/test_config_props.lua @@ -102,3 +102,16 @@ ]] end + + function suite.structureIsCorrect_onDefaultValues_on2019() + _ACTION = "vs2019" + prepare() + test.capture [[ + + Application + true + MultiByte + v142 + + ]] + end -- cgit v1.2.3