From 35a35f066c50ea444a7495cd6946020f081c07b0 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Wed, 7 Oct 2026 14:29:42 +0800 Subject: [PATCH] Android: fixes binaries built via NDK running on Termux --- CMakeLists.txt | 8 ++++++-- src/common/impl/FFPlatform_unix.c | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c8c017da..0223394e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1550,11 +1550,15 @@ if(APPLE AND BINARY_LINK_TYPE STREQUAL "dlopen") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,/opt/homebrew/lib -Wl,-rpath,/usr/local/lib -Wl,-rpath,/opt/local/lib") endif() +# Termux installs the libraries fastfetch dlopens -- freetype among them -- under TARGET_DIR_ROOT, which +# is not on the Android linker's default search path (DT_RUNPATH, LD_LIBRARY_PATH and the default +# namespace). Termux's own clang injects -rpath=$PREFIX/lib into every binary it links, so a build made +# inside Termux finds them; a plain NDK build, which is what the CI does, does not. if(ANDROID) if(CMAKE_SIZEOF_VOID_P EQUAL 8) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,/vendor/lib64 -Wl,-rpath,/system/lib64") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,${TARGET_DIR_ROOT}/lib -Wl,-rpath,/vendor/lib64 -Wl,-rpath,/system/lib64") else() - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,/vendor/lib -Wl,-rpath,/system/lib") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,${TARGET_DIR_ROOT}/lib -Wl,-rpath,/vendor/lib -Wl,-rpath,/system/lib") endif() endif() diff --git a/src/common/impl/FFPlatform_unix.c b/src/common/impl/FFPlatform_unix.c index 45e79543f..de483c463 100644 --- a/src/common/impl/FFPlatform_unix.c +++ b/src/common/impl/FFPlatform_unix.c @@ -333,7 +333,12 @@ static void getCwd(FFPlatform* platform) { void ffPlatformInitImpl(FFPlatform* platform) { platform->pid = (uint32_t) getpid(); platform->uid = getuid(); +#if !__ANDROID__ struct passwd* pwd = getpwuid(platform->uid); +#else + // On Android, /etc/passwd is empty, and getpwuid() will return `/data` for pw_dir + struct passwd* pwd = nullptr; +#endif struct utsname uts; if (uname(&uts) < 0) {