From b224b17653758223f48ebf4ae3deb3217caf925a Mon Sep 17 00:00:00 2001 From: feihongxu0824 Date: Tue, 9 Jun 2026 16:01:21 +0800 Subject: [PATCH] fix: add cmake subproject integration check (#465) --- .../subproject-integration/CMakeLists.txt | 26 +++++ .github/workflows/03-macos-linux-build.yml | 21 ++++ .../08-cmake-subproject-integration.yml | 97 +++++++++++++++++++ thirdparty/FastPFOR/CMakeLists.txt | 2 +- 4 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 .github/cmake/subproject-integration/CMakeLists.txt create mode 100644 .github/workflows/08-cmake-subproject-integration.yml diff --git a/.github/cmake/subproject-integration/CMakeLists.txt b/.github/cmake/subproject-integration/CMakeLists.txt new file mode 100644 index 0000000..7bde0d7 --- /dev/null +++ b/.github/cmake/subproject-integration/CMakeLists.txt @@ -0,0 +1,26 @@ +cmake_minimum_required(VERSION 3.13) +project(zvec_subproject_integration LANGUAGES C CXX) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +set(ZVEC_SOURCE_DIR "" CACHE PATH "Path to the zvec source tree") +if(NOT ZVEC_SOURCE_DIR) + message(FATAL_ERROR "ZVEC_SOURCE_DIR is required") +endif() + +add_subdirectory("${ZVEC_SOURCE_DIR}" zvec) + +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") + +add_executable(zvec_embed_db_example + "${ZVEC_SOURCE_DIR}/examples/c++/db/main.cc") +target_link_libraries(zvec_embed_db_example PRIVATE zvec_shared) + +add_executable(zvec_embed_core_example + "${ZVEC_SOURCE_DIR}/examples/c++/core/main.cc") +target_link_libraries(zvec_embed_core_example PRIVATE zvec_shared) + +add_executable(zvec_embed_ailego_example + "${ZVEC_SOURCE_DIR}/examples/c++/ailego/main.cc") +target_link_libraries(zvec_embed_ailego_example PRIVATE zvec_shared) diff --git a/.github/workflows/03-macos-linux-build.yml b/.github/workflows/03-macos-linux-build.yml index f9fdd8f..4388f03 100644 --- a/.github/workflows/03-macos-linux-build.yml +++ b/.github/workflows/03-macos-linux-build.yml @@ -107,6 +107,27 @@ jobs: setuptools_scm shell: bash + - name: Check CMake subproject integration + if: matrix.platform == 'linux-x64' + run: | + SMOKE_SOURCE="$RUNNER_TEMP/zvec-subproject-smoke" + SMOKE_BUILD="$RUNNER_TEMP/zvec-subproject-build" + + mkdir -p "$SMOKE_SOURCE" "$SMOKE_BUILD" + cp "$GITHUB_WORKSPACE/.github/cmake/subproject-integration/CMakeLists.txt" \ + "$SMOKE_SOURCE/CMakeLists.txt" + + cmake -S "$SMOKE_SOURCE" -B "$SMOKE_BUILD" -G Ninja \ + -DZVEC_SOURCE_DIR="$GITHUB_WORKSPACE" \ + -DCMAKE_BUILD_TYPE=Release \ + -DBUILD_TOOLS=OFF \ + -DBUILD_C_BINDINGS=OFF \ + -DBUILD_PYTHON_BINDINGS=OFF \ + -DENABLE_WERROR=ON \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache + shell: bash + - name: Build from source run: | cd "$GITHUB_WORKSPACE" diff --git a/.github/workflows/08-cmake-subproject-integration.yml b/.github/workflows/08-cmake-subproject-integration.yml new file mode 100644 index 0000000..21e98ce --- /dev/null +++ b/.github/workflows/08-cmake-subproject-integration.yml @@ -0,0 +1,97 @@ +name: Nightly CMake Subproject Integration + +on: + schedule: + # Run after the other nightly jobs to avoid starting every heavy job at once. + - cron: '30 16 * * *' + workflow_dispatch: + +permissions: + contents: read + +jobs: + subproject-integration: + name: Subproject Build & Example (linux-x64) + runs-on: ubuntu-24.04 + timeout-minutes: 90 + + steps: + - name: Checkout code + uses: actions/checkout@v6 + with: + submodules: recursive + + - name: Setup ccache + uses: hendrikmuhs/ccache-action@v1.2 + with: + key: cmake-subproject-linux-x64 + max-size: 150M + + - name: Set up Python + uses: actions/setup-python@v6 + with: + python-version: '3.10' + cache: 'pip' + cache-dependency-path: 'pyproject.toml' + + - name: Install system dependencies + run: | + sudo apt-get update + sudo apt-get install -y --no-install-recommends \ + libaio-dev + shell: bash + + - name: Set up environment variables + run: | + NPROC=$(nproc 2>/dev/null || echo 2) + echo "NPROC=$NPROC" >> "$GITHUB_ENV" + echo "$(python -c 'import site; print(site.USER_BASE)')/bin" >> "$GITHUB_PATH" + shell: bash + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install \ + cmake==3.30.0 \ + ninja==1.11.1 + shell: bash + + - name: Configure subproject integration + run: | + SMOKE_SOURCE="$RUNNER_TEMP/zvec-subproject-nightly" + SMOKE_BUILD="$RUNNER_TEMP/zvec-subproject-nightly-build" + + mkdir -p "$SMOKE_SOURCE" "$SMOKE_BUILD" + cp "$GITHUB_WORKSPACE/.github/cmake/subproject-integration/CMakeLists.txt" \ + "$SMOKE_SOURCE/CMakeLists.txt" + + cmake -S "$SMOKE_SOURCE" -B "$SMOKE_BUILD" -G Ninja \ + -DZVEC_SOURCE_DIR="$GITHUB_WORKSPACE" \ + -DCMAKE_BUILD_TYPE=Release \ + -DBUILD_TOOLS=OFF \ + -DBUILD_C_BINDINGS=OFF \ + -DBUILD_PYTHON_BINDINGS=OFF \ + -DENABLE_WERROR=ON \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache + + echo "SMOKE_BUILD=$SMOKE_BUILD" >> "$GITHUB_ENV" + shell: bash + + - name: Build subproject targets + run: | + cmake --build "$SMOKE_BUILD" --target \ + core_knn_diskann \ + zvec_embed_db_example \ + zvec_embed_core_example \ + zvec_embed_ailego_example \ + --parallel "$NPROC" + shell: bash + + - name: Run subproject examples + run: | + cd "$SMOKE_BUILD" + ./bin/zvec_embed_db_example + ./bin/zvec_embed_core_example + ./bin/zvec_embed_ailego_example + shell: bash diff --git a/thirdparty/FastPFOR/CMakeLists.txt b/thirdparty/FastPFOR/CMakeLists.txt index 4d19289..6ff7b80 100644 --- a/thirdparty/FastPFOR/CMakeLists.txt +++ b/thirdparty/FastPFOR/CMakeLists.txt @@ -1,4 +1,4 @@ -include(${CMAKE_SOURCE_DIR}/cmake/bazel.cmake) +include(${PROJECT_ROOT_DIR}/cmake/bazel.cmake) # On non-x86 platforms, FastPFOR uses SIMDe to emulate SSE intrinsics. # Detection covers native ARM/RISC-V builds AND cross-compilation (e.g. iOS/Android).