Skip to content

Commit

Permalink
Update way lua is "customized"
Browse files Browse the repository at this point in the history
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
  • Loading branch information
edo9300 committed Sep 23, 2024
1 parent 1fc4a58 commit 900966b
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 42 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ygopro-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ lua*
!lua*/
lua*/*
!lua*/Android.mk
!lua*/luaconf-customize.h
!lua*/premake5.lua
*.exe
*.pdb
Expand Down
16 changes: 13 additions & 3 deletions lua/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions lua/luaconf-customize.h
Original file line number Diff line number Diff line change
@@ -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
26 changes: 24 additions & 2 deletions lua/premake5.lua
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
9 changes: 0 additions & 9 deletions scripts/install-lua.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 0 additions & 22 deletions scripts/install-lua.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,3 @@ fi

mkdir -p lua/src
tar xf $LUA_ARCHIVE --strip-components=1 -C lua/src
cd lua
cat <<EOT >> 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 <<EOT >> 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

0 comments on commit 900966b

Please sign in to comment.