From 6bdc95478f999309e74249cd886615fe6118d178 Mon Sep 17 00:00:00 2001 From: "xufeihong.xfh" Date: Tue, 10 Feb 2026 17:50:21 +0800 Subject: [PATCH 01/22] init --- .gitignore | 3 +- build_android.sh | 61 +++++++++++++++++++++ cmake/bazel.cmake | 3 + examples/c++/CMakeLists.txt | 26 +++++++++ examples/c++/build_android.sh | 41 ++++++++++++++ src/ailego/CMakeLists.txt | 2 +- thirdparty/arrow/CMakeLists.txt | 54 ++++++++++++------ thirdparty/arrow/arrow.android.patch | 82 ++++++++++++++++++++++++++++ thirdparty/glog/CMakeLists.txt | 9 ++- thirdparty/glog/glog.android.patch | 78 ++++++++++++++++++++++++++ thirdparty/lz4/CMakeLists.txt | 73 +++++++++++++++++++------ 11 files changed, 396 insertions(+), 36 deletions(-) create mode 100644 build_android.sh create mode 100644 examples/c++/build_android.sh create mode 100644 thirdparty/arrow/arrow.android.patch create mode 100644 thirdparty/glog/glog.android.patch diff --git a/.gitignore b/.gitignore index 755089d0..0827e539 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,6 @@ build* bin/* lib/* var/* -thirdparty venv* tests/integration/conf/* tests/de_integration/conf/* @@ -48,3 +47,5 @@ yarn-debug.log* yarn-error.log* allure-* + +!build_android.sh \ No newline at end of file diff --git a/build_android.sh b/build_android.sh new file mode 100644 index 00000000..968db554 --- /dev/null +++ b/build_android.sh @@ -0,0 +1,61 @@ +#!/bin/bash +set -e +CURRENT_DIR=$(pwd) + +ABI=${1:-"arm64-v8a"} +API_LEVEL=${2:-21} +BUILD_TYPE=${3:-"Release"} + +# step1: use host env to compile protoc +echo "step1: building protoc for host..." +HOST_BUILD_DIR="build_host" +mkdir -p $HOST_BUILD_DIR +cd $HOST_BUILD_DIR + +cmake -DCMAKE_BUILD_TYPE="$BUILD_TYPE" .. +make -j protoc +PROTOC_EXECUTABLE=$CURRENT_DIR/$HOST_BUILD_DIR/bin/protoc +cd $CURRENT_DIR + +echo "step1: Done!!!" + +# step2: cross build zvec based on android ndk +echo "step2: building zvec for android..." +export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk +export ANDROID_HOME=$ANDROID_SDK_ROOT +export ANDROID_NDK_HOME=$ANDROID_SDK_ROOT/ndk/28.2.13676358 +export CMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake + +export PATH=$PATH:$ANDROID_SDK_ROOT/cmdline-tools/latest/bin +export PATH=$PATH:$ANDROID_SDK_ROOT/platform-tools +export PATH=$PATH:$ANDROID_NDK_HOME + +if [ -z "$ANDROID_NDK_HOME" ]; then + echo "error: ANDROID_NDK_HOME env not set" + echo "please install NDK and set env variable ANDROID_NDK_HOME" + exit 1 +fi + +BUILD_DIR="build_android_${ABI}_macos" +mkdir -p $BUILD_DIR +cd $BUILD_DIR + +echo "configure CMake..." +cmake \ + -DANDROID_NDK="$ANDROID_NDK_HOME" \ + -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake" \ + -DANDROID_ABI="$ABI" \ + -DANDROID_NATIVE_API_LEVEL="$API_LEVEL" \ + -DANDROID_STL="c++_static" \ + -DCMAKE_BUILD_TYPE="$BUILD_TYPE" \ + -DBUILD_PYTHON_BINDINGS=OFF \ + -DBUILD_TOOLS=OFF \ + -DCMAKE_INSTALL_PREFIX="./install" \ + -DGLOBAL_CC_PROTOBUF_PROTOC=$PROTOC_EXECUTABLE \ + ../ + +echo "building..." +CORE_COUNT=$(sysctl -n hw.ncpu) +make -j$CORE_COUNT + +echo "step2: Done!!!" \ No newline at end of file diff --git a/cmake/bazel.cmake b/cmake/bazel.cmake index deaf1656..f1effc6d 100644 --- a/cmake/bazel.cmake +++ b/cmake/bazel.cmake @@ -1313,6 +1313,9 @@ function(cc_proto_library) _find_protobuf("${CC_ARGS_PROTOBUF_VERSION}") set(CC_PROTOBUF_PROTOC ${CC_PROTOBUF_PROTOC_${CC_ARGS_PROTOBUF_VERSION}}) + if(DEFINED GLOBAL_CC_PROTOBUF_PROTOC) + set(CC_PROTOBUF_PROTOC ${GLOBAL_CC_PROTOBUF_PROTOC}) + endif() set(CC_PROTOBUF_INCS ${CC_PROTOBUF_INCS_${CC_ARGS_PROTOBUF_VERSION}}) set(CC_PROTOBUF_LIBS ${CC_PROTOBUF_LIBS_${CC_ARGS_PROTOBUF_VERSION}}) diff --git a/examples/c++/CMakeLists.txt b/examples/c++/CMakeLists.txt index 0751bf9e..b29dce8e 100644 --- a/examples/c++/CMakeLists.txt +++ b/examples/c++/CMakeLists.txt @@ -84,6 +84,16 @@ elseif(APPLE) zvec-ailego ${zvec_core_deps} ) +elseif(ANDROID) + target_link_libraries(zvec-core INTERFACE + -Wl,--whole-archive + zvec_core + -Wl,--no-whole-archive + -Wl,--start-group + zvec-ailego + ${zvec_core_deps} + -Wl,--end-group + ) else() message(FATAL_ERROR "Unsupported platform: ${CMAKE_SYSTEM_NAME}") endif() @@ -106,6 +116,17 @@ elseif(APPLE) zvec-ailego ${zvec_db_deps} ) +elseif(ANDROID) + target_link_libraries(zvec-db INTERFACE + zvec_db + zvec-core + zvec-ailego + -Wl,--start-group + ${zvec_db_deps} + -Wl,--end-group + ) +else() + message(FATAL_ERROR "Unsupported platform: ${CMAKE_SYSTEM_NAME}") endif() @@ -114,6 +135,11 @@ add_executable(db-example db/main.cc) target_link_libraries(db-example PRIVATE zvec-db ) +if(ANDROID) + target_link_libraries(db-example PRIVATE + log + ) +endif() add_executable(core-example core/main.cc) target_link_libraries(core-example PRIVATE diff --git a/examples/c++/build_android.sh b/examples/c++/build_android.sh new file mode 100644 index 00000000..946f8ed4 --- /dev/null +++ b/examples/c++/build_android.sh @@ -0,0 +1,41 @@ +export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk +export ANDROID_HOME=$ANDROID_SDK_ROOT +export ANDROID_NDK_HOME=$ANDROID_SDK_ROOT/ndk/28.2.13676358 +export CMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake + +export PATH=$PATH:$ANDROID_SDK_ROOT/cmdline-tools/latest/bin +export PATH=$PATH:$ANDROID_SDK_ROOT/platform-tools +export PATH=$PATH:$ANDROID_NDK_HOME + +#!/bin/bash +set -e + +if [ -z "$ANDROID_NDK_HOME" ]; then + echo "error: ANDROID_NDK_HOME env not set" + echo "please install NDK and set env variable ANDROID_NDK_HOME" + exit 1 +fi + +ABI=${1:-"arm64-v8a"} +API_LEVEL=${2:-21} +BUILD_TYPE=${3:-"Release"} + +BUILD_DIR="build_android_${ABI}_macos" +mkdir -p $BUILD_DIR +cd $BUILD_DIR + +echo "configure CMake..." +cmake \ + -DANDROID_NDK="$ANDROID_NDK_HOME" \ + -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake" \ + -DANDROID_ABI="$ABI" \ + -DANDROID_NATIVE_API_LEVEL="$API_LEVEL" \ + -DCMAKE_BUILD_TYPE="$BUILD_TYPE" \ + -DBUILD_PYTHON_BINDINGS=OFF \ + -DBUILD_TOOLS=OFF \ + -DCMAKE_INSTALL_PREFIX="./install" \ + ../ + +echo "building..." +CORE_COUNT=$(sysctl -n hw.ncpu) +make -j$CORE_COUNT diff --git a/src/ailego/CMakeLists.txt b/src/ailego/CMakeLists.txt index b01df973..5fcaacac 100644 --- a/src/ailego/CMakeLists.txt +++ b/src/ailego/CMakeLists.txt @@ -3,7 +3,7 @@ include(${PROJECT_ROOT_DIR}/cmake/option.cmake) find_package(Threads REQUIRED) -if(UNIX AND NOT APPLE) +if(UNIX AND NOT APPLE AND NOT ANDROID) find_library(LIB_RT NAMES rt) else() set(LIB_RT "") diff --git a/thirdparty/arrow/CMakeLists.txt b/thirdparty/arrow/CMakeLists.txt index eb8cad06..19c7e863 100644 --- a/thirdparty/arrow/CMakeLists.txt +++ b/thirdparty/arrow/CMakeLists.txt @@ -1,6 +1,11 @@ set(ARROW_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/apache-arrow-21.0.0) -set(ARROW_PATCH ${CMAKE_CURRENT_SOURCE_DIR}/arrow.patch) -apply_patch_once("arrow_fix" "${ARROW_SRC_DIR}" "${ARROW_PATCH}") +if(ANDROID) + set(ARROW_PATCH ${CMAKE_CURRENT_SOURCE_DIR}/arrow.android.patch) + apply_patch_once("arrow_android_fix" "${ARROW_SRC_DIR}" "${ARROW_PATCH}") +else() + set(ARROW_PATCH ${CMAKE_CURRENT_SOURCE_DIR}/arrow.patch) + apply_patch_once("arrow_fix" "${ARROW_SRC_DIR}" "${ARROW_PATCH}") +endif() include(ExternalProject) include(ProcessorCount) @@ -14,20 +19,37 @@ set(LIB_ACERO ${EXTERNAL_LIB_DIR}/libarrow_acero.a) set(LIB_ARROW_DEPENDS ${EXTERNAL_LIB_DIR}/libarrow_bundled_dependencies.a) set(LIB_ARROW_DATASET ${EXTERNAL_LIB_DIR}/libarrow_dataset.a) -ExternalProject_Add( - ARROW.BUILD PREFIX arrow - SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/apache-arrow-21.0.0 - DOWNLOAD_COMMAND "" - BUILD_IN_SOURCE false - CONFIGURE_COMMAND "${CMAKE_COMMAND}" ${CMAKE_CACHE_ARGS} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_DEBUG_POSTFIX= -DARROW_BUILD_SHARED=OFF -DARROW_ACERO=ON -DARROW_FILESYSTEM=ON -DARROW_DATASET=ON -DARROW_PARQUET=ON -DARROW_COMPUTE=ON -DARROW_WITH_ZLIB=OFF -DARROW_DEPENDENCY_SOURCE=BUNDLED -DARROW_MIMALLOC=OFF -DCMAKE_INSTALL_LIBDIR=lib "/cpp" - BUILD_COMMAND "${CMAKE_COMMAND}" --build . --target all -- -j ${NPROC} - INSTALL_COMMAND "${CMAKE_COMMAND}" --install "" --prefix=${EXTERNAL_BINARY_DIR}/usr/local - BYPRODUCTS ${LIB_PARQUET} ${LIB_ARROW} ${LIB_COMPUTE} ${LIB_ACERO} ${LIB_ARROW_DEPENDS} ${LIB_ARROW_DATASET} - LOG_DOWNLOAD ON - LOG_CONFIGURE ON - LOG_BUILD ON - LOG_INSTALL ON -) +if(ANDROID) + ExternalProject_Add( + ARROW.BUILD PREFIX arrow + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/apache-arrow-21.0.0 + DOWNLOAD_COMMAND "" + BUILD_IN_SOURCE false + CONFIGURE_COMMAND "${CMAKE_COMMAND}" ${CMAKE_CACHE_ARGS} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_DEBUG_POSTFIX= -DARROW_BUILD_SHARED=OFF -DARROW_ACERO=ON -DARROW_FILESYSTEM=ON -DARROW_DATASET=ON -DARROW_PARQUET=ON -DARROW_COMPUTE=ON -DARROW_WITH_ZLIB=OFF -DARROW_DEPENDENCY_SOURCE=BUNDLED -DARROW_MIMALLOC=OFF -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} -DANDROID_ABI=${ANDROID_ABI} -DANDROID_NATIVE_API_LEVEL=${ANDROID_NATIVE_API_LEVEL} -DARROW_WITH_MUSL=OFF "/cpp" + BUILD_COMMAND "${CMAKE_COMMAND}" --build . --target all -- -j ${NPROC} + INSTALL_COMMAND "${CMAKE_COMMAND}" --install "" --prefix=${EXTERNAL_BINARY_DIR}/usr/local + BYPRODUCTS ${LIB_PARQUET} ${LIB_ARROW} ${LIB_COMPUTE} ${LIB_ACERO} ${LIB_ARROW_DEPENDS} ${LIB_ARROW_DATASET} + LOG_DOWNLOAD ON + LOG_CONFIGURE ON + LOG_BUILD ON + LOG_INSTALL ON + ) +else() + ExternalProject_Add( + ARROW.BUILD PREFIX arrow + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/apache-arrow-21.0.0 + DOWNLOAD_COMMAND "" + BUILD_IN_SOURCE false + CONFIGURE_COMMAND "${CMAKE_COMMAND}" ${CMAKE_CACHE_ARGS} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_DEBUG_POSTFIX= -DARROW_BUILD_SHARED=OFF -DARROW_ACERO=ON -DARROW_FILESYSTEM=ON -DARROW_DATASET=ON -DARROW_PARQUET=ON -DARROW_COMPUTE=ON -DARROW_WITH_ZLIB=OFF -DARROW_DEPENDENCY_SOURCE=BUNDLED -DARROW_MIMALLOC=OFF -DCMAKE_INSTALL_LIBDIR=lib "/cpp" + BUILD_COMMAND "${CMAKE_COMMAND}" --build . --target all -- -j ${NPROC} + INSTALL_COMMAND "${CMAKE_COMMAND}" --install "" --prefix=${EXTERNAL_BINARY_DIR}/usr/local + BYPRODUCTS ${LIB_PARQUET} ${LIB_ARROW} ${LIB_COMPUTE} ${LIB_ACERO} ${LIB_ARROW_DEPENDS} ${LIB_ARROW_DATASET} + LOG_DOWNLOAD ON + LOG_CONFIGURE ON + LOG_BUILD ON + LOG_INSTALL ON + ) +endif() add_library(arrow UNKNOWN IMPORTED GLOBAL) add_dependencies(arrow ARROW.BUILD) diff --git a/thirdparty/arrow/arrow.android.patch b/thirdparty/arrow/arrow.android.patch new file mode 100644 index 00000000..a4e8bba2 --- /dev/null +++ b/thirdparty/arrow/arrow.android.patch @@ -0,0 +1,82 @@ +diff --git a/cpp/cmake_modules/ThirdpartyToolchain.cmake b/cpp/cmake_modules/ThirdpartyToolchain.cmake +index 7fa4b66d4b..78bcb6d47e 100644 +--- a/cpp/cmake_modules/ThirdpartyToolchain.cmake ++++ b/cpp/cmake_modules/ThirdpartyToolchain.cmake +@@ -950,6 +950,13 @@ set(EP_COMMON_CMAKE_ARGS + # https://github.com/apache/arrow/issues/45985 + -DCMAKE_POLICY_VERSION_MINIMUM=3.5) + ++if(ANDROID) ++ list(APPEND EP_COMMON_CMAKE_ARGS ++ -DANDROID_ABI=${ANDROID_ABI} ++ -DANDROID_NATIVE_API_LEVEL=${ANDROID_NATIVE_API_LEVEL} ++ -DANDROID_NDK=${ANDROID_NDK}) ++endif() ++ + # if building with a toolchain file, pass that through + if(CMAKE_TOOLCHAIN_FILE) + list(APPEND EP_COMMON_CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}) +diff --git a/cpp/src/arrow/acero/source_node.cc b/cpp/src/arrow/acero/source_node.cc +index 0f58406760..cf68bfdcbe 100644 +--- a/cpp/src/arrow/acero/source_node.cc ++++ b/cpp/src/arrow/acero/source_node.cc +@@ -407,7 +407,7 @@ struct SchemaSourceNode : public SourceNode { + struct RecordBatchReaderSourceNode : public SourceNode { + RecordBatchReaderSourceNode(ExecPlan* plan, std::shared_ptr schema, + arrow::AsyncGenerator> generator) +- : SourceNode(plan, schema, generator) {} ++ : SourceNode(plan, schema, generator, Ordering::Implicit()) {} + + static Result Make(ExecPlan* plan, std::vector inputs, + const ExecNodeOptions& options) { +diff --git a/cpp/src/arrow/vendored/datetime/tz.cpp b/cpp/src/arrow/vendored/datetime/tz.cpp +index 2cf6c62a84..9e64b62297 100644 +--- a/cpp/src/arrow/vendored/datetime/tz.cpp ++++ b/cpp/src/arrow/vendored/datetime/tz.cpp +@@ -605,7 +605,9 @@ tzdb_list + create_tzdb() + { + tzdb_list tz_db; ++#if !defined(ANDROID) && !defined(__ANDROID__) + tzdb_list::undocumented_helper::push_front(tz_db, init_tzdb().release()); ++#endif // !defined(ANDROID) && !defined(__ANDROID__) + return tz_db; + } + +@@ -3900,7 +3902,9 @@ reload_tzdb() + if (!v.empty() && v == remote_version()) + return get_tzdb_list().front(); + #endif // AUTO_DOWNLOAD ++#if !defined(ANDROID) && !defined(__ANDROID__) + tzdb_list::undocumented_helper::push_front(get_tzdb_list(), init_tzdb().release()); ++#endif // !defined(ANDROID) && !defined(__ANDROID__) + return get_tzdb_list().front(); + } + +diff --git a/cpp/src/arrow/vendored/datetime/tz.h b/cpp/src/arrow/vendored/datetime/tz.h +index 61ab3df106..d456d6765f 100644 +--- a/cpp/src/arrow/vendored/datetime/tz.h ++++ b/cpp/src/arrow/vendored/datetime/tz.h +@@ -858,7 +858,9 @@ private: + load_data(std::istream& inf, std::int32_t tzh_leapcnt, std::int32_t tzh_timecnt, + std::int32_t tzh_typecnt, std::int32_t tzh_charcnt); + # if defined(ANDROID) || defined(__ANDROID__) ++public: + void parse_from_android_tzdata(std::ifstream& inf, const std::size_t off); ++private: + # endif // defined(ANDROID) || defined(__ANDROID__) + #else // !USE_OS_TZDB + DATE_API sys_info get_info_impl(sys_seconds tp, int tz_int) const; +diff --git a/cpp/src/arrow/vendored/musl/strptime.c b/cpp/src/arrow/vendored/musl/strptime.c +index 41912fd1bb..9d0b4dc1bf 100644 +--- a/cpp/src/arrow/vendored/musl/strptime.c ++++ b/cpp/src/arrow/vendored/musl/strptime.c +@@ -17,7 +17,7 @@ + + #undef HAVE_LANGINFO + +-#ifndef _WIN32 ++#if !defined(_WIN32) && !defined(__ANDROID__) + #define HAVE_LANGINFO 1 + #endif + diff --git a/thirdparty/glog/CMakeLists.txt b/thirdparty/glog/CMakeLists.txt index 04c1d085..611f18ef 100644 --- a/thirdparty/glog/CMakeLists.txt +++ b/thirdparty/glog/CMakeLists.txt @@ -6,8 +6,13 @@ set(HAVE_LIB_GFLAGS TRUE CACHE BOOL "") add_compile_options(-Wno-deprecated-declarations) set(GLOG_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/glog-0.5.0) -set(GLOG_PATCH ${CMAKE_CURRENT_SOURCE_DIR}/glog.patch) -apply_patch_once("glog_fix" "${GLOG_SRC_DIR}" "${GLOG_PATCH}") +if (ANDROID) + set(GLOG_ANDROID_PATCH ${CMAKE_CURRENT_SOURCE_DIR}/glog.android.patch) + apply_patch_once("glog_android_fix" "${GLOG_SRC_DIR}" "${GLOG_ANDROID_PATCH}") +else() + set(GLOG_PATCH ${CMAKE_CURRENT_SOURCE_DIR}/glog.patch) + apply_patch_once("glog_fix" "${GLOG_SRC_DIR}" "${GLOG_PATCH}") +endif() set(_SAVED_CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${EXTERNAL_LIB_DIR}) diff --git a/thirdparty/glog/glog.android.patch b/thirdparty/glog/glog.android.patch new file mode 100644 index 00000000..7b2d1a31 --- /dev/null +++ b/thirdparty/glog/glog.android.patch @@ -0,0 +1,78 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 62ebbcc..e17f67e 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -17,7 +17,7 @@ set (CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR}) + set (CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH}) + set (CPACK_PACKAGE_VERSION ${PROJECT_VERSION}) + +-option (BUILD_SHARED_LIBS "Build shared libraries" ON) ++option (BUILD_STATIC_LIBS "Build shared libraries" ON) + option (PRINT_UNSYMBOLIZED_STACK_TRACES + "Print file offsets in traces instead of symbolizing" OFF) + option (WITH_CUSTOM_PREFIX "Enable support for user-generated message prefixes" OFF) +@@ -802,12 +802,12 @@ if (BUILD_TESTING) + FIXTURES_REQUIRED "cmake_package_config;cmake_package_config_working") + endif (BUILD_TESTING) + +-install (TARGETS glog +- EXPORT glog-targets +- RUNTIME DESTINATION ${_glog_CMake_BINDIR} +- PUBLIC_HEADER DESTINATION ${_glog_CMake_INCLUDE_DIR}/glog +- LIBRARY DESTINATION ${_glog_CMake_LIBDIR} +- ARCHIVE DESTINATION ${_glog_CMake_LIBDIR}) ++#install (TARGETS glog ++# EXPORT glog-targets ++# RUNTIME DESTINATION ${_glog_CMake_BINDIR} ++# PUBLIC_HEADER DESTINATION ${_glog_CMake_INCLUDE_DIR}/glog ++# LIBRARY DESTINATION ${_glog_CMake_LIBDIR} ++# ARCHIVE DESTINATION ${_glog_CMake_LIBDIR}) + + if (WITH_PKGCONFIG) + install ( +@@ -840,8 +840,8 @@ write_basic_package_version_file ( + ${CMAKE_CURRENT_BINARY_DIR}/glog-config-version.cmake + COMPATIBILITY SameMajorVersion) + +-export (TARGETS glog NAMESPACE glog:: FILE glog-targets.cmake) +-export (PACKAGE glog) ++#export (TARGETS glog NAMESPACE glog:: FILE glog-targets.cmake) ++#export (PACKAGE glog) + + get_filename_component (_PREFIX "${CMAKE_INSTALL_PREFIX}" ABSOLUTE) + +@@ -885,5 +885,5 @@ install (DIRECTORY ${_glog_BINARY_CMake_DATADIR} + FILES_MATCHING PATTERN "*.cmake" + ) + +-install (EXPORT glog-targets NAMESPACE glog:: DESTINATION +- ${_glog_CMake_INSTALLDIR}) ++#install (EXPORT glog-targets NAMESPACE glog:: DESTINATION ++# ${_glog_CMake_INSTALLDIR}) +diff --git a/src/stacktrace_generic-inl.h b/src/stacktrace_generic-inl.h +index fad81d3..67209ac 100644 +--- a/src/stacktrace_generic-inl.h ++++ b/src/stacktrace_generic-inl.h +@@ -39,21 +39,7 @@ _START_GOOGLE_NAMESPACE_ + + // If you change this function, also change GetStackFrames below. + int GetStackTrace(void** result, int max_depth, int skip_count) { +- static const int kStackLength = 64; +- void * stack[kStackLength]; +- int size; +- +- size = backtrace(stack, kStackLength); +- skip_count++; // we want to skip the current frame as well +- int result_count = size - skip_count; +- if (result_count < 0) +- result_count = 0; +- if (result_count > max_depth) +- result_count = max_depth; +- for (int i = 0; i < result_count; i++) +- result[i] = stack[i + skip_count]; +- +- return result_count; ++ return 0; + } + + _END_GOOGLE_NAMESPACE_ diff --git a/thirdparty/lz4/CMakeLists.txt b/thirdparty/lz4/CMakeLists.txt index ad5f96b1..7db62d4f 100644 --- a/thirdparty/lz4/CMakeLists.txt +++ b/thirdparty/lz4/CMakeLists.txt @@ -4,26 +4,67 @@ file(MAKE_DIRECTORY ${lz4_INCLUDE_DIR}) file(MAKE_DIRECTORY ${lz4_LIBRARY_DIR}) include(ExternalProject) -ExternalProject_Add( - Lz4.BUILD - PREFIX lz4 - URL "${CMAKE_CURRENT_SOURCE_DIR}/lz4-1.9.4" - CONFIGURE_COMMAND "" - BUILD_COMMAND env CFLAGS=-fPIC BUILD_SHARED=no make -j - INSTALL_COMMAND make DESTDIR=${EXTERNAL_BINARY_DIR} BUILD_SHARED=no install - BUILD_IN_SOURCE ON - LOG_DOWNLOAD ON - LOG_CONFIGURE ON - LOG_BUILD ON - LOG_INSTALL ON - BUILD_BYPRODUCTS ${lz4_LIBRARY_DIR}/liblz4.a + +set(_lz4_env "") +if(ANDROID) + string(REGEX REPLACE "^android-([0-9]+)$" "\\1" ANDROID_API_LEVEL "${ANDROID_PLATFORM}") + + if(ANDROID_ABI STREQUAL "arm64-v8a") + set(TARGET_TRIPLE "aarch64-linux-android") + elseif(ANDROID_ABI STREQUAL "armeabi-v7a") + set(TARGET_TRIPLE "armv7a-linux-androideabi") + elseif(ANDROID_ABI STREQUAL "x86") + set(TARGET_TRIPLE "i686-linux-android") + elseif(ANDROID_ABI STREQUAL "x86_64") + set(TARGET_TRIPLE "x86_64-linux-android") + else() + message(FATAL_ERROR "Unsupported ANDROID_ABI: ${ANDROID_ABI}") + endif() + + set(SYSROOT "${ANDROID_NDK}/toolchains/llvm/prebuilt/${ANDROID_HOST_TAG}/sysroot") + set(COMMON_FLAGS + "--sysroot=${SYSROOT}" + "-target ${TARGET_TRIPLE}${ANDROID_API_LEVEL}" + "-fPIC" + "-D__ANDROID_API__=${ANDROID_API_LEVEL}" + ) + + list(APPEND COMMON_FLAGS ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE}}) + + string(JOIN " " _lz4_cflags ${COMMON_FLAGS}) + + list(APPEND _lz4_env + "CC=${CMAKE_C_COMPILER}" + "AR=${CMAKE_AR}" + "RANLIB=${CMAKE_RANLIB}" + "STRIP=${ANDROID_NDK}/toolchains/llvm/prebuilt/${ANDROID_HOST_TAG}/bin/llvm-strip" + "CFLAGS=${_lz4_cflags}" ) +else() + list(APPEND _lz4_env "CFLAGS=-fPIC") +endif() + +ExternalProject_Add( + Lz4.BUILD + PREFIX lz4 + URL "${CMAKE_CURRENT_SOURCE_DIR}/lz4-1.9.4" + CONFIGURE_COMMAND "" + BUILD_COMMAND env ${_lz4_env} BUILD_SHARED=no make -j + INSTALL_COMMAND make DESTDIR=${EXTERNAL_BINARY_DIR} BUILD_SHARED=no install + BUILD_IN_SOURCE ON + LOG_DOWNLOAD ON + LOG_CONFIGURE ON + LOG_BUILD ON + LOG_INSTALL ON + BUILD_BYPRODUCTS ${lz4_LIBRARY_DIR}/liblz4.a +) + add_library(lz4 STATIC IMPORTED GLOBAL) set_target_properties( - lz4 PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${lz4_INCLUDE_DIR}" - IMPORTED_LOCATION "${lz4_LIBRARY_DIR}/liblz4.a" + lz4 PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${lz4_INCLUDE_DIR}" + IMPORTED_LOCATION "${lz4_LIBRARY_DIR}/liblz4.a" ) add_dependencies(lz4 Lz4.BUILD) From dde93021930c1a4e1dc59338477c265b6bfdfdf8 Mon Sep 17 00:00:00 2001 From: "xufeihong.xfh" Date: Tue, 10 Feb 2026 18:09:00 +0800 Subject: [PATCH 02/22] fix --- build_android.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build_android.sh b/build_android.sh index 968db554..7a5c40a6 100644 --- a/build_android.sh +++ b/build_android.sh @@ -21,6 +21,10 @@ echo "step1: Done!!!" # step2: cross build zvec based on android ndk echo "step2: building zvec for android..." + +# reset thirdparty directory +git submodule foreach --recursive 'git stash --include-untracked' + export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk export ANDROID_HOME=$ANDROID_SDK_ROOT export ANDROID_NDK_HOME=$ANDROID_SDK_ROOT/ndk/28.2.13676358 From 7fad00234847d914fa6b9d4dc81a90a8e7fbdf42 Mon Sep 17 00:00:00 2001 From: "xufeihong.xfh" Date: Tue, 10 Feb 2026 20:26:11 +0800 Subject: [PATCH 03/22] fix ruff ignore --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index dee6728d..051bb136 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -182,6 +182,7 @@ exclude = [ ".git/", ".venv/", "venv/", + "thirdparty", ] [tool.ruff.lint] From 902b6efc25b2f30a28686a8734177c34cb540e9f Mon Sep 17 00:00:00 2001 From: "xufeihong.xfh" Date: Tue, 10 Feb 2026 20:54:14 +0800 Subject: [PATCH 04/22] add android ci --- .github/workflows/android_build.yml | 72 +++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 .github/workflows/android_build.yml diff --git a/.github/workflows/android_build.yml b/.github/workflows/android_build.yml new file mode 100644 index 00000000..d624768d --- /dev/null +++ b/.github/workflows/android_build.yml @@ -0,0 +1,72 @@ +name: android-cross-build + +on: + push: + branches: [ "main" ] + paths-ignore: + - '**.md' + merge_group: + pull_request: + branches: [ "main" ] + paths-ignore: + - '**.md' + workflow_dispatch: + +jobs: + build-android: + runs-on: ubuntu-22.04 + strategy: + fail-fast: false + matrix: + # abi: [arm64-v8a, armeabi-v7a, x86_64] + abi: [arm64-v8a] + api: [21] + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y --no-install-recommends \ + cmake ninja-build git ca-certificates python3 \ + build-essential make + + - name: Setup Android NDK + uses: android-actions/setup-android@v3 + + - name: Install NDK (side by side) + shell: bash + run: | + yes | sdkmanager --licenses + sdkmanager "ndk;26.1.10909125" + + - name: Use host env to compile protoc + shell: bash + run: | + cmake -S . -B build-host -G Ninja + cmake --build build-host --target protoc --parallel + + - name: Configure (CMake) + shell: bash + run: | + git submodule foreach --recursive 'git stash --include-untracked' + + export ANDROID_SDK_ROOT="$ANDROID_HOME" + export ANDROID_NDK_HOME="$ANDROID_SDK_ROOT/ndk/26.1.10909125" + + cmake -S . -B build-android-${{ matrix.abi }} -G Ninja \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake" \ + -DANDROID_ABI=${{ matrix.abi }} \ + -DANDROID_PLATFORM=android-${{ matrix.api }} \ + -DANDROID_STL=c++_shared \ + -DBUILD_PYTHON_BINDINGS=OFF \ + -DBUILD_TOOLS=OFF \ + -DGLOBAL_CC_PROTOBUF_PROTOC=build-host/bin/protoc \ + + - name: Build + shell: bash + run: | + cmake --build build-android-${{ matrix.abi }} --parallel From 632a819caa258f89266b09e836106a963be7b605 Mon Sep 17 00:00:00 2001 From: "xufeihong.xfh" Date: Tue, 10 Feb 2026 20:59:30 +0800 Subject: [PATCH 05/22] fix --- .github/workflows/android_build.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/android_build.yml b/.github/workflows/android_build.yml index d624768d..6fcdd669 100644 --- a/.github/workflows/android_build.yml +++ b/.github/workflows/android_build.yml @@ -33,14 +33,20 @@ jobs: cmake ninja-build git ca-certificates python3 \ build-essential make + - name: Setup Java 17 + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: '17' + - name: Setup Android NDK uses: android-actions/setup-android@v3 - name: Install NDK (side by side) shell: bash run: | - yes | sdkmanager --licenses - sdkmanager "ndk;26.1.10909125" + yes | sdkmanager --licenses + sdkmanager "ndk;26.1.10909125" - name: Use host env to compile protoc shell: bash From a49cb0030841c19a596c2ce1dec538e89805cdcc Mon Sep 17 00:00:00 2001 From: "xufeihong.xfh" Date: Tue, 10 Feb 2026 21:05:39 +0800 Subject: [PATCH 06/22] fix --- .github/workflows/android_build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/android_build.yml b/.github/workflows/android_build.yml index 6fcdd669..c21f9a86 100644 --- a/.github/workflows/android_build.yml +++ b/.github/workflows/android_build.yml @@ -45,7 +45,7 @@ jobs: - name: Install NDK (side by side) shell: bash run: | - yes | sdkmanager --licenses + # yes | sdkmanager --licenses sdkmanager "ndk;26.1.10909125" - name: Use host env to compile protoc From 8146a6c7463289fe8dc7fd81bf3bee7a0f830d68 Mon Sep 17 00:00:00 2001 From: "xufeihong.xfh" Date: Tue, 10 Feb 2026 21:08:51 +0800 Subject: [PATCH 07/22] fix --- .github/workflows/android_build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/android_build.yml b/.github/workflows/android_build.yml index c21f9a86..a54e9ff8 100644 --- a/.github/workflows/android_build.yml +++ b/.github/workflows/android_build.yml @@ -51,6 +51,7 @@ jobs: - name: Use host env to compile protoc shell: bash run: | + git submodule update --init cmake -S . -B build-host -G Ninja cmake --build build-host --target protoc --parallel From d2fddc13d088ad00e7dfc02796fecf5ebdd0ca39 Mon Sep 17 00:00:00 2001 From: "xufeihong.xfh" Date: Tue, 10 Feb 2026 21:41:08 +0800 Subject: [PATCH 08/22] fix --- .github/workflows/android_build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/android_build.yml b/.github/workflows/android_build.yml index a54e9ff8..667975e7 100644 --- a/.github/workflows/android_build.yml +++ b/.github/workflows/android_build.yml @@ -71,7 +71,7 @@ jobs: -DANDROID_STL=c++_shared \ -DBUILD_PYTHON_BINDINGS=OFF \ -DBUILD_TOOLS=OFF \ - -DGLOBAL_CC_PROTOBUF_PROTOC=build-host/bin/protoc \ + -DGLOBAL_CC_PROTOBUF_PROTOC="$GITHUB_WORKSPACE/build-host/bin/protoc" \ - name: Build shell: bash From 9c6c0ca5c260ac9d4ffd4c31c19d3b2d6b3e3043 Mon Sep 17 00:00:00 2001 From: "xufeihong.xfh" Date: Wed, 11 Feb 2026 11:19:16 +0800 Subject: [PATCH 09/22] add adb shell --- .github/workflows/android_build.yml | 46 +++++++++++++++++++++++++++++ build_android.sh | 2 +- examples/c++/CMakeLists.txt | 9 ++++-- examples/c++/build_android.sh | 4 +-- 4 files changed, 55 insertions(+), 6 deletions(-) diff --git a/.github/workflows/android_build.yml b/.github/workflows/android_build.yml index 667975e7..ae0bc9f8 100644 --- a/.github/workflows/android_build.yml +++ b/.github/workflows/android_build.yml @@ -77,3 +77,49 @@ jobs: shell: bash run: | cmake --build build-android-${{ matrix.abi }} --parallel + + - name: Build examples + shell: bash + run: | + cd examples/c++ + + cmake -S . -B build-android-examples-${{ matrix.abi }} -D Ninja \ + -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake" \ + -DANDROID_ABI=${{ matrix.abi }} \ + -DANDROID_PLATFORM=android-${{ matrix.api }} \ + -DANDROID_STL=c++_shared \ + -DCMAKE_BUILD_TYPE=Release \ + -DHOST_BUILD_DIR="build-android-${{ matrix.abi }}" \ + + cmake --build build-android-examples-${{ matrix.abi }} --parallel + + - name: Install ADB and setup Android emulator + uses: reactivecircus/android-emulator-runner@v2 + with: + api-level: ${{ matrix.api }} + abi: ${{ matrix.abi }} + script: | + # Wait for device to be ready + adb wait-for-device + + # Push executables to device + adb push examples/c++/build-android-examples-${{ matrix.abi }}/ailego-example /data/local/tmp/ + adb push examples/c++/build-android-examples-${{ matrix.abi }}/core-example /data/local/tmp/ + adb push examples/c++/build-android-examples-${{ matrix.abi }}/db-example /data/local/tmp/ + + # Make executables executable + adb shell chmod +x /data/local/tmp/ailego-example + adb shell chmod +x /data/local/tmp/core-example + adb shell chmod +x /data/local/tmp/db-example + + echo "Running ailego example:" + adb shell 'cd /data/local/tmp/ && ./ailego-example' + echo "Exit code: $?" + + echo "Running core example:" + adb shell 'cd /data/local/tmp/ && ./core-example' + echo "Exit code: $?" + + echo "Running db example:" + adb shell 'cd /data/local/tmp/ && ./db-example' + echo "Exit code: $?" diff --git a/build_android.sh b/build_android.sh index 7a5c40a6..80ff80cd 100644 --- a/build_android.sh +++ b/build_android.sh @@ -40,7 +40,7 @@ if [ -z "$ANDROID_NDK_HOME" ]; then exit 1 fi -BUILD_DIR="build_android_${ABI}_macos" +BUILD_DIR="build_android_${ABI}" mkdir -p $BUILD_DIR cd $BUILD_DIR diff --git a/examples/c++/CMakeLists.txt b/examples/c++/CMakeLists.txt index b29dce8e..13d6711c 100644 --- a/examples/c++/CMakeLists.txt +++ b/examples/c++/CMakeLists.txt @@ -7,9 +7,14 @@ set(CMAKE_CXX_STANDARD 17) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # --- Paths to Zvec and dependencies --- +# Allow custom host build directory, default to "build" +if(NOT DEFINED HOST_BUILD_DIR) + set(HOST_BUILD_DIR "build") +endif() + set(ZVEC_INCLUDE_DIR ${CMAKE_BINARY_DIR}/../../../src/include) -set(ZVEC_LIB_DIR ${CMAKE_BINARY_DIR}/../../../build/lib) -set(ZVEC_DEPENDENCY_LIB_DIR ${CMAKE_BINARY_DIR}/../../../build/external/usr/local/lib) +set(ZVEC_LIB_DIR ${CMAKE_BINARY_DIR}/../../../${HOST_BUILD_DIR}/lib) +set(ZVEC_DEPENDENCY_LIB_DIR ${CMAKE_BINARY_DIR}/../../../${HOST_BUILD_DIR}/external/usr/local/lib) # Add include and library search paths include_directories(${ZVEC_INCLUDE_DIR}) diff --git a/examples/c++/build_android.sh b/examples/c++/build_android.sh index 946f8ed4..64409c34 100644 --- a/examples/c++/build_android.sh +++ b/examples/c++/build_android.sh @@ -31,9 +31,7 @@ cmake \ -DANDROID_ABI="$ABI" \ -DANDROID_NATIVE_API_LEVEL="$API_LEVEL" \ -DCMAKE_BUILD_TYPE="$BUILD_TYPE" \ - -DBUILD_PYTHON_BINDINGS=OFF \ - -DBUILD_TOOLS=OFF \ - -DCMAKE_INSTALL_PREFIX="./install" \ + -DHOST_BUILD_DIR="build_android_${ABI}" \ ../ echo "building..." From 157a2bc014fa84e118d4c45b587d16aab9b0e354 Mon Sep 17 00:00:00 2001 From: "xufeihong.xfh" Date: Wed, 11 Feb 2026 11:48:07 +0800 Subject: [PATCH 10/22] add cache --- .github/workflows/android_build.yml | 104 ++++++++++++++++++++++------ 1 file changed, 81 insertions(+), 23 deletions(-) diff --git a/.github/workflows/android_build.yml b/.github/workflows/android_build.yml index ae0bc9f8..0c4f13c3 100644 --- a/.github/workflows/android_build.yml +++ b/.github/workflows/android_build.yml @@ -26,12 +26,21 @@ jobs: - name: Checkout uses: actions/checkout@v4 + - name: Cache dependencies + uses: actions/cache@v3 + with: + path: | + ~/.ccache + key: ${{ runner.os }}-dependencies-cache-${{ hashFiles('**/CMakeLists.txt', 'thirdparty/**') }} + restore-keys: | + ${{ runner.os }}-dependencies-cache- + - name: Install dependencies run: | sudo apt-get update sudo apt-get install -y --no-install-recommends \ cmake ninja-build git ca-certificates python3 \ - build-essential make + build-essential make ccache - name: Setup Java 17 uses: actions/setup-java@v4 @@ -48,12 +57,39 @@ jobs: # yes | sdkmanager --licenses sdkmanager "ndk;26.1.10909125" + - name: Cache host protoc build + uses: actions/cache@v3 + with: + path: build-host + key: ${{ runner.os }}-host-protoc-${{ hashFiles('src/**', 'CMakeLists.txt') }} + restore-keys: | + ${{ runner.os }}-host-protoc- + - name: Use host env to compile protoc shell: bash run: | git submodule update --init - cmake -S . -B build-host -G Ninja - cmake --build build-host --target protoc --parallel + if [ ! -d "build-host" ]; then + # Setup ccache for host build + export CCACHE_BASEDIR="$GITHUB_WORKSPACE" + export CCACHE_NOHASHDIR=1 + export CCACHE_SLOPPINESS=clang_index_store,file_stat_matches,include_file_mtime,locale,time_macros + + cmake -S . -B build-host -G Ninja \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache + cmake --build build-host --target protoc --parallel + else + echo "Using cached host protoc build" + fi + + - name: Cache Android build + uses: actions/cache@v3 + with: + path: build-android-${{ matrix.abi }} + key: ${{ runner.os }}-android-build-${{ matrix.abi }}-${{ hashFiles('src/**', 'CMakeLists.txt', 'cmake/**') }} + restore-keys: | + ${{ runner.os }}-android-build-${{ matrix.abi }}- - name: Configure (CMake) shell: bash @@ -63,35 +99,57 @@ jobs: export ANDROID_SDK_ROOT="$ANDROID_HOME" export ANDROID_NDK_HOME="$ANDROID_SDK_ROOT/ndk/26.1.10909125" - cmake -S . -B build-android-${{ matrix.abi }} -G Ninja \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake" \ - -DANDROID_ABI=${{ matrix.abi }} \ - -DANDROID_PLATFORM=android-${{ matrix.api }} \ - -DANDROID_STL=c++_shared \ - -DBUILD_PYTHON_BINDINGS=OFF \ - -DBUILD_TOOLS=OFF \ - -DGLOBAL_CC_PROTOBUF_PROTOC="$GITHUB_WORKSPACE/build-host/bin/protoc" \ + # Setup ccache + export CCACHE_BASEDIR="$GITHUB_WORKSPACE" + export CCACHE_NOHASHDIR=1 + export CCACHE_SLOPPINESS=clang_index_store,file_stat_matches,include_file_mtime,locale,time_macros + + if [ ! -d "build-android-${{ matrix.abi }}" ]; then + cmake -S . -B build-android-${{ matrix.abi }} -G Ninja \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake" \ + -DANDROID_ABI=${{ matrix.abi }} \ + -DANDROID_PLATFORM=android-${{ matrix.api }} \ + -DANDROID_STL=c++_shared \ + -DBUILD_PYTHON_BINDINGS=OFF \ + -DBUILD_TOOLS=OFF \ + -DGLOBAL_CC_PROTOBUF_PROTOC="$GITHUB_WORKSPACE/build-host/bin/protoc" \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ + else + echo "Using cached Android build directory" + fi - name: Build shell: bash run: | cmake --build build-android-${{ matrix.abi }} --parallel + - name: Cache examples build + uses: actions/cache@v3 + with: + path: examples/c++/build-android-examples-${{ matrix.abi }} + key: ${{ runner.os }}-examples-build-${{ matrix.abi }}-${{ hashFiles('examples/c++/**', 'CMakeLists.txt', 'src/**') }} + restore-keys: | + ${{ runner.os }}-examples-build-${{ matrix.abi }}- + - name: Build examples shell: bash run: | - cd examples/c++ - - cmake -S . -B build-android-examples-${{ matrix.abi }} -D Ninja \ - -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake" \ - -DANDROID_ABI=${{ matrix.abi }} \ - -DANDROID_PLATFORM=android-${{ matrix.api }} \ - -DANDROID_STL=c++_shared \ - -DCMAKE_BUILD_TYPE=Release \ - -DHOST_BUILD_DIR="build-android-${{ matrix.abi }}" \ - - cmake --build build-android-examples-${{ matrix.abi }} --parallel + if [ ! -d "examples/c++/build-android-examples-${{ matrix.abi }}" ]; then + cmake -S examples/c++ -B examples/c++/build-android-examples-${{ matrix.abi }} -G Ninja \ + -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake" \ + -DANDROID_ABI=${{ matrix.abi }} \ + -DANDROID_PLATFORM=android-${{ matrix.api }} \ + -DANDROID_STL=c++_shared \ + -DCMAKE_BUILD_TYPE=Release \ + -DHOST_BUILD_DIR="build-android-${{ matrix.abi }}" \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ + cmake --build examples/c++/build-android-examples-${{ matrix.abi }} --parallel + else + echo "Using cached examples build" + fi - name: Install ADB and setup Android emulator uses: reactivecircus/android-emulator-runner@v2 From 6af5c6341779539bce8531c080abb2ebdeadf086 Mon Sep 17 00:00:00 2001 From: "xufeihong.xfh" Date: Wed, 11 Feb 2026 12:39:11 +0800 Subject: [PATCH 11/22] fix --- .github/workflows/android_build.yml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/android_build.yml b/.github/workflows/android_build.yml index 0c4f13c3..a5efa721 100644 --- a/.github/workflows/android_build.yml +++ b/.github/workflows/android_build.yml @@ -91,7 +91,7 @@ jobs: restore-keys: | ${{ runner.os }}-android-build-${{ matrix.abi }}- - - name: Configure (CMake) + - name: Configure and Build shell: bash run: | git submodule foreach --recursive 'git stash --include-untracked' @@ -115,15 +115,12 @@ jobs: -DBUILD_TOOLS=OFF \ -DGLOBAL_CC_PROTOBUF_PROTOC="$GITHUB_WORKSPACE/build-host/bin/protoc" \ -DCMAKE_C_COMPILER_LAUNCHER=ccache \ - -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache + cmake --build build-android-${{ matrix.abi }} --parallel else echo "Using cached Android build directory" fi - - name: Build - shell: bash - run: | - cmake --build build-android-${{ matrix.abi }} --parallel - name: Cache examples build uses: actions/cache@v3 @@ -145,7 +142,7 @@ jobs: -DCMAKE_BUILD_TYPE=Release \ -DHOST_BUILD_DIR="build-android-${{ matrix.abi }}" \ -DCMAKE_C_COMPILER_LAUNCHER=ccache \ - -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache cmake --build examples/c++/build-android-examples-${{ matrix.abi }} --parallel else echo "Using cached examples build" From 4a24d0eecac50bc4fe4dffd725c8cec514149826 Mon Sep 17 00:00:00 2001 From: "xufeihong.xfh" Date: Wed, 11 Feb 2026 14:52:32 +0800 Subject: [PATCH 12/22] add strip --- .github/workflows/android_build.yml | 1 + examples/c++/CMakeLists.txt | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/.github/workflows/android_build.yml b/.github/workflows/android_build.yml index a5efa721..ba537cc8 100644 --- a/.github/workflows/android_build.yml +++ b/.github/workflows/android_build.yml @@ -140,6 +140,7 @@ jobs: -DANDROID_PLATFORM=android-${{ matrix.api }} \ -DANDROID_STL=c++_shared \ -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON \ -DHOST_BUILD_DIR="build-android-${{ matrix.abi }}" \ -DCMAKE_C_COMPILER_LAUNCHER=ccache \ -DCMAKE_CXX_COMPILER_LAUNCHER=ccache diff --git a/examples/c++/CMakeLists.txt b/examples/c++/CMakeLists.txt index 13d6711c..37d42d60 100644 --- a/examples/c++/CMakeLists.txt +++ b/examples/c++/CMakeLists.txt @@ -155,3 +155,24 @@ add_executable(ailego-example ailego/main.cc) target_link_libraries(ailego-example PRIVATE zvec-ailego ) + +# Strip symbols to reduce executable size +if(CMAKE_BUILD_TYPE STREQUAL "Release" OR ANDROID) + add_custom_command(TARGET db-example POST_BUILD + COMMAND ${CMAKE_STRIP} "$" + COMMENT "Stripping symbols from db-example") + add_custom_command(TARGET core-example POST_BUILD + COMMAND ${CMAKE_STRIP} "$" + COMMENT "Stripping symbols from core-example") + add_custom_command(TARGET ailego-example POST_BUILD + COMMAND ${CMAKE_STRIP} "$" + COMMENT "Stripping symbols from ailego-example") +endif() + +# Optimize for size +if(CMAKE_BUILD_TYPE STREQUAL "Release" OR ANDROID) + set_property(TARGET db-example core-example ailego-example + PROPERTY COMPILE_FLAGS "-Os") + set_property(TARGET db-example core-example ailego-example + PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) +endif() From 258c701fc3a8582e92870c35a17f2694304fd050 Mon Sep 17 00:00:00 2001 From: "xufeihong.xfh" Date: Wed, 11 Feb 2026 15:46:04 +0800 Subject: [PATCH 13/22] fix --- .github/workflows/android_build.yml | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/.github/workflows/android_build.yml b/.github/workflows/android_build.yml index ba537cc8..955f140f 100644 --- a/.github/workflows/android_build.yml +++ b/.github/workflows/android_build.yml @@ -158,24 +158,34 @@ jobs: # Wait for device to be ready adb wait-for-device + # Check file sizes before pushing + echo "Checking binary sizes:" + ls -lah examples/c++/build-android-examples-${{ matrix.abi }}/ + # Push executables to device adb push examples/c++/build-android-examples-${{ matrix.abi }}/ailego-example /data/local/tmp/ adb push examples/c++/build-android-examples-${{ matrix.abi }}/core-example /data/local/tmp/ adb push examples/c++/build-android-examples-${{ matrix.abi }}/db-example /data/local/tmp/ # Make executables executable - adb shell chmod +x /data/local/tmp/ailego-example - adb shell chmod +x /data/local/tmp/core-example - adb shell chmod +x /data/local/tmp/db-example + adb shell 'chmod 755 /data/local/tmp/ailego-example' + adb shell 'chmod 755 /data/local/tmp/core-example' + adb shell 'chmod 755 /data/local/tmp/db-example' + + # Verify file integrity + echo "File info on device:" + adb shell 'ls -la /data/local/tmp/ailego-example' + adb shell 'ls -la /data/local/tmp/core-example' + adb shell 'ls -la /data/local/tmp/db-example' echo "Running ailego example:" - adb shell 'cd /data/local/tmp/ && ./ailego-example' + adb shell 'cd /data/local/tmp && chmod +x ailego-example && ./ailego-example' echo "Exit code: $?" echo "Running core example:" - adb shell 'cd /data/local/tmp/ && ./core-example' + adb shell 'cd /data/local/tmp && chmod +x core-example && ./core-example' echo "Exit code: $?" echo "Running db example:" - adb shell 'cd /data/local/tmp/ && ./db-example' + adb shell 'cd /data/local/tmp && chmod +x db-example && ./db-example' echo "Exit code: $?" From 5708305e5a359c1597ecd2c29154b9b806068d1d Mon Sep 17 00:00:00 2001 From: "xufeihong.xfh" Date: Wed, 11 Feb 2026 16:25:49 +0800 Subject: [PATCH 14/22] fix --- .github/workflows/android_build.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/android_build.yml b/.github/workflows/android_build.yml index 955f140f..0793e6b3 100644 --- a/.github/workflows/android_build.yml +++ b/.github/workflows/android_build.yml @@ -179,13 +179,13 @@ jobs: adb shell 'ls -la /data/local/tmp/db-example' echo "Running ailego example:" - adb shell 'cd /data/local/tmp && chmod +x ailego-example && ./ailego-example' + adb shell 'cd /data/local/tmp && ./ailego-example' echo "Exit code: $?" echo "Running core example:" - adb shell 'cd /data/local/tmp && chmod +x core-example && ./core-example' + adb shell 'cd /data/local/tmp && ./core-example' echo "Exit code: $?" echo "Running db example:" - adb shell 'cd /data/local/tmp && chmod +x db-example && ./db-example' + adb shell 'cd /data/local/tmp && ./db-example' echo "Exit code: $?" From cbeda2df80d02de44768848f9274e89a85cd807d Mon Sep 17 00:00:00 2001 From: "xufeihong.xfh" Date: Wed, 11 Feb 2026 16:36:34 +0800 Subject: [PATCH 15/22] debug --- .github/workflows/android_build.yml | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/.github/workflows/android_build.yml b/.github/workflows/android_build.yml index 0793e6b3..70d335ee 100644 --- a/.github/workflows/android_build.yml +++ b/.github/workflows/android_build.yml @@ -162,15 +162,33 @@ jobs: echo "Checking binary sizes:" ls -lah examples/c++/build-android-examples-${{ matrix.abi }}/ + # Check device architecture + echo "Device architecture info:" + adb shell getprop ro.product.cpu.abi + adb shell getprop ro.product.cpu.abilist + adb shell uname -m + + # Check binary architecture (requires file command) + echo "Checking if file command is available:" + if command -v file >/dev/null 2>&1; then + file examples/c++/build-android-examples-${{ matrix.abi }}/ailego-example + file examples/c++/build-android-examples-${{ matrix.abi }}/core-example + file examples/c++/build-android-examples-${{ matrix.abi }}/db-example + else + echo "file command not available on host" + # Check ELF header manually + hexdump -C examples/c++/build-android-examples-${{ matrix.abi }}/ailego-example | head -1 + fi + # Push executables to device adb push examples/c++/build-android-examples-${{ matrix.abi }}/ailego-example /data/local/tmp/ adb push examples/c++/build-android-examples-${{ matrix.abi }}/core-example /data/local/tmp/ adb push examples/c++/build-android-examples-${{ matrix.abi }}/db-example /data/local/tmp/ # Make executables executable - adb shell 'chmod 755 /data/local/tmp/ailego-example' - adb shell 'chmod 755 /data/local/tmp/core-example' - adb shell 'chmod 755 /data/local/tmp/db-example' + adb shell 'chmod a+x /data/local/tmp/ailego-example' + adb shell 'chmod a+x /data/local/tmp/core-example' + adb shell 'chmod a+x /data/local/tmp/db-example' # Verify file integrity echo "File info on device:" From d9100569230c80758efcb5411d7666b810bc41de Mon Sep 17 00:00:00 2001 From: "xufeihong.xfh" Date: Thu, 12 Feb 2026 10:26:37 +0800 Subject: [PATCH 16/22] fix --- .github/workflows/android_build.yml | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/.github/workflows/android_build.yml b/.github/workflows/android_build.yml index 70d335ee..b7ffc7a6 100644 --- a/.github/workflows/android_build.yml +++ b/.github/workflows/android_build.yml @@ -153,7 +153,10 @@ jobs: uses: reactivecircus/android-emulator-runner@v2 with: api-level: ${{ matrix.api }} - abi: ${{ matrix.abi }} + arch: ${{ matrix.abi }} + target: google_apis + emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim + disable-animations: true script: | # Wait for device to be ready adb wait-for-device @@ -164,21 +167,8 @@ jobs: # Check device architecture echo "Device architecture info:" - adb shell getprop ro.product.cpu.abi - adb shell getprop ro.product.cpu.abilist - adb shell uname -m - - # Check binary architecture (requires file command) - echo "Checking if file command is available:" - if command -v file >/dev/null 2>&1; then - file examples/c++/build-android-examples-${{ matrix.abi }}/ailego-example - file examples/c++/build-android-examples-${{ matrix.abi }}/core-example - file examples/c++/build-android-examples-${{ matrix.abi }}/db-example - else - echo "file command not available on host" - # Check ELF header manually - hexdump -C examples/c++/build-android-examples-${{ matrix.abi }}/ailego-example | head -1 - fi + adb shell 'getprop ro.product.cpu.abi' + adb shell 'getprop ro.product.cpu.abilist' # Push executables to device adb push examples/c++/build-android-examples-${{ matrix.abi }}/ailego-example /data/local/tmp/ From a6df4ce0a5355da189687611be26be370be1be7f Mon Sep 17 00:00:00 2001 From: "xufeihong.xfh" Date: Thu, 12 Feb 2026 11:13:50 +0800 Subject: [PATCH 17/22] fix --- .github/workflows/android_build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/android_build.yml b/.github/workflows/android_build.yml index b7ffc7a6..394014bb 100644 --- a/.github/workflows/android_build.yml +++ b/.github/workflows/android_build.yml @@ -19,7 +19,7 @@ jobs: fail-fast: false matrix: # abi: [arm64-v8a, armeabi-v7a, x86_64] - abi: [arm64-v8a] + abi: [x86_64] api: [21] steps: From b0b0afa0b2375f24dafd9ce82eeb5889f56ec11a Mon Sep 17 00:00:00 2001 From: "xufeihong.xfh" Date: Thu, 12 Feb 2026 15:01:31 +0800 Subject: [PATCH 18/22] fix --- .github/workflows/android_build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/android_build.yml b/.github/workflows/android_build.yml index 394014bb..c79568ba 100644 --- a/.github/workflows/android_build.yml +++ b/.github/workflows/android_build.yml @@ -155,8 +155,8 @@ jobs: api-level: ${{ matrix.api }} arch: ${{ matrix.abi }} target: google_apis - emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim - disable-animations: true + # emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim + # disable-animations: true script: | # Wait for device to be ready adb wait-for-device From b6221ec1559a5a14edb8dfe47ee75c588464c386 Mon Sep 17 00:00:00 2001 From: "xufeihong.xfh" Date: Thu, 12 Feb 2026 15:39:06 +0800 Subject: [PATCH 19/22] fix --- .github/workflows/android_build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/android_build.yml b/.github/workflows/android_build.yml index c79568ba..937cf6d6 100644 --- a/.github/workflows/android_build.yml +++ b/.github/workflows/android_build.yml @@ -154,7 +154,7 @@ jobs: with: api-level: ${{ matrix.api }} arch: ${{ matrix.abi }} - target: google_apis + # target: google_apis # emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim # disable-animations: true script: | From c657d4ca1576f7d03f94da8d82a4b158a13bd37a Mon Sep 17 00:00:00 2001 From: "xufeihong.xfh" Date: Thu, 12 Feb 2026 16:19:37 +0800 Subject: [PATCH 20/22] fix --- .github/workflows/android_build.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/android_build.yml b/.github/workflows/android_build.yml index 937cf6d6..2f7fed15 100644 --- a/.github/workflows/android_build.yml +++ b/.github/workflows/android_build.yml @@ -110,7 +110,7 @@ jobs: -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake" \ -DANDROID_ABI=${{ matrix.abi }} \ -DANDROID_PLATFORM=android-${{ matrix.api }} \ - -DANDROID_STL=c++_shared \ + -DANDROID_STL=c++_static \ -DBUILD_PYTHON_BINDINGS=OFF \ -DBUILD_TOOLS=OFF \ -DGLOBAL_CC_PROTOBUF_PROTOC="$GITHUB_WORKSPACE/build-host/bin/protoc" \ @@ -138,7 +138,7 @@ jobs: -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake" \ -DANDROID_ABI=${{ matrix.abi }} \ -DANDROID_PLATFORM=android-${{ matrix.api }} \ - -DANDROID_STL=c++_shared \ + -DANDROID_STL=c++_static \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON \ -DHOST_BUILD_DIR="build-android-${{ matrix.abi }}" \ @@ -176,9 +176,9 @@ jobs: adb push examples/c++/build-android-examples-${{ matrix.abi }}/db-example /data/local/tmp/ # Make executables executable - adb shell 'chmod a+x /data/local/tmp/ailego-example' - adb shell 'chmod a+x /data/local/tmp/core-example' - adb shell 'chmod a+x /data/local/tmp/db-example' + adb shell 'chmod 755 /data/local/tmp/ailego-example' + adb shell 'chmod 755 /data/local/tmp/core-example' + adb shell 'chmod 755 /data/local/tmp/db-example' # Verify file integrity echo "File info on device:" From f711c07c2a5961a05abdfcb5db84f630fe825f9e Mon Sep 17 00:00:00 2001 From: "xufeihong.xfh" Date: Thu, 12 Feb 2026 16:39:45 +0800 Subject: [PATCH 21/22] fix --- .github/workflows/android_build.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/android_build.yml b/.github/workflows/android_build.yml index 2f7fed15..e249825f 100644 --- a/.github/workflows/android_build.yml +++ b/.github/workflows/android_build.yml @@ -31,7 +31,7 @@ jobs: with: path: | ~/.ccache - key: ${{ runner.os }}-dependencies-cache-${{ hashFiles('**/CMakeLists.txt', 'thirdparty/**') }} + key: ${{ runner.os }}-dependencies-cache-${{ hashFiles('**/CMakeLists.txt', 'thirdparty/**') }}-stl-fix restore-keys: | ${{ runner.os }}-dependencies-cache- @@ -61,7 +61,7 @@ jobs: uses: actions/cache@v3 with: path: build-host - key: ${{ runner.os }}-host-protoc-${{ hashFiles('src/**', 'CMakeLists.txt') }} + key: ${{ runner.os }}-host-protoc-${{ hashFiles('src/**', 'CMakeLists.txt') }}-stl-fix restore-keys: | ${{ runner.os }}-host-protoc- @@ -87,7 +87,7 @@ jobs: uses: actions/cache@v3 with: path: build-android-${{ matrix.abi }} - key: ${{ runner.os }}-android-build-${{ matrix.abi }}-${{ hashFiles('src/**', 'CMakeLists.txt', 'cmake/**') }} + key: ${{ runner.os }}-android-build-${{ matrix.abi }}-${{ hashFiles('src/**', 'CMakeLists.txt', 'cmake/**') }}-stl-fix restore-keys: | ${{ runner.os }}-android-build-${{ matrix.abi }}- @@ -126,7 +126,7 @@ jobs: uses: actions/cache@v3 with: path: examples/c++/build-android-examples-${{ matrix.abi }} - key: ${{ runner.os }}-examples-build-${{ matrix.abi }}-${{ hashFiles('examples/c++/**', 'CMakeLists.txt', 'src/**') }} + key: ${{ runner.os }}-examples-build-${{ matrix.abi }}-${{ hashFiles('examples/c++/**', 'CMakeLists.txt', 'src/**') }}-stl-fix restore-keys: | ${{ runner.os }}-examples-build-${{ matrix.abi }}- From 4df824d135419c157cfcc47bd3606ea40f7fee57 Mon Sep 17 00:00:00 2001 From: "xufeihong.xfh" Date: Thu, 12 Feb 2026 17:08:10 +0800 Subject: [PATCH 22/22] fix --- .github/workflows/android_build.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/android_build.yml b/.github/workflows/android_build.yml index e249825f..82667254 100644 --- a/.github/workflows/android_build.yml +++ b/.github/workflows/android_build.yml @@ -87,9 +87,7 @@ jobs: uses: actions/cache@v3 with: path: build-android-${{ matrix.abi }} - key: ${{ runner.os }}-android-build-${{ matrix.abi }}-${{ hashFiles('src/**', 'CMakeLists.txt', 'cmake/**') }}-stl-fix - restore-keys: | - ${{ runner.os }}-android-build-${{ matrix.abi }}- + key: ${{ runner.os }}-android-build-${{ matrix.abi }}-${{ hashFiles('src/**', 'CMakeLists.txt', 'cmake/**', 'thirdparty/**') }}-stl-fix-2 - name: Configure and Build shell: bash @@ -126,9 +124,7 @@ jobs: uses: actions/cache@v3 with: path: examples/c++/build-android-examples-${{ matrix.abi }} - key: ${{ runner.os }}-examples-build-${{ matrix.abi }}-${{ hashFiles('examples/c++/**', 'CMakeLists.txt', 'src/**') }}-stl-fix - restore-keys: | - ${{ runner.os }}-examples-build-${{ matrix.abi }}- + key: ${{ runner.os }}-examples-build-${{ matrix.abi }}-${{ hashFiles('examples/c++/**', 'CMakeLists.txt', 'src/**') }}-stl-fix-2 - name: Build examples shell: bash