-
Notifications
You must be signed in to change notification settings - Fork 500
feat: add c language support #167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
chinaux
wants to merge
12
commits into
main
Choose a base branch
from
feat/add_c_api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+15,295
−5
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
90ea721
init branch
chinaux b116d6c
format c_api.h
chinaux 87aded5
fix some code
chinaux a979e33
format c_api code
chinaux 551c8c9
build rpm
chinaux 50ed717
fix some code
chinaux d0f828c
fix some code
chinaux 7619eb7
remove rpm build
chinaux 6f30a7c
Add GitHub Actions release workflow for C API
chinaux 7d0ff14
add release linux-arm64
chinaux 0ed36ed
remove c api version
chinaux d6c4c8d
fix some code
chinaux File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,193 @@ | ||
| name: Release | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| on: | ||
| push: | ||
| tags: | ||
| - 'v*' # Match v0.3.0, v1.0.0, etc. | ||
| workflow_dispatch: # Allow manual trigger | ||
|
|
||
| jobs: | ||
| # ============================================================================ | ||
| # Linux x64 Build | ||
| # ============================================================================ | ||
| linux-x64: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| submodules: recursive | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install -y cmake ninja-build build-essential | ||
|
|
||
| - name: Build libzvec_c_api.so | ||
| run: | | ||
| cmake -S . -B build -G Ninja \ | ||
| -DCMAKE_BUILD_TYPE=Release \ | ||
| -DBUILD_PYTHON_BINDINGS=OFF \ | ||
| -DBUILD_TOOLS=OFF \ | ||
| -DBUILD_EXAMPLES=OFF | ||
| cmake --build build --parallel --target zvec_c_api | ||
|
|
||
| - name: Verify library | ||
| run: | | ||
| echo "=== Library file ===" | ||
| ls -lh build/src/c_api/libzvec_c_api.so | ||
| echo "=== Check dependencies ===" | ||
| ldd build/src/c_api/libzvec_c_api.so || true | ||
|
|
||
| - name: Create tarball | ||
| run: | | ||
| cp src/include/zvec/c_api.h . | ||
| cp build/src/c_api/libzvec_c_api.so . | ||
| tar -czvf libzvec-capi-linux-x64.tar.gz \ | ||
| c_api.h \ | ||
| libzvec_c_api.so | ||
|
|
||
| - name: Upload artifact | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: zvec-capi-linux-x64 | ||
| path: libzvec-capi-linux-x64.tar.gz | ||
|
|
||
| # ============================================================================ | ||
| # Linux ARM64 Build | ||
| # ============================================================================ | ||
| linux-arm64: | ||
| runs-on: ubuntu-24.04-arm | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| submodules: recursive | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install -y cmake ninja-build build-essential | ||
|
|
||
| - name: Build libzvec_c_api.so (ARM64) | ||
| run: | | ||
| cmake -S . -B build -G Ninja \ | ||
| -DCMAKE_BUILD_TYPE=Release \ | ||
| -DBUILD_PYTHON_BINDINGS=OFF \ | ||
| -DBUILD_TOOLS=OFF \ | ||
| -DBUILD_EXAMPLES=OFF | ||
| cmake --build build --parallel --target zvec_c_api | ||
|
|
||
| - name: Verify library | ||
| run: | | ||
| echo "=== Library file ===" | ||
| ls -lh build/src/c_api/libzvec_c_api.so | ||
| echo "=== Check dependencies ===" | ||
| ldd build/src/c_api/libzvec_c_api.so || true | ||
|
|
||
| - name: Create tarball | ||
| run: | | ||
| cp src/include/zvec/c_api.h . | ||
| cp build/src/c_api/libzvec_c_api.so . | ||
| tar -czvf libzvec-capi-linux-arm64.tar.gz \ | ||
| c_api.h \ | ||
| libzvec_c_api.so | ||
|
|
||
| - name: Upload artifact | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: zvec-capi-linux-arm64 | ||
| path: libzvec-capi-linux-arm64.tar.gz | ||
|
|
||
| # ============================================================================ | ||
| # macOS Universal Build (arm64 + x86_64) | ||
| # ============================================================================ | ||
| macos-universal: | ||
|
||
| runs-on: macos-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| submodules: recursive | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| brew install cmake ninja | ||
|
|
||
| - name: Build libzvec_c_api.dylib (Universal Binary) | ||
| env: | ||
| CMAKE_OSX_ARCHITECTURES: "arm64;x86_64" | ||
| MACOSX_DEPLOYMENT_TARGET: "11.0" | ||
| run: | | ||
| cmake -S . -B build -G Ninja \ | ||
| -DCMAKE_BUILD_TYPE=Release \ | ||
| -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" \ | ||
| -DCMAKE_OSX_DEPLOYMENT_TARGET="11.0" \ | ||
| -DBUILD_PYTHON_BINDINGS=OFF \ | ||
| -DBUILD_TOOLS=OFF \ | ||
| -DBUILD_EXAMPLES=OFF | ||
| cmake --build build --parallel --target zvec_c_api | ||
|
|
||
| - name: Verify library | ||
| run: | | ||
| echo "=== Library file ===" | ||
| ls -lh build/src/c_api/libzvec_c_api.dylib | ||
| echo "=== Check architectures ===" | ||
| lipo -archs build/src/c_api/libzvec_c_api.dylib | ||
|
|
||
| - name: Create tarball | ||
| run: | | ||
| cp src/include/zvec/c_api.h . | ||
| cp build/src/c_api/libzvec_c_api.dylib . | ||
| tar -czvf libzvec-capi-macos-universal.tar.gz \ | ||
| c_api.h \ | ||
| libzvec_c_api.dylib | ||
|
|
||
| - name: Upload artifact | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: zvec-capi-macos-universal | ||
| path: libzvec-capi-macos-universal.tar.gz | ||
|
|
||
| # ============================================================================ | ||
| # Upload to GitHub Releases | ||
| # ============================================================================ | ||
| upload-release: | ||
|
||
| needs: [linux-x64, linux-arm64, macos-universal] | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| # Download build artifacts for each platform | ||
| - uses: actions/download-artifact@v4 | ||
| with: | ||
| name: zvec-capi-linux-x64 | ||
| path: dist/ | ||
|
|
||
| - uses: actions/download-artifact@v4 | ||
| with: | ||
| name: zvec-capi-linux-arm64 | ||
| path: dist/ | ||
|
|
||
| - uses: actions/download-artifact@v4 | ||
| with: | ||
| name: zvec-capi-macos-universal | ||
| path: dist/ | ||
|
|
||
| - name: List artifacts | ||
| run: ls -la dist/ | ||
|
|
||
| # Upload to GitHub Releases | ||
| - uses: softprops/action-gh-release@v1 | ||
| with: | ||
| files: dist/*.tar.gz | ||
| generate_release_notes: true | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # Copyright 2025-present the zvec project | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| add_subdirectory(c_api) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| # Copyright 2025-present the zvec project | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| # Basic example | ||
| add_executable(c_api_basic_example basic_example.c) | ||
| target_link_libraries(c_api_basic_example PRIVATE zvec_c_api) | ||
| target_include_directories(c_api_basic_example PRIVATE | ||
| ${PROJECT_SOURCE_DIR}/src/include | ||
| ) | ||
| set_target_properties(c_api_basic_example PROPERTIES | ||
| RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/examples/c_api | ||
| ) | ||
|
|
||
|
|
||
| # Schema example | ||
| add_executable(c_api_collection_schema_example collection_schema_example.c) | ||
| target_link_libraries(c_api_collection_schema_example PRIVATE zvec_c_api) | ||
| target_include_directories(c_api_collection_schema_example PRIVATE | ||
| ${PROJECT_SOURCE_DIR}/src/include | ||
| ) | ||
| set_target_properties(c_api_collection_schema_example PROPERTIES | ||
| RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/examples/c_api | ||
| ) | ||
|
|
||
| # Struct document example | ||
| add_executable(c_api_doc_example doc_example.c) | ||
| target_link_libraries(c_api_doc_example PRIVATE zvec_c_api) | ||
| target_include_directories(c_api_doc_example PRIVATE | ||
| ${PROJECT_SOURCE_DIR}/src/include | ||
| ) | ||
| set_target_properties(c_api_doc_example PROPERTIES | ||
| RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/examples/c_api | ||
| ) | ||
|
|
||
| # Index example | ||
| add_executable(c_api_index_example index_example.c) | ||
| target_link_libraries(c_api_index_example PRIVATE zvec_c_api) | ||
| set_target_properties(c_api_index_example PROPERTIES | ||
| RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/examples/c_api | ||
| ) | ||
|
|
||
| # Newly added field schema example | ||
| add_executable(c_api_field_schema_example field_schema_example.c) | ||
| target_link_libraries(c_api_field_schema_example PRIVATE zvec_c_api) | ||
| set_target_properties(c_api_field_schema_example PROPERTIES | ||
| RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/examples/c_api | ||
| ) | ||
|
|
||
| # Optimized example | ||
| add_executable(c_api_optimized_example optimized_example.c) | ||
| target_link_libraries(c_api_optimized_example PRIVATE zvec_c_api) | ||
| set_target_properties(c_api_optimized_example PROPERTIES | ||
| RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/examples/c_api | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.