Skip to content

Commit

Permalink
Put back lua building directly into premake project
Browse files Browse the repository at this point in the history
No longer rely on prebuilt binaries on windows and android, and remove no longer needed "lua-path" option from the premake project
  • Loading branch information
edo9300 committed Apr 15, 2024
1 parent b91dd7f commit ed84904
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 89 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/ygopro-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ jobs:
sudo docker run -dt --rm --name alpine -v $PWD:/core -w="/core" alpine-cmake
- name: Install lua
shell: bash
run: |
sudo docker exec -t -w="/core" -e TRAVIS_OS_NAME=linux -e MAKE=make alpine ./travis/install-lua.sh
run: ./travis/install-lua.sh
- name: Install premake
shell: bash
run: ./travis/install-premake5.sh
Expand Down Expand Up @@ -197,9 +196,7 @@ jobs:
fetch-depth: 1
- name: Install lua
shell: bash
run: |
cd ..
curl https://codeload.github.com/edo9300/edopro-android/tar.gz/master | tar -xz --strip=2 edopro-android-master/deps/lua
run: ./travis/install-lua.sh
- name: Build
shell: bash
run: ./travis/build-android.sh
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ tmp/
.vs/
.DS_Store
lua*
!lua*/
lua*/*
!lua*/Android.mk
!lua*/premake5.lua
7 changes: 3 additions & 4 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ LOCAL_SRC_FILES := card.cpp \
processor_visit.cpp \
scriptlib.cpp

LOCAL_CFLAGS := -pedantic -Wextra -fvisibility=hidden -DOCGCORE_EXPORT_FUNCTIONS -DNDEBUG
LOCAL_CFLAGS := -pedantic -Wextra -fvisibility=hidden -DOCGCORE_EXPORT_FUNCTIONS -DNDEBUG
LOCAL_CPPFLAGS := -fexceptions -fno-rtti
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../lua/include
LOCAL_STATIC_LIBRARIES += liblua5.3
LOCAL_STATIC_LIBRARIES += liblua

include $(BUILD_SHARED_LIBRARY)

$(call import-add-path,$(LOCAL_PATH)/..)
$(call import-add-path,$(LOCAL_PATH))
$(call import-module,lua)

1 change: 0 additions & 1 deletion jni/Application.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
APP_ABI := armeabi-v7a arm64-v8a x86
APP_PLATFORM := android-16
APP_ALLOW_MISSING_DEPS=true
APP_STL := c++_static
APP_CPPFLAGS := -std=c++1z
APP_OPTIM := release
16 changes: 16 additions & 0 deletions lua/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := lua
EXCLUDED_LUA_FILES=$(LOCAL_PATH)/src/lua.c $(LOCAL_PATH)/src/luac.c
FILE_LIST := $(wildcard $(LOCAL_PATH)/src/*.c)
LOCAL_SRC_FILES := $(filter-out $(EXCLUDED_LUA_FILES), $(FILE_LIST))

LOCAL_CPPFLAGS := -fexceptions -fno-rtti -D"lua_getlocaledecpoint()='.'" -Wno-deprecated
LOCAL_EXPORT_CFLAGS := -D"lua_getlocaledecpoint()='.'"
LOCAL_CPP_EXTENSION := .c
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/src
LOCAL_THIN_ARCHIVE := true

include $(BUILD_STATIC_LIBRARY)
8 changes: 8 additions & 0 deletions lua/premake5.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
project "lua"
kind "StaticLib"
pic "On"
files { "src/*.c", "src/*.h" }
excludes { "src/lua.c", "src/luac.c" }

filter { "files:**.c" }
compileas "C++"
49 changes: 16 additions & 33 deletions premake5.lua
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
local ocgcore_config=function()
files { "**.h", "**.hpp", "**.cpp" }
files { "*.h", "*.hpp", "*.cpp", "RNG/*.hpp", "RNG/*.cpp" }
warnings "Extra"
optimize "Speed"
cppdialect "C++17"
rtti "Off"

filter "action:not vs*"
buildoptions { "-Wno-unused-parameter", "-pedantic" }
if os.istarget("macosx") then
filter { "files:processor_visit.cpp" }
buildoptions { "-fno-exceptions" }
end
filter {}
include "lua"
links { "lua" }
includedirs { "lua/src" }
end

if not subproject then
newoption {
trigger = "oldwindows",
description = "Use the v140_xp or v141_xp toolset to support windows XP sp3"
}
newoption {
trigger = "lua-path",
description = "Path where the lua library has been installed"
description = "Use the v141_xp toolset to support windows XP sp3"
}
workspace "ocgcore"
location "build"
language "C++"
objdir "obj"
configurations { "Debug", "Release" }
symbols "On"
staticruntime "on"

if _OPTIONS["oldwindows"] then
toolset "v141_xp"
end

filter "system:windows"
defines { "WIN32", "_WIN32", "NOMINMAX" }
Expand All @@ -38,25 +44,10 @@ if not subproject then
filter "platforms:x64"
architecture "x64"

if _OPTIONS["oldwindows"] then
filter {}
toolset "v141_xp"
end

filter "action:vs*"
flags "MultiProcessorCompile"
vectorextensions "SSE2"

filter "action:not vs*"
buildoptions "-fno-strict-aliasing"
if _OPTIONS["lua-path"] then
includedirs{ _OPTIONS["lua-path"] .. "/include" }
libdirs{ _OPTIONS["lua-path"] .. "/lib" }
else
includedirs "/usr/local/include"
libdirs "/usr/local/lib"
end

filter "configurations:Debug"
defines "_DEBUG"
targetdir "bin/debug"
Expand All @@ -78,30 +69,25 @@ if not subproject then
linkoptions { "-mthreads", "-municode", "-static-libgcc", "-static-libstdc++", "-static", "-lpthread" }
defines { "UNICODE", "_UNICODE" }

local function vcpkgStaticTriplet(prj)
premake.w('<VcpkgTriplet Condition="\'$(Platform)\'==\'Win32\'">x86-windows-static</VcpkgTriplet>')
premake.w('<VcpkgTriplet Condition="\'$(Platform)\'==\'x64\'">x64-windows-static</VcpkgTriplet>')
end

local function disableWinXPWarnings(prj)
premake.w('<XPDeprecationWarning>false</XPDeprecationWarning>')
end

local function vcpkgStaticTriplet202006(prj)
premake.w('<VcpkgEnabled>true</VcpkgEnabled>')
premake.w('<VcpkgUseStatic>true</VcpkgUseStatic>')
premake.w('<VcpkgAutoLink>true</VcpkgAutoLink>')
premake.w('<VcpkgEnabled>false</VcpkgEnabled>')
premake.w('<VcpkgUseStatic>false</VcpkgUseStatic>')
premake.w('<VcpkgAutoLink>false</VcpkgAutoLink>')
end

require('vstudio')

premake.override(premake.vstudio.vc2010.elements, "globals", function(base, prj)
local calls = base(prj)
table.insertafter(calls, premake.vstudio.vc2010.targetPlatformVersionGlobal, vcpkgStaticTriplet)
table.insertafter(calls, premake.vstudio.vc2010.targetPlatformVersionGlobal, disableWinXPWarnings)
table.insertafter(calls, premake.vstudio.vc2010.globals, vcpkgStaticTriplet202006)
return calls
end)
startproject "ocgcoreshared"
end

project "ocgcore"
Expand All @@ -116,6 +102,3 @@ project "ocgcoreshared"
staticruntime "on"
visibility "Hidden"
ocgcore_config()

filter "action:not vs*"
links "lua"
14 changes: 4 additions & 10 deletions travis/build-android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@ set -euxo pipefail

NDK_VERSION=${NDK_VERSION:-"21.4.7075529"}

SDKMANAGER=$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager
echo y | $SDKMANAGER "ndk;$NDK_VERSION"
ln -sfn $ANDROID_HOME/ndk/$NDK_VERSION $ANDROID_HOME/ndk-bundle

if [[ "$OS_NAME" == "osx" ]]; then
ANDROID_HOME=$HOME/Library/Android/sdk
SDKMANAGER=$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager
echo y | $SDKMANAGER "ndk;$NDK_VERSION"
ln -sfn $ANDROID_HOME/ndk/$NDK_VERSION $ANDROID_HOME/ndk-bundle
$ANDROID_HOME/ndk-bundle/ndk-build -j3
fi
if [[ "$OS_NAME" == "linux" ]]; then
ANDROID_ROOT=/usr/local/lib/android
ANDROID_SDK_ROOT=${ANDROID_ROOT}/sdk
SDKMANAGER=${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager
echo "y" | $SDKMANAGER "ndk;$NDK_VERSION"
ANDROID_NDK_ROOT=${ANDROID_SDK_ROOT}/ndk-bundle
ln -sfn $ANDROID_SDK_ROOT/ndk/$NDK_VERSION $ANDROID_NDK_ROOT
$ANDROID_HOME/ndk-bundle/ndk-build -j2
fi
2 changes: 1 addition & 1 deletion travis/build-premake5.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fi

if [[ "$TRAVIS_OS_NAME" == "windows" ]]; then
./premake5.exe vs2019 --oldwindows=true;
msbuild.exe -p:Configuration=$BUILD_CONFIG -p:Platform=Win32 -t:ocgcoreshared -verbosity:minimal -p:EchoOff=true ./build/ocgcore.sln;
msbuild.exe -p:Configuration=$BUILD_CONFIG -p:Platform=Win32 -t:ocgcoreshared -verbosity:minimal -p:EchoOff=true ./build/ocgcore.sln;
fi
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
./premake5 gmake2 $PREMAKE_FLAGS
Expand Down
49 changes: 14 additions & 35 deletions travis/install-lua.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,21 @@

set -euxo pipefail

TRAVIS_OS_NAME=${1:-$TRAVIS_OS_NAME}
TARGET_OS=${TARGET_OS:-$TRAVIS_OS_NAME}
CXX=${CXX:-g++}
MAKE=${MAKE:-sudo make}
curl --retry 2 --connect-timeout 30 --location --remote-header-name --remote-name https://www.lua.org/ftp/lua-5.3.6.tar.gz || \
curl --retry 2 --connect-timeout 30 --location --remote-header-name --remote-name https://www.tecgraf.puc-rio.br/lua/mirror/ftp/lua-5.3.6.tar.gz
mkdir -p lua
tar xf lua-5.3.6.tar.gz --strip-components=1 -C lua
cd lua
cat <<EOT >> src/luaconf.h
#ifdef LUA_USE_WINDOWS
#undef LUA_USE_WINDOWS
#undef LUA_DL_DLL
#undef LUA_USE_C89
#endif
if [[ "$TARGET_OS" == "windows" ]]; then
mkdir -p "$VCPKG_ROOT"
cd "$VCPKG_ROOT"
curl --retry 5 --connect-timeout 30 --location --remote-header-name --output installed.zip "$VCPKG_CACHE_ZIP_URL"
unzip -uo installed.zip > /dev/null
mkdir ports
mkdir triplets
mkdir triplets/community
./vcpkg.exe integrate install
else
cd /tmp
curl --retry 2 --connect-timeout 30 --location --remote-header-name --remote-name https://www.lua.org/ftp/lua-5.3.5.tar.gz || \
curl --retry 2 --connect-timeout 30 --location --remote-header-name --remote-name https://www.tecgraf.puc-rio.br/lua/mirror/ftp/lua-5.3.5.tar.gz
tar xf lua-5.3.5.tar.gz
cd lua-5.3.5
if [[ -n ${LUA_APICHECK:-""} ]]; then
EOT
if [[ -n ${LUA_APICHECK:-""} ]]; then
cat <<EOT >> src/luaconf.h
#ifndef luaconf_h_ocgcore_api_check
Expand All @@ -33,19 +27,4 @@ void ocgcore_lua_api_check(void* L, const char* error_message);
#endif
EOT
# The default makefile also builds the lua standalone interpreter and compiler, append a dummy implementation of
# the apicheck function to make it happy and not fail to link
cat <<EOT >> src/luac.c
void ocgcore_lua_api_check(void* L, const char* error_message){}
EOT
cat <<EOT >> src/lua.c
void ocgcore_lua_api_check(void* L, const char* error_message){}
EOT
fi
if [[ "$TARGET_OS" == "osx" ]]; then
make -j3 macosx CC=$CXX MYCFLAGS="${CFLAGS:-""}" MYLDFLAGS="${LDFLAGS:-""}" AR="${AR:-"ar rcu"}" RANLIB="${RANLIB:-"ranlib"}"
else
make -j2 posix CC=$CXX MYCFLAGS="${CFLAGS:-"-fPIC"}" MYLDFLAGS="${LDFLAGS:-""}" AR="${AR:-"ar rcu"}" RANLIB="${RANLIB:-"ranlib"}"
fi
$MAKE install
fi

0 comments on commit ed84904

Please sign in to comment.