Merge pull request #718 from a1batross/android_library_naming

Partially implement library naming scheme, and use it on Android
This commit is contained in:
Max 2025-08-04 15:10:08 +03:00 committed by GitHub
commit 85af7c7c63
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 66 additions and 24 deletions

View file

@ -10,9 +10,7 @@ cmake_minimum_required(VERSION 3.5)
project(yapb VERSION 4.5 LANGUAGES CXX)
if(NOT ANDROID)
set(CMAKE_SHARED_MODULE_PREFIX "")
endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

View file

@ -795,11 +795,45 @@ bool Game::loadCSBinary () {
if (modname.empty ()) {
return false;
}
Array <StringRef> libs { "mp", "cs", "cs_i386" };
// lookup for x64 binaries first
Array <String> libs;
// construct library suffix
String lib_suffix;
if (plat.android) {
lib_suffix += "_android";
} else if (plat.psvita) {
lib_suffix += "_psvita";
}
if (plat.x64) {
libs.insert (0, { "mp_amd64", "mp_arm64", "cs_arm64", "cs_amd64" });
if (plat.arm) {
lib_suffix += "_arm64";
} else if (plat.ppc) {
lib_suffix += "_ppc64le";
} else {
lib_suffix += "_amd64";
}
} else {
if (plat.arm) {
// don't want to put whole build.h logic from xash3d, just set whatever is supported by the YaPB
if (plat.android) {
lib_suffix += "_armv7l";
} else {
lib_suffix += "_armv7hf";
}
} else if (!plat.nix && !plat.win && !plat.macos) {
lib_suffix += "_i386";
}
}
if (lib_suffix.empty ())
libs.insert (0, { "mp", "cs", "cs_i386" });
else {
libs.insert (0, { "mp", "cs" });
for (auto &lib: libs) {
lib += lib_suffix;
}
}
auto libCheck = [&] (StringRef mod, StringRef dll) {
@ -818,12 +852,27 @@ bool Game::loadCSBinary () {
// search the libraries inside game dlls directory
for (const auto &lib : libs) {
auto path = strings.joinPath (modname, "dlls", lib) + kLibrarySuffix;
String path;
if (plat.android) {
// this will be removed as soon as mod downloader will be implemented on engine side
auto gamelibdir = plat.env ("XASH3D_GAMELIBDIR");
path = strings.joinPath (gamelibdir, lib) + kLibrarySuffix;
// if we can't read file, skip it
if (!plat.fileExists (path.chars ())) {
path = "";
}
}
if (path.empty()) {
path = strings.joinPath (modname, "dlls", lib) + kLibrarySuffix;
// if we can't read file, skip it
if (!plat.fileExists (path.chars ())) {
continue;
}
}
// special case, czero is always detected first, as it's has custom directory
if (modname == "czero") {
@ -958,13 +1007,8 @@ bool Game::postload () {
if (is (GameFlags::Metamod)) {
return true; // we should stop the attempt for loading the real gamedll, since metamod handle this for us
}
auto gamedll = strings.format ("%s/%s", plat.env ("XASH3D_GAMELIBDIR"), "libserver.so");
}
if (!m_gameLib.load (gamedll)) {
logger.fatal ("Unable to load gamedll \"%s\". Exiting... (gamedir: %s)", gamedll, getRunningModName ());
}
}
else {
const bool binaryLoaded = loadCSBinary ();
if (!binaryLoaded && !is (GameFlags::Metamod)) {
@ -975,7 +1019,7 @@ bool Game::postload () {
m_gameLib.unload ();
return true;
}
}
return false;
}