Skip to content

Commit

Permalink
[backport] improve Android compatibility (alibaba#1518)
Browse files Browse the repository at this point in the history
* improve Android compatibility
  • Loading branch information
alph00 committed Aug 7, 2024
1 parent adee668 commit 0f06c8e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions core/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ link_lz4(${PROJECT_NAME})
link_zlib(${PROJECT_NAME})
link_zstd(${PROJECT_NAME})
link_unwind(${PROJECT_NAME})
if (NOT ANDROID)
link_asan(${PROJECT_NAME})
endif()
if (UNIX)
link_uuid(${PROJECT_NAME})
if (LINUX)
Expand Down
7 changes: 6 additions & 1 deletion core/common/RuntimeUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,17 @@
#include "LogtailCommonFlags.h"
#include "FileSystemUtil.h"

DECLARE_FLAG_STRING(logtail_sys_conf_dir);

namespace logtail {

// TODO: In ConfigManager.cpp, some places use / to concat path, which might fail on Windows,
// replace them with PATH_SEPARATOR.
std::string GetProcessExecutionDir(void) {
#if defined(__linux__)
#if defined(__ANDROID__)
// In Android, runtime configuration files cannot be stored in the same directory as the executable
return STRING_FLAG(logtail_sys_conf_dir);
#elif defined(__linux__)
char exePath[PATH_MAX + 1] = "";
readlink("/proc/self/exe", exePath, sizeof(exePath));
std::string fullPath(exePath);
Expand Down
2 changes: 2 additions & 0 deletions core/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ endmacro()
macro(link_zlib target_name)
if (zlib_${LINK_OPTION_SUFFIX})
target_link_libraries(${target_name} "${zlib_${LINK_OPTION_SUFFIX}}")
elseif(ANDROID)
target_link_libraries(${target_name} z)
elseif (UNIX)
target_link_libraries(${target_name} "${zlib_${LIBRARY_DIR_SUFFIX}}/libz.a")
elseif (MSVC)
Expand Down
4 changes: 3 additions & 1 deletion core/logtail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ int main(int argc, char** argv) {
gflags::SetUsageMessage(
std::string("The Lightweight Collector of SLS in Alibaba Cloud\nUsage: ./ilogtail [OPTION]"));
gflags::SetVersionString(std::string(ILOGTAIL_VERSION) + " Community Edition");
google::ParseCommandLineFlags(&argc, &argv, true);
if (argc != 0) {
google::ParseCommandLineFlags(&argc, &argv, true);
}

if (setenv("TCMALLOC_RELEASE_RATE", "10.0", 1) == -1) {
exit(3);
Expand Down

0 comments on commit 0f06c8e

Please sign in to comment.