From 7b9012671abdbe1d3b831099ea052f5682ba82e2 Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Mon, 30 Oct 2023 19:01:26 +0200 Subject: [PATCH 1/5] Add libuv --- .gitmodules | 6 ++++++ CMakeLists.txt | 11 ++++++++++- src/lua.cpp | 7 +++++++ third_party/libuv | 1 + third_party/luv | 1 + 5 files changed, 25 insertions(+), 1 deletion(-) create mode 160000 third_party/libuv create mode 160000 third_party/luv diff --git a/.gitmodules b/.gitmodules index 8a6cac49..93bb8f9d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -43,3 +43,9 @@ [submodule "third_party/hydra_core"] path = third_party/hydra_core url = https://github.com/hydra-emu/core +[submodule "third_party/luv"] + path = third_party/luv + url = https://github.com/luvit/luv +[submodule "third_party/libuv"] + path = third_party/libuv + url = https://github.com/libuv/libuv diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a718fbb..52ddb495 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -245,6 +245,15 @@ set(THIRD_PARTY_SOURCE_FILES third_party/imgui/imgui.cpp third_party/xxhash/xxhash.c ) +if(ENABLE_LUAJIT) + # Build luv and libuv for TCP Lua server usage + include_directories(third_party/luv/src) + include_directories(third_party/luv/deps/lua-compat-5.3/c-api) + include_directories(third_party/libuv/include) + set(THIRD_PARTY_SOURCE_FILES ${THIRD_PARTY_SOURCE_FILES} third_party/luv/src/luv.c) + + add_subdirectory(third_party/libuv) +endif() if(ENABLE_QT_GUI) include_directories(third_party/duckstation) @@ -399,7 +408,7 @@ endif() if(ENABLE_LUAJIT) target_compile_definitions(Alber PUBLIC "PANDA3DS_ENABLE_LUA=1") - target_link_libraries(Alber PRIVATE libluajit) + target_link_libraries(Alber PRIVATE libluajit uv) endif() if(ENABLE_OPENGL) diff --git a/src/lua.cpp b/src/lua.cpp index 729b6581..f7e0b719 100644 --- a/src/lua.cpp +++ b/src/lua.cpp @@ -1,6 +1,10 @@ #ifdef PANDA3DS_ENABLE_LUA #include "lua_manager.hpp" +extern "C" { + #include "luv.h" +} + void LuaManager::initialize() { L = luaL_newstate(); // Open Lua @@ -11,6 +15,9 @@ void LuaManager::initialize() { } luaL_openlibs(L); + lua_pushstring(L, "luv"); + luaopen_luv(L); + lua_settable(L, LUA_GLOBALSINDEX); initializeThunks(); initialized = true; diff --git a/third_party/libuv b/third_party/libuv new file mode 160000 index 00000000..b8368a14 --- /dev/null +++ b/third_party/libuv @@ -0,0 +1 @@ +Subproject commit b8368a1441fd4ebdaaae70b67136c80b1a98be32 diff --git a/third_party/luv b/third_party/luv new file mode 160000 index 00000000..3e55ac43 --- /dev/null +++ b/third_party/luv @@ -0,0 +1 @@ +Subproject commit 3e55ac4331d06aa5f43016a142aa2aaa23264105 From 93042b928348d615505b4af4cd622f04c4154894 Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Mon, 30 Oct 2023 21:37:59 +0200 Subject: [PATCH 2/5] Disable libuv on Android --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 52ddb495..82484596 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,11 @@ option(ENABLE_LUAJIT "Enable scripting with the Lua programming language" ON) option(ENABLE_QT_GUI "Enable the Qt GUI. If not selected then the emulator uses a minimal SDL-based UI instead" OFF) option(BUILD_HYDRA_CORE "Build a Hydra core" OFF) +if(ENABLE_LUAJIT AND ANDROID) + message(STATUS "Enabled LuaJIT on Android build. Automatically disabling it until it works properly") + set(ENABLE_LUAJIT OFF) +endif() + include_directories(${PROJECT_SOURCE_DIR}/include/) include_directories(${PROJECT_SOURCE_DIR}/include/kernel) include_directories (${FMT_INCLUDE_DIR}) From 3bb4af5e13bd0ea125cf1d22daf9a694061f34fb Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Mon, 30 Oct 2023 23:47:39 +0200 Subject: [PATCH 3/5] Fix libuv linkage --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 82484596..0d8278cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -413,7 +413,7 @@ endif() if(ENABLE_LUAJIT) target_compile_definitions(Alber PUBLIC "PANDA3DS_ENABLE_LUA=1") - target_link_libraries(Alber PRIVATE libluajit uv) + target_link_libraries(Alber PRIVATE libluajit uv_a) endif() if(ENABLE_OPENGL) From 362b8e6621f7b604b6b1fb0d5f94eae5e253f21a Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Thu, 1 Feb 2024 20:02:53 +0200 Subject: [PATCH 4/5] Update luv bindings to be disabled on Android --- CMakeLists.txt | 16 ++++++++-------- src/lua.cpp | 8 ++++++-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f9238264..e2548312 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,11 +40,6 @@ option(ENABLE_LUAJIT "Enable scripting with the Lua programming language" ON) option(ENABLE_QT_GUI "Enable the Qt GUI. If not selected then the emulator uses a minimal SDL-based UI instead" OFF) option(BUILD_HYDRA_CORE "Build a Hydra core" OFF) -if(ENABLE_LUAJIT AND ANDROID) - message(STATUS "Enabled LuaJIT on Android build. Automatically disabling it until it works properly") - set(ENABLE_LUAJIT OFF) -endif() - include_directories(${PROJECT_SOURCE_DIR}/include/) include_directories(${PROJECT_SOURCE_DIR}/include/kernel) include_directories (${FMT_INCLUDE_DIR}) @@ -271,8 +266,8 @@ set(THIRD_PARTY_SOURCE_FILES third_party/imgui/imgui.cpp third_party/xxhash/xxhash.c ) -if(ENABLE_LUAJIT) - # Build luv and libuv for TCP Lua server usage +if(ENABLE_LUAJIT AND NOT ANDROID) + # Build luv and libuv for Lua TCP server usage if we're not on Android include_directories(third_party/luv/src) include_directories(third_party/luv/deps/lua-compat-5.3/c-api) include_directories(third_party/libuv/include) @@ -446,7 +441,12 @@ endif() if(ENABLE_LUAJIT) target_compile_definitions(Alber PUBLIC "PANDA3DS_ENABLE_LUA=1") - target_link_libraries(Alber PRIVATE libluajit uv_a) + target_link_libraries(Alber PRIVATE libluajit) + + # If we're not on Android, link libuv too + if (NOT ANDROID) + target_link_libraries(Alber PRIVATE uv_a) + endif() endif() if(ENABLE_OPENGL) diff --git a/src/lua.cpp b/src/lua.cpp index ccfe955d..09c63173 100644 --- a/src/lua.cpp +++ b/src/lua.cpp @@ -1,9 +1,11 @@ #ifdef PANDA3DS_ENABLE_LUA #include "lua_manager.hpp" +#ifndef __ANDROID__ extern "C" { #include "luv.h" } +#endif void LuaManager::initialize() { L = luaL_newstate(); // Open Lua @@ -13,13 +15,15 @@ void LuaManager::initialize() { initialized = false; return; } - luaL_openlibs(L); + +#ifndef __ANDROID__ lua_pushstring(L, "luv"); luaopen_luv(L); lua_settable(L, LUA_GLOBALSINDEX); - initializeThunks(); +#endif + initializeThunks(); initialized = true; haveScript = false; } From ce63596716a723f7aba8e0f38e3caecd234a9f3b Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Thu, 1 Feb 2024 21:42:04 +0200 Subject: [PATCH 5/5] Do not build libuv shared library --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index e2548312..456d6513 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -272,6 +272,7 @@ if(ENABLE_LUAJIT AND NOT ANDROID) include_directories(third_party/luv/deps/lua-compat-5.3/c-api) include_directories(third_party/libuv/include) set(THIRD_PARTY_SOURCE_FILES ${THIRD_PARTY_SOURCE_FILES} third_party/luv/src/luv.c) + set(LIBUV_BUILD_SHARED OFF) add_subdirectory(third_party/libuv) endif()