From 900966b7c70ac0967b13d7d5c4b22b8187936971 Mon Sep 17 00:00:00 2001 From: Edoardo Lolletti Date: Mon, 23 Sep 2024 21:14:35 +0200 Subject: [PATCH] Update way lua is "customized" No longer patch luaconf.h, but rather force include a customization header in every translation unit and only build the actual used libraries, instead of building everything --- .github/workflows/ygopro-core.yml | 12 ++++++------ .gitignore | 1 + lua/Android.mk | 16 +++++++++++++--- lua/luaconf-customize.h | 7 +++++++ lua/premake5.lua | 26 ++++++++++++++++++++++++-- scripts/install-lua.bat | 9 --------- scripts/install-lua.sh | 22 ---------------------- 7 files changed, 51 insertions(+), 42 deletions(-) create mode 100644 lua/luaconf-customize.h diff --git a/.github/workflows/ygopro-core.yml b/.github/workflows/ygopro-core.yml index 3c783f3d..5c4b87ed 100644 --- a/.github/workflows/ygopro-core.yml +++ b/.github/workflows/ygopro-core.yml @@ -130,13 +130,13 @@ jobs: include: - deploy-branch: travis-core-linux-musl docker-image: x86_64-linux-musl - apicheck: 0 + premake-flags: - deploy-branch: travis-core-linux-musl-apicheck docker-image: x86_64-linux-musl - apicheck: 1 + premake-flags: --lua-apicheck - deploy-branch: travis-core-linux-musl-aarch64 docker-image: aarch64-linux-musl - apicheck: 0 + premake-flags: runs-on: ubuntu-latest env: DEPLOY_BRANCH: ${{ matrix.deploy-branch }} @@ -153,16 +153,16 @@ jobs: sudo docker run -dt --rm --name alpine -v $PWD:/core -w="/core" alpine-cmake - name: Install lua shell: bash - env: - LUA_APICHECK: ${{ matrix.apicheck }} run: ./scripts/install-lua.sh - name: Install premake shell: bash run: ./scripts/install-premake5.sh - name: Build shell: bash + env: + PREMAKE_FLAGS: ${{ matrix.premake-flags }} run: | - ./premake5 gmake2 + ./premake5 gmake2 $PREMAKE_FLAGS sudo docker exec -t -w="/core" alpine make -Cbuild ocgcoreshared -j$(nproc) config=release LDFLAGS="-static -Wl,-Bstatic" && sudo chown -R $USER bin - name: Predeploy diff --git a/.gitignore b/.gitignore index 31fc50da..2484c57f 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ lua* !lua*/ lua*/* !lua*/Android.mk +!lua*/luaconf-customize.h !lua*/premake5.lua *.exe *.pdb diff --git a/lua/Android.mk b/lua/Android.mk index 248f2e21..13bdb5d5 100644 --- a/lua/Android.mk +++ b/lua/Android.mk @@ -3,12 +3,22 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := lua -EXCLUDED_LUA_FILES := $(LOCAL_PATH)/src/lua.c $(LOCAL_PATH)/src/luac.c $(LOCAL_PATH)/src/ltests.h $(LOCAL_PATH)/src/ltests.c $(LOCAL_PATH)/src/onelua.c +EXCLUDED_LUA_FILES := \ + $(LOCAL_PATH)/src/lbitlib.c \ + $(LOCAL_PATH)/src/lcorolib.c \ + $(LOCAL_PATH)/src/ldblib.c \ + $(LOCAL_PATH)/src/linit.c \ + $(LOCAL_PATH)/src/loadlib.c \ + $(LOCAL_PATH)/src/loslib.c \ + $(LOCAL_PATH)/src/ltests.c \ + $(LOCAL_PATH)/src/lua.c \ + $(LOCAL_PATH)/src/luac.c \ + $(LOCAL_PATH)/src/lutf8lib.c \ + $(LOCAL_PATH)/src/onelua.c FILE_LIST := $(filter-out $(EXCLUDED_LUA_FILES), $(wildcard $(LOCAL_PATH)/src/*.c)) LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%) -LOCAL_CPPFLAGS := -fexceptions -fno-rtti -D"lua_getlocaledecpoint()='.'" -Wno-deprecated -LOCAL_EXPORT_CFLAGS := -D"lua_getlocaledecpoint()='.'" +LOCAL_CPPFLAGS := -fexceptions -fno-rtti -include ./luaconf-customize.h -Wno-deprecated LOCAL_CPP_EXTENSION := .c LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/src LOCAL_THIN_ARCHIVE := true diff --git a/lua/luaconf-customize.h b/lua/luaconf-customize.h new file mode 100644 index 00000000..d1073a10 --- /dev/null +++ b/lua/luaconf-customize.h @@ -0,0 +1,7 @@ +#if defined(LUA_EPRO_APICHECK) +void ocgcore_lua_api_check(void* L, const char* error_message); +#define luai_apicheck(l,e) do { if(!e) ocgcore_lua_api_check(l,"Lua api check failed: " #e); } while(0) +#endif +#if defined(__ANDROID__) +#define lua_getlocaledecpoint() '.' +#endif diff --git a/lua/premake5.lua b/lua/premake5.lua index daa10d5d..0bf29958 100644 --- a/lua/premake5.lua +++ b/lua/premake5.lua @@ -1,8 +1,30 @@ +newoption { + trigger = "lua-apicheck", + description = "build lua with apicheck support" +} project "lua" kind "StaticLib" pic "On" - files { "src/*.c", "src/*.h" } - removefiles { "src/lua.c", "src/luac.c", "src/ltests.h", "src/ltests.c", "src/onelua.c" } + files { "src/*.c" } + removefiles { + "src/lbitlib.c", + "src/lcorolib.c", + "src/ldblib.c", + "src/linit.c", + "src/loadlib.c", + "src/loslib.c", + "src/ltests.c", + "src/lua.c", + "src/luac.c", + "src/lutf8lib.c", + "src/onelua.c" + } + + includedirs { "./" } + forceincludes { "luaconf-customize.h" } + if _OPTIONS["lua-apicheck"] then + defines "LUA_EPRO_APICHECK" + end filter "configurations:Release" optimize "Speed" diff --git a/scripts/install-lua.bat b/scripts/install-lua.bat index 3fb1399e..9e587a07 100644 --- a/scripts/install-lua.bat +++ b/scripts/install-lua.bat @@ -23,13 +23,4 @@ IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL% REN "lua/lua-%LUA_VERSION%" src IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL% -SET LUACONF="lua\src\luaconf.h" ->>%LUACONF% ECHO. ->>%LUACONF% ECHO #ifdef LUA_USE_WINDOWS ->>%LUACONF% ECHO #undef LUA_USE_WINDOWS ->>%LUACONF% ECHO #undef LUA_DL_DLL ->>%LUACONF% ECHO #undef LUA_USE_C89 ->>%LUACONF% ECHO #endif ->>%LUACONF% ECHO. - EXIT /B diff --git a/scripts/install-lua.sh b/scripts/install-lua.sh index f20da9e2..3f9066c2 100755 --- a/scripts/install-lua.sh +++ b/scripts/install-lua.sh @@ -16,25 +16,3 @@ fi mkdir -p lua/src tar xf $LUA_ARCHIVE --strip-components=1 -C lua/src -cd lua -cat <> src/luaconf.h - -#ifdef LUA_USE_WINDOWS -#undef LUA_USE_WINDOWS -#undef LUA_DL_DLL -#undef LUA_USE_C89 -#endif - -EOT -if [[ "${LUA_APICHECK:-0}" == "1" ]]; then - cat <> src/luaconf.h - -#ifndef luaconf_h_ocgcore_api_check -#define luaconf_h_ocgcore_api_check -void ocgcore_lua_api_check(void* L, const char* error_message); -#define luai_apicheck(l,e) do { if(!e) ocgcore_lua_api_check(l,"Lua api check failed: " #e); } while(0) - - -#endif -EOT -fi