From e58fa07828c95d3d090450e33861b308dcbcded6 Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Fri, 15 Mar 2024 10:40:13 -0700 Subject: [PATCH] Switch to Lua 5.4 and add Arm64 From Anders Broman: Switch to Lua 5.4.6. From me: Add an Arm64 build and use vcpkg triplets in the package names. Co-authored-by: Anders Broman --- CMakeLists.txt | 16 ++++++++------- build-all.ps1 | 15 +++++++++++---- prepare-sources.cmake | 4 ++-- src/utf8_wrappers.c | 45 ------------------------------------------- src/utf8_wrappers.h | 17 +--------------- 5 files changed, 23 insertions(+), 74 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c0b63eb..8aca895 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.5) -project(Lua VERSION 5.2.4 LANGUAGES C) +project(Lua VERSION 5.4.6 LANGUAGES C) if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/luaconf.h") message(FATAL_ERROR "Run \"cmake -P prepare-sources.cmake\" and change dirs.") @@ -13,8 +13,8 @@ set(LUA_TO_INC lua.h luaconf.h lualib.h lauxlib.h lua.hpp) set(LUA_CORE_SOURCES lapi.c lcode.c lctype.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c lmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c ltable.c ltm.c lundump.c lvm.c lzio.c) -set(LUA_LIB_SOURCES lauxlib.c lbaselib.c lbitlib.c lcorolib.c ldblib.c liolib.c - lmathlib.c loslib.c lstrlib.c ltablib.c loadlib.c linit.c) +set(LUA_LIB_SOURCES lauxlib.c lbaselib.c lcorolib.c ldblib.c liolib.c + lmathlib.c loslib.c lstrlib.c ltablib.c loadlib.c linit.c lutf8lib.c) set(LUA_SOURCES) foreach(_src IN LISTS LUA_CORE_SOURCES LUA_LIB_SOURCES) list(APPEND LUA_SOURCES "src/${_src}") @@ -107,10 +107,12 @@ else() endif() if(WIN32) - if(CMAKE_GENERATOR_PLATFORM STREQUAL "Win32") - set(name lua-${PROJECT_VERSION}-unicode-win32) - elseif(CMAKE_GENERATOR_PLATFORM STREQUAL "x64") - set(name lua-${PROJECT_VERSION}-unicode-win64) + if(CMAKE_GENERATOR_PLATFORM STREQUAL "x64") + set(name lua-${PROJECT_VERSION}-unicode-x64-windows) + elseif(CMAKE_GENERATOR_PLATFORM STREQUAL "arm64") + set(name lua-${PROJECT_VERSION}-unicode-arm64-windows) + elseif(CMAKE_GENERATOR_PLATFORM STREQUAL "Win32") + set(name lua-${PROJECT_VERSION}-unicode-x86-windows) else() message(FATAL_ERROR "Unexpected generator platform") endif() diff --git a/build-all.ps1 b/build-all.ps1 index d00f63c..d9c6f61 100644 --- a/build-all.ps1 +++ b/build-all.ps1 @@ -3,15 +3,22 @@ # Abort whenever a command fails. $ErrorActionPreference = "Stop" -New-Item -Type Directory build64 -Push-Location build64 +New-Item -Type Directory build-x64 +Push-Location build-x64 cmake .. -A x64 cmake --build . --target create-zip --config RelWithDebInfo Move-Item *.zip .. Pop-Location -New-Item -Type Directory build32 -Push-Location build32 +New-Item -Type Directory build-arm64 +Push-Location build-arm64 +cmake .. -A arm64 +cmake --build . --target create-zip --config RelWithDebInfo +Move-Item *.zip .. +Pop-Location + +New-Item -Type Directory build-x86 +Push-Location build-x86 cmake .. -A Win32 cmake --build . --target create-zip --config RelWithDebInfo Move-Item *.zip .. diff --git a/prepare-sources.cmake b/prepare-sources.cmake index ca80866..2e15d34 100644 --- a/prepare-sources.cmake +++ b/prepare-sources.cmake @@ -2,10 +2,10 @@ # (A subdirectory will be created for the sources.) cmake_minimum_required(VERSION 3.5) -set(PROJECT_VERSION 5.2.4) +set(PROJECT_VERSION 5.4.6) set(URL https://www.lua.org/ftp/lua-${PROJECT_VERSION}.tar.gz) -set(SHA256 b9e2e4aad6789b3b63a056d442f7b39f0ecfca3ae0f1fc0ae4e9614401b69f4b) +set(SHA256 7d5ea1b9cb6aa0b59ca3dde1c6adcb57ef83a1ba8e5432c0ecd06bf439b3ad88) # Directory to store the source tarball and create the source directory. if(NOT OUTPUT_DIR) diff --git a/src/utf8_wrappers.c b/src/utf8_wrappers.c index d9247aa..e57ff07 100644 --- a/src/utf8_wrappers.c +++ b/src/utf8_wrappers.c @@ -42,26 +42,6 @@ FILE *freopen_utf8(const char *pathname, const char *mode, FILE *stream) { return _wfreopen(pathname_w, mode_w, stream); } -int remove_utf8(const char *pathname) { - wchar_t pathname_w[MAX_PATH_SIZE]; - if (!MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, pathname, -1, pathname_w, MAX_PATH_SIZE)) { - errno = EINVAL; - return -1; - } - return _wremove(pathname_w); -} - -int rename_utf8(const char *oldpath, const char *newpath) { - wchar_t oldpath_w[MAX_PATH_SIZE]; - wchar_t newpath_w[MAX_PATH_SIZE]; - if (!MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, oldpath, -1, oldpath_w, MAX_PATH_SIZE) || - !MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, newpath, -1, newpath_w, MAX_PATH_SIZE)) { - errno = EINVAL; - return -1; - } - return _wrename(oldpath_w, newpath_w); -} - FILE *popen_utf8(const char *command, const char *mode) { wchar_t command_w[MAX_CMD_SIZE]; wchar_t mode_w[MAX_MODE_SIZE]; @@ -73,29 +53,4 @@ FILE *popen_utf8(const char *command, const char *mode) { return _wpopen(command_w, mode_w); } -int system_utf8(const char *command) { - wchar_t command_w[MAX_CMD_SIZE]; - if (!MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, command, -1, command_w, MAX_CMD_SIZE)) { - errno = EINVAL; - return -1; - } - return _wsystem(command_w); -} - -DWORD GetModuleFileNameA_utf8(HMODULE hModule, LPSTR lpFilename, DWORD nSize) { - wchar_t filename_w[MAX_PATH + 1]; - if (!GetModuleFileNameW(hModule, filename_w, MAX_PATH + 1)) { - return 0; - } - return WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, filename_w, -1, lpFilename, nSize, NULL, NULL); -} - -HMODULE LoadLibraryExA_utf8(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags) { - wchar_t pathname_w[MAX_PATH_SIZE]; - if (!MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, lpLibFileName, -1, pathname_w, MAX_PATH_SIZE)) { - SetLastError(ERROR_INVALID_NAME); - return NULL; - } - return LoadLibraryExW(pathname_w, hFile, dwFlags); -} #endif diff --git a/src/utf8_wrappers.h b/src/utf8_wrappers.h index 846b096..66b6bc2 100644 --- a/src/utf8_wrappers.h +++ b/src/utf8_wrappers.h @@ -23,22 +23,7 @@ FILE *popen_utf8(const char *command, const char *mode); #define _popen popen_utf8 #endif -#ifdef loslib_c -int remove_utf8(const char *pathname); -int rename_utf8(const char *oldpath, const char *newpath); -int system_utf8(const char *command); -#define remove remove_utf8 -#define rename rename_utf8 -#define system system_utf8 -#endif - -#ifdef loadlib_c -DWORD GetModuleFileNameA_utf8(HMODULE hModule, LPSTR lpFilename, DWORD nSize); -HMODULE LoadLibraryExA_utf8(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags); -#define GetModuleFileNameA GetModuleFileNameA_utf8 -#define LoadLibraryExA LoadLibraryExA_utf8 -#endif -#endif +#endif // _WIN32 #if defined(lua_c) || defined(luac_c) int main_utf8(int argc, char *argv[]);