From efc6f3f7ceffaad86991ae516d6fce47a29c21dc Mon Sep 17 00:00:00 2001 From: feihongxu0824 Date: Mon, 9 Feb 2026 23:31:56 +0800 Subject: [PATCH] fix: add c++ example to macos/linux ci (#86) --- .github/workflows/linux_x64_docker_ci.yml | 7 ++++ .github/workflows/mac_arm64_ci.yml | 7 ++++ examples/c++/CMakeLists.txt | 37 ++++++++++++++----- src/ailego/math_batch/distance_batch.h | 2 +- .../math_batch/inner_product_distance_batch.h | 2 +- .../zvec}/ailego/math_batch/utils.h | 1 + .../zvec/core/framework/index_metric.h | 2 +- 7 files changed, 46 insertions(+), 12 deletions(-) rename src/{ => include/zvec}/ailego/math_batch/utils.h (97%) diff --git a/.github/workflows/linux_x64_docker_ci.yml b/.github/workflows/linux_x64_docker_ci.yml index 3a76630..c839d96 100644 --- a/.github/workflows/linux_x64_docker_ci.yml +++ b/.github/workflows/linux_x64_docker_ci.yml @@ -137,3 +137,10 @@ jobs: cd "$CLEAN_WORKSPACE/build" make unittest -j$(nproc) shell: bash + + - name: Run Cpp Examples + run: | + cd "$CLEAN_WORKSPACE/examples/c++" + mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Release + make -j 16 && ./db-example && ./core-example && ./ailego-example + shell: bash diff --git a/.github/workflows/mac_arm64_ci.yml b/.github/workflows/mac_arm64_ci.yml index bff4f0d..73aa922 100644 --- a/.github/workflows/mac_arm64_ci.yml +++ b/.github/workflows/mac_arm64_ci.yml @@ -104,3 +104,10 @@ jobs: cd "$CLEAN_WORKSPACE/build" make unittest -j 16 shell: bash + + - name: Run Cpp Examples + run: | + cd "$CLEAN_WORKSPACE/examples/c++" + mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Release + make -j 16 && ./db-example && ./core-example && ./ailego-example + shell: bash diff --git a/examples/c++/CMakeLists.txt b/examples/c++/CMakeLists.txt index 2810f3e..0751bf9 100644 --- a/examples/c++/CMakeLists.txt +++ b/examples/c++/CMakeLists.txt @@ -27,10 +27,14 @@ else() endif() # --- Dependency groups --- +find_package(Threads REQUIRED) + set(zvec_ailego_deps arrow parquet arrow_bundled_dependencies + ${CMAKE_THREAD_LIBS_INIT} + ${CMAKE_DL_LIBS} ) set(zvec_core_deps @@ -66,13 +70,17 @@ target_link_libraries(zvec-ailego INTERFACE add_library(zvec-core INTERFACE) if(CMAKE_SYSTEM_NAME STREQUAL "Linux") target_link_libraries(zvec-core INTERFACE - "-Wl,--whole-archive,${ZVEC_LIB_DIR}/libzvec_core.a,-Wl,--no-whole-archive" + -Wl,--whole-archive + zvec_core + -Wl,--no-whole-archive + -Wl,--start-group zvec-ailego ${zvec_core_deps} + -Wl,--end-group ) elseif(APPLE) target_link_libraries(zvec-core INTERFACE - "-Wl,-force_load,${ZVEC_LIB_DIR}/libzvec_core.a" + -Wl,-force_load ${ZVEC_LIB_DIR}/libzvec_core.a zvec-ailego ${zvec_core_deps} ) @@ -82,12 +90,23 @@ endif() # zvec_db: links libzvec_db.a + all deps add_library(zvec-db INTERFACE) -target_link_libraries(zvec-db INTERFACE - zvec_db - zvec-core - zvec-ailego - ${zvec_db_deps} -) +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + target_link_libraries(zvec-db INTERFACE + zvec_db + zvec-core + zvec-ailego + -Wl,--start-group + ${zvec_db_deps} + -Wl,--end-group + ) +elseif(APPLE) + target_link_libraries(zvec-db INTERFACE + zvec_db + zvec-core + zvec-ailego + ${zvec_db_deps} + ) +endif() # --- Main executable --- @@ -104,4 +123,4 @@ target_link_libraries(core-example PRIVATE add_executable(ailego-example ailego/main.cc) target_link_libraries(ailego-example PRIVATE zvec-ailego -) \ No newline at end of file +) diff --git a/src/ailego/math_batch/distance_batch.h b/src/ailego/math_batch/distance_batch.h index 87a80eb..c762a25 100644 --- a/src/ailego/math_batch/distance_batch.h +++ b/src/ailego/math_batch/distance_batch.h @@ -14,10 +14,10 @@ #pragma once +#include #include "ailego/math/distance_matrix.h" #include "cosine_distance_batch.h" #include "inner_product_distance_batch.h" -#include "utils.h" namespace zvec::ailego { diff --git a/src/ailego/math_batch/inner_product_distance_batch.h b/src/ailego/math_batch/inner_product_distance_batch.h index 3a65a27..f579949 100644 --- a/src/ailego/math_batch/inner_product_distance_batch.h +++ b/src/ailego/math_batch/inner_product_distance_batch.h @@ -18,11 +18,11 @@ #include #include #include +#include #include #include "inner_product_distance_batch_impl.h" #include "inner_product_distance_batch_impl_fp16.h" #include "inner_product_distance_batch_impl_int8.h" -#include "utils.h" namespace zvec::ailego::DistanceBatch { diff --git a/src/ailego/math_batch/utils.h b/src/include/zvec/ailego/math_batch/utils.h similarity index 97% rename from src/ailego/math_batch/utils.h rename to src/include/zvec/ailego/math_batch/utils.h index 4b19b0d..3a22dd9 100644 --- a/src/ailego/math_batch/utils.h +++ b/src/include/zvec/ailego/math_batch/utils.h @@ -14,6 +14,7 @@ #pragma once +#include namespace zvec::ailego::DistanceBatch { typedef void (*DistanceBatchQueryPreprocessFunc)(void *query, size_t dim); diff --git a/src/include/zvec/core/framework/index_metric.h b/src/include/zvec/core/framework/index_metric.h index 5d93ba1..24d7723 100644 --- a/src/include/zvec/core/framework/index_metric.h +++ b/src/include/zvec/core/framework/index_metric.h @@ -14,8 +14,8 @@ #pragma once #include -#include #include +#include #include #include #include