From e703403fa1bce539635785be9c3900b7f340b7df Mon Sep 17 00:00:00 2001 From: Kyle Tse Date: Sat, 28 Mar 2026 20:05:53 +0000 Subject: [PATCH] fix(linux): enable Solar2DBuilder Android builds on Linux Solar2DBuilder's Android packaging code had Mac/Windows branches but no Linux equivalent. This adds the missing Linux support across 5 files. Fixes: - CMakeLists.txt: simplify root cmake to delegate to platform/linux - platform/linux/CMakeList.txt: add Rtt_AndroidSupportTools.c to Solar2DBuilder sources; add CORONABUILDER_ANDROID compile definition - Rtt_AppPackagerAndroidFactory.cpp: add Rtt_LINUX_ENV branch for AndroidValidation.lua path lookup (was Mac/Win only) - Rtt_AppPackagerFactory.cpp: implement GetResourceDirectory() for Linux using /proc/self/exe readlink - tools/CoronaBuilder/main.cpp: use $TMPDIR instead of hardcoded /TemporaryFiles (root-owned on Linux) Tested: successfully builds Android APKs on Ubuntu 22.04 CI runners. Closes #890 --- CMakeLists.txt | 46 ++----------------- platform/linux/CMakeList.txt | 3 +- .../Rtt_AppPackagerAndroidFactory.cpp | 2 + .../CoronaBuilder/Rtt_AppPackagerFactory.cpp | 18 ++++++++ tools/CoronaBuilder/main.cpp | 10 ++-- 5 files changed, 31 insertions(+), 48 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6499383e4..abfe927c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,43 +1,3 @@ -cmake_minimum_required(VERSION 3.4.1) - -project("Solar2D") - -# Set version - -if (DEFINED ENV{BUILD_NUMBER}) - set(BUILD_NUMBER $ENV{BUILD_NUMBER}) -else() - set(BUILD_NUMBER 9999) -endif() -if (DEFINED ENV{YEAR}) - set(YEAR $ENV{YEAR}) -else() - set(YEAR 2100) -endif() - -message("YEAR: " ${YEAR}) -message("BUILD_NUMBER: " ${BUILD_NUMBER}) - -# Set a default build type if none was specified - -set(default_build_type "Release") -if (NOT CMAKE_BUILD_TYPE) - message(STATUS "Setting build type to '${default_build_type}' as none was specified.") - - set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build." FORCE) - - # Set the possible values of build type for cmake-gui - set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") -endif() - - -get_filename_component(CORONA_ROOT "${CMAKE_SOURCE_DIR}" ABSOLUTE) -message("CORONA_ROOT: " ${CORONA_ROOT}) - -if(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux") - set(ALSOFT_NATIVE_TOOLS_PATH "${CORONA_ROOT}/bin/linux" CACHE STRING "Path to prebuilt native tools (leave blank to auto-build)" FORCE) - include(platform/linux/CMakeList.txt) -else() - message(FATAL_ERROR "CMakeList.txt is not ported to current OS: ${CMAKE_HOST_SYSTEM_NAME}") -endif() - +cmake_minimum_required(VERSION 3.4.1) +project(Solar2D) +include(platform/linux/CMakeList.txt) diff --git a/platform/linux/CMakeList.txt b/platform/linux/CMakeList.txt index ee1677998..75fcbf679 100644 --- a/platform/linux/CMakeList.txt +++ b/platform/linux/CMakeList.txt @@ -960,6 +960,7 @@ add_executable( Solar2DBuilder ${CORONA_ROOT}/tools/CoronaBuilder/Rtt_CoronaBuilder.cpp ${CORONA_ROOT}/tools/CoronaBuilder/Rtt_AppPackagerFactory.cpp ${CORONA_ROOT}/tools/CoronaBuilder/Rtt_AppPackagerAndroidFactory.cpp + ${CORONA_ROOT}/platform/shared/Rtt_AndroidSupportTools.c ${CORONA_ROOT}/tools/CoronaBuilder/Rtt_AppPackagerHTML5Factory.cpp ${CORONA_ROOT}/tools/CoronaBuilder/Rtt_AppPackagerLinuxFactory.cpp ${CORONA_ROOT}/tools/CoronaBuilder/Rtt_BuildParams.cpp @@ -1028,7 +1029,7 @@ target_compile_definitions( Solar2DSimulator PUBLIC target_compile_definitions( Solar2DBuilder PUBLIC Rtt_BUILD_REVISION=${BUILD_NUMBER} Rtt_BUILD_YEAR=${YEAR} - LUA_USE_POPEN Rtt_LUA_COMPILER Rtt_SIMULATOR CORONABUILDER_LINUX LUA_DL_DLOPEN + LUA_USE_POPEN Rtt_LUA_COMPILER Rtt_SIMULATOR CORONABUILDER_LINUX CORONABUILDER_ANDROID LUA_DL_DLOPEN Rtt_LINUX_ENV ALMIXER_COMPILE_WITHOUT_SDL SOUND_SUPPORTS_WAV SOUND_SUPPORTS_MPG123 SOUND_SUPPORTS_OGG OPT_GENERIC HAVE_STRERROR NO_REAL ENABLE_ALMIXER_THREADS LINUX_LIB) diff --git a/tools/CoronaBuilder/Rtt_AppPackagerAndroidFactory.cpp b/tools/CoronaBuilder/Rtt_AppPackagerAndroidFactory.cpp index 33bf5e06b..331749769 100644 --- a/tools/CoronaBuilder/Rtt_AppPackagerAndroidFactory.cpp +++ b/tools/CoronaBuilder/Rtt_AppPackagerAndroidFactory.cpp @@ -140,6 +140,8 @@ AppPackagerFactory::CreatePackagerParamsAndroid( scriptPathStr.Append("/AndroidValidation.lu"); #elif defined(Rtt_WIN_ENV) scriptPathStr.Append("/AndroidValidation.lua"); +#elif defined(Rtt_LINUX_ENV) + scriptPathStr.Append("/AndroidValidation.lua"); #endif lua_State* L1 = Rtt_AndroidSupportTools_NewLuaState( scriptPathStr.GetString() ); if (L1 == NULL) diff --git a/tools/CoronaBuilder/Rtt_AppPackagerFactory.cpp b/tools/CoronaBuilder/Rtt_AppPackagerFactory.cpp index 2c2c61317..19e064055 100644 --- a/tools/CoronaBuilder/Rtt_AppPackagerFactory.cpp +++ b/tools/CoronaBuilder/Rtt_AppPackagerFactory.cpp @@ -10,6 +10,11 @@ #include "Core/Rtt_Build.h" #include "Rtt_AppPackagerFactory.h" +#if defined(Rtt_LINUX_ENV) +#include +#include +#include +#endif #if defined(CORONABUILDER_ANDROID) #include "Rtt_AndroidAppPackager.h" @@ -394,6 +399,19 @@ AppPackagerFactory::GetResourceDirectory() const return GetResourceDirectoryOSX(); #elif defined(Rtt_WIN_ENV) return GetResourceDirectoryWin(); +#elif defined(Rtt_LINUX_ENV) + // On Linux, resources are alongside the Solar2DBuilder binary in Resources/ + static char resourceDir[PATH_MAX + 1]; + if (resourceDir[0] == '\0') { + ssize_t count = readlink("/proc/self/exe", resourceDir, PATH_MAX); + resourceDir[count] = '\0'; + char *slash = strrchr(resourceDir, '/'); + if (slash) *slash = '\0'; + strncat(resourceDir, "/Resources", PATH_MAX - strlen(resourceDir)); + } + return resourceDir; +#else + return NULL; #endif } diff --git a/tools/CoronaBuilder/main.cpp b/tools/CoronaBuilder/main.cpp index cd6474979..3e47c9a63 100644 --- a/tools/CoronaBuilder/main.cpp +++ b/tools/CoronaBuilder/main.cpp @@ -28,10 +28,12 @@ int main(int argc, const char *argv[]) string skinDir; // setup directory paths - documentsDir.append("/Documents"); - temporaryDir.append("/TemporaryFiles"); - cachesDir.append("/CachedFiles"); - systemCachesDir.append("/.system"); + const char *tmpBase = getenv("TMPDIR"); + if (!tmpBase || tmpBase[0] == '\0') tmpBase = "/tmp"; + documentsDir = std::string(tmpBase) + "/Documents"; + temporaryDir = std::string(tmpBase) + "/TemporaryFiles"; + cachesDir = std::string(tmpBase) + "/CachedFiles"; + systemCachesDir = std::string(tmpBase) + "/.system"; Rtt::LinuxConsolePlatform *platform = new Rtt::LinuxConsolePlatform(pathToApp.c_str(), documentsDir.c_str(), temporaryDir.c_str(), cachesDir.c_str(), systemCachesDir.c_str(), skinDir.c_str(), GetStartupPath(NULL)); Rtt::LinuxPlatformServices services(platform);