Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions .github/workflows/build-c-api-bindings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Copyright 2026 Intel Corporation
#
# 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.

name: Build and test C API bindings

on:
push:
branches:
- main
pull_request:
workflow_dispatch:

permissions:
contents: read

# This allows a subsequently queued workflow run to interrupt previous runs
concurrency:
group: ${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}
cancel-in-progress: true

jobs:
build:
name: ${{ matrix.cxx }}, ${{ matrix.build_type }}
runs-on: ubuntu-22.04
strategy:
matrix:
build_type: [RelWithDebInfo]
cxx: [g++-11, g++-12, clang++-15]
include:
- cxx: g++-11
cc: gcc-11
- cxx: g++-12
cc: gcc-12
- cxx: clang++-15
cc: clang-15
fail-fast: false

steps:
- uses: actions/checkout@v6

- name: Install OpenMP runtime
env:
CXX: ${{ matrix.cxx }}
run: |
sudo apt-get update
# The default libgomp shipped with GCC does not match the clang
# toolchain, so install the LLVM OpenMP runtime (libomp) for clang.
if [[ "${CXX}" == clang* ]]; then
sudo apt-get install -y libomp-15-dev
fi

- name: Configure build
working-directory: ${{ runner.temp }}
env:
CXX: ${{ matrix.cxx }}
CC: ${{ matrix.cc }}
TEMP_WORKSPACE: ${{ runner.temp }}
run: |
cmake -B${TEMP_WORKSPACE}/build -S${GITHUB_WORKSPACE}/bindings/c \
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-DSVS_BUILD_C_API_TESTS=ON

- name: Build C API, tests and samples
working-directory: ${{ runner.temp }}/build
run: make -j$(nproc)

- name: Run C API tests
env:
CTEST_OUTPUT_ON_FAILURE: 1
working-directory: ${{ runner.temp }}/build
run: ctest -C ${{ matrix.build_type }} --output-on-failure
3 changes: 3 additions & 0 deletions bindings/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ endif()


if(SVS_BUILD_C_API_TESTS)
# Add test to CTest
include(CTest)
enable_testing()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_options(${TARGET_NAME} PRIVATE --coverage)
target_link_options(${TARGET_NAME} PRIVATE --coverage)
Expand Down
6 changes: 3 additions & 3 deletions bindings/c/src/data_builder/leanvec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ class LeanVecDataBuilder {
}
};

template <size_t I1, size_t I2, typename Allocator>
template <size_t I1, size_t I2, typename Alloc>
struct lib::
DispatchConverter<const c_runtime::Storage*, LeanVecDataBuilder<I1, I2, Allocator>> {
DispatchConverter<const c_runtime::Storage*, LeanVecDataBuilder<I1, I2, Alloc>> {
using From = const svs::c_runtime::Storage*;
using To = LeanVecDataBuilder<I1, I2, Allocator>;
using To = LeanVecDataBuilder<I1, I2, Alloc>;

static int64_t match(From from) {
if (from->kind == SVS_STORAGE_KIND_LEANVEC) {
Expand Down
6 changes: 3 additions & 3 deletions bindings/c/src/data_builder/lvq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ class LVQDataBuilder {
}
};

template <size_t PrimaryBits, size_t ResidualBits, typename Allocator>
template <size_t PrimaryBits, size_t ResidualBits, typename Alloc>
struct lib::DispatchConverter<
const c_runtime::Storage*,
LVQDataBuilder<PrimaryBits, ResidualBits, Allocator>> {
LVQDataBuilder<PrimaryBits, ResidualBits, Alloc>> {
using From = const svs::c_runtime::Storage*;
using To = LVQDataBuilder<PrimaryBits, ResidualBits, Allocator>;
using To = LVQDataBuilder<PrimaryBits, ResidualBits, Alloc>;

static int64_t match(From from) {
if (from->kind == SVS_STORAGE_KIND_LVQ) {
Expand Down
6 changes: 3 additions & 3 deletions bindings/c/src/data_builder/simple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ class SimpleDataBuilder {
}
};

template <Arithmetic T, typename Allocator>
struct lib::DispatchConverter<const c_runtime::Storage*, SimpleDataBuilder<T, Allocator>> {
template <Arithmetic T, typename Alloc>
struct lib::DispatchConverter<const c_runtime::Storage*, SimpleDataBuilder<T, Alloc>> {
using From = const svs::c_runtime::Storage*;
using To = SimpleDataBuilder<T, Allocator>;
using To = SimpleDataBuilder<T, Alloc>;

static int64_t match(From from) {
if constexpr (svs::is_arithmetic_v<T>) {
Expand Down
6 changes: 3 additions & 3 deletions bindings/c/src/data_builder/sq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ template <Arithmetic T, typename Allocator = svs::lib::Allocator<T>> class SQDat
}
};

template <Arithmetic T, typename Allocator>
struct lib::DispatchConverter<const c_runtime::Storage*, SQDataBuilder<T, Allocator>> {
template <Arithmetic T, typename Alloc>
struct lib::DispatchConverter<const c_runtime::Storage*, SQDataBuilder<T, Alloc>> {
using From = const svs::c_runtime::Storage*;
using To = SQDataBuilder<T, Allocator>;
using To = SQDataBuilder<T, Alloc>;

static int64_t match(From from) {
if (from->kind == SVS_STORAGE_KIND_SQ) {
Expand Down
12 changes: 9 additions & 3 deletions bindings/c/tests/c_api_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,17 +231,23 @@ CATCH_TEST_CASE("C API Index Build and Search", "[c_api][index][build][search]")
DIMENSION / 2, SVS_DATA_TYPE_INT4, SVS_DATA_TYPE_INT8, error
);
CATCH_REQUIRE(check_storage_support(storage, error) == true);
run_build_and_search(storage);
if (storage != nullptr) {
run_build_and_search(storage);
}

// LVQ: primary = int4, residual = int8
storage = svs_storage_create_lvq(SVS_DATA_TYPE_INT4, SVS_DATA_TYPE_INT8, error);
CATCH_REQUIRE(check_storage_support(storage, error) == true);
run_build_and_search(storage);
if (storage != nullptr) {
run_build_and_search(storage);
}

// Scalar Quantization: int8
storage = svs_storage_create_sq(SVS_DATA_TYPE_INT8, error);
CATCH_REQUIRE(check_storage_support(storage, error) == true);
run_build_and_search(storage);
if (storage != nullptr) {
run_build_and_search(storage);
}

svs_error_free(error);
}
Expand Down
Loading