diff --git a/.github/workflows/prerelease.yml b/.github/workflows/prerelease.yml index 3aa9d911..4f43b800 100644 --- a/.github/workflows/prerelease.yml +++ b/.github/workflows/prerelease.yml @@ -17,14 +17,10 @@ permissions: jobs: - test_cpp_c_ubuntu: - name: Test C++ Ubuntu (${{ matrix.compiler }}) + test_cpp_c_ubuntu_gcc: + name: Test C++ Ubuntu (GCC) runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - compiler: [g++-9, g++-10, g++-11, clang-10, clang-11, clang-12] - + steps: - uses: actions/checkout@v3 with: @@ -32,20 +28,47 @@ jobs: - run: git submodule update --init --recursive - name: Install Dependencies + run: sudo apt update && sudo apt install -y cmake build-essential libjemalloc-dev libomp-dev g++-12 + + - name: Build run: | - sudo apt update && - sudo apt install -y cmake build-essential libjemalloc-dev ${{ matrix.compiler }} + export CC=gcc-12 + export CXX=g++-12 + cmake -B build -DCMAKE_BUILD_TYPE=Debug -DUSEARCH_BUILD_TEST_CPP=1 -DUSEARCH_BUILD_TEST_C=1 -DUSEARCH_USE_OPENMP=1 -DUSEARCH_USE_SIMSIMD=1 -DUSEARCH_USE_JEMALLOC=1 + cmake --build build --config Debug + + - name: Run C++ tests + run: ./build/test_cpp + - name: Run C tests + run: ./build/test_c + + + test_cpp_c_ubuntu_clang: + name: Test C++ Ubuntu (Clang) + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + with: + ref: main-dev + - run: git submodule update --init --recursive + + - name: Install Dependencies + run: sudo apt update && sudo apt install -y cmake build-essential libjemalloc-dev clang-15 - name: Build run: | - export CXX=${{ matrix.compiler }} - cmake -B build -DCMAKE_BUILD_TYPE=Debug -DUSEARCH_BUILD_TEST=1 -DUSEARCH_BUILD_CTEST=1 -DUSEARCH_USE_OPENMP=1 -DUSEARCH_USE_SIMSIMD=1 -DUSEARCH_USE_JEMALLOC=1 + export CC=clang-15 + export CXX=clang++-15 + cmake -B build -DCMAKE_BUILD_TYPE=Debug -DUSEARCH_BUILD_TEST_CPP=1 -DUSEARCH_BUILD_TEST_C=1 -DUSEARCH_USE_SIMSIMD=1 -DUSEARCH_USE_JEMALLOC=1 cmake --build build --config Debug + - name: Run C++ tests run: ./build/test_cpp - name: Run C tests run: ./build/test_c + test_cpp_c_macos: name: Test C++ MacOS runs-on: macos-latest @@ -59,13 +82,13 @@ jobs: run: | brew update brew install cmake - + - name: Build run: | - cmake -B build -DCMAKE_BUILD_TYPE=Debug -DUSEARCH_BUILD_TEST=1 -DUSEARCH_BUILD_CTEST=1 + cmake -B build -DCMAKE_BUILD_TYPE=Debug -DUSEARCH_BUILD_TEST_CPP=1 -DUSEARCH_BUILD_TEST_C=1 cmake --build build --config Debug - name: Run C++ tests - run: ./build/test + run: ./build/test_cpp - name: Run C tests run: ./build/test_c @@ -83,12 +106,12 @@ jobs: - name: Build run: | - cmake -B build -DCMAKE_BUILD_TYPE=Debug -DUSEARCH_BUILD_TEST=1 -DUSEARCH_BUILD_CTEST=1 + cmake -B build -DCMAKE_BUILD_TYPE=Debug -DUSEARCH_BUILD_TEST_CPP=1 -DUSEARCH_BUILD_TEST_C=1 cmake --build build --config Debug - name: Run C++ tests - run: ./build/test + run: .\build\test_cpp - name: Run C tests - run: ./build/test_c + run: .\build\test_c test_python_311: name: Test Python diff --git a/.vscode/settings.json b/.vscode/settings.json index c8f37b24..d3821cb8 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -118,6 +118,7 @@ "downcasted", "Downcasting", "dtype", + "DUSEARCH", "emcmake", "equi", "equidimensional", diff --git a/CMakeLists.txt b/CMakeLists.txt index f27d7b72..f0182de7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,10 +21,10 @@ option(USEARCH_USE_SIMSIMD "Use SimSIMD hardware-accelerated metrics" OFF) option(USEARCH_USE_JEMALLOC "Use JeMalloc for faster memory allocations" OFF) option(USEARCH_USE_NATIVE_F16 "Use native half-precision types" OFF) -option(USEARCH_BUILD_TEST "Compile a native unit test in C++" ${USEARCH_IS_MAIN_PROJECT}) -option(USEARCH_BUILD_BENCHMARK "Compile a native benchmark in C++" ${USEARCH_IS_MAIN_PROJECT}) -option(USEARCH_BUILD_CLIB "Compile a native library for the C 99 interface" OFF) -option(USEARCH_BUILD_CTEST "Compile a test for the C 99 interface" OFF) +option(USEARCH_BUILD_TEST_CPP "Compile a native unit test in C++" ${USEARCH_IS_MAIN_PROJECT}) +option(USEARCH_BUILD_BENCH_CPP "Compile a native benchmark in C++" ${USEARCH_IS_MAIN_PROJECT}) +option(USEARCH_BUILD_LIB_C "Compile a native library for the C 99 interface" OFF) +option(USEARCH_BUILD_TEST_C "Compile a test for the C 99 interface" OFF) option(USEARCH_BUILD_WOLFRAM "Compile Wolfram Language bindings" OFF) # Includes @@ -220,7 +220,10 @@ function (setup_target TARGET_NAME) ) # Check if the compiler is AppleClang, and if not, add the leak sanitizer - if (NOT CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "AppleClang") + if (CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin") + # It's likely AppleClang Adjust options as needed for AppleClang + else () + # It's likely LLVM Clang target_compile_options(${TARGET_NAME} PRIVATE $<$:-fsanitize=leak>) target_link_options(${TARGET_NAME} PRIVATE $<$:-fsanitize=leak>) endif () @@ -255,6 +258,8 @@ function (setup_target TARGET_NAME) endif () target_include_directories(${TARGET_NAME} PRIVATE ${USEARCH_HEADER_INCLUDES}) + set_target_properties(${TARGET_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}) + set_target_properties(${TARGET_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}) set_target_properties(${TARGET_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) set_target_properties(${TARGET_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) set_target_properties(${TARGET_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) @@ -272,7 +277,7 @@ function (setup_target TARGET_NAME) endfunction () -if (${USEARCH_BUILD_TEST} OR ${USEARCH_BUILD_BENCHMARK}) +if (${USEARCH_BUILD_TEST_CPP} OR ${USEARCH_BUILD_BENCH_CPP}) add_subdirectory(cpp) endif () @@ -284,6 +289,6 @@ if (${USEARCH_BUILD_WASM}) add_subdirectory(wasm) endif () -if (${USEARCH_BUILD_CLIB} OR ${USEARCH_BUILD_CTEST}) +if (${USEARCH_BUILD_LIB_C} OR ${USEARCH_BUILD_TEST_C}) add_subdirectory(c) endif () diff --git a/binding.gyp b/binding.gyp index 733a496d..5a6665c7 100644 --- a/binding.gyp +++ b/binding.gyp @@ -20,7 +20,7 @@ "-fexceptions", "-Wno-unknown-pragmas", "-Wno-maybe-uninitialized", - "-std=c++11", + "-std=c++17", ], "xcode_settings": { "GCC_ENABLE_CPP_EXCEPTIONS": "YES", @@ -30,7 +30,7 @@ "msvs_settings": { "VCCLCompilerTool": { "ExceptionHandling": 1, - "AdditionalOptions": ["-std:c++11"], + "AdditionalOptions": ["-std:c++17"], } }, } diff --git a/c/CMakeLists.txt b/c/CMakeLists.txt index 79816a4a..709ddc51 100644 --- a/c/CMakeLists.txt +++ b/c/CMakeLists.txt @@ -1,4 +1,4 @@ -if (USEARCH_BUILD_CLIB) +if (USEARCH_BUILD_TEST_C) add_executable(test_c test.c lib.cpp) setup_target(test_c) include(CTest) @@ -8,7 +8,7 @@ endif () # This article discusses a better way to allow building either static or shared libraries: # https://alexreinking.com/blog/building-a-dual-shared-and-static-library-with-cmake.html -if (USEARCH_BUILD_CTEST) +if (USEARCH_BUILD_LIB_C) add_library(usearch_c SHARED lib.cpp) add_library(usearch_static_c STATIC lib.cpp) diff --git a/c/README.md b/c/README.md index 7e082b2d..34ef80ca 100644 --- a/c/README.md +++ b/c/README.md @@ -3,14 +3,12 @@ ## Installation The simplest form to integrate is to copy the contents of `usearch/c/` into your project. -To build the library `libusearch_static_c` and `libusearch_c`, pass enable the `USEARCH_BUILD_CLIB` CMake option: +To build the library `libusearch_static_c` and `libusearch_c`, pass enable the `USEARCH_BUILD_LIB_C` CMake option: ```bash -cmake -DUSEARCH_BUILD_CLIB=1 -DUSEARCH_BUILD_CTEST=1 -DUSEARCH_BUILD_STATIC=0 -DUSEARCH_BUILD_TEST=0 -DUSEARCH_BUILD_BENCHMARK=0 .. +cmake -DUSEARCH_BUILD_LIB_C=1 -DUSEARCH_BUILD_TEST_C=1 -DUSEARCH_BUILD_TEST_CPP=0 -DUSEARCH_BUILD_BENCH_CPP=0 .. ``` -You can choose between a static and dynamic library by setting `USEARCH_BUILD_STATIC`. - ## Quickstart ```c diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 0ed75807..27d78723 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -1,5 +1,4 @@ - -if (USEARCH_BUILD_TEST) +if (USEARCH_BUILD_TEST_CPP) add_executable(test_cpp test.cpp) setup_target(test_cpp) include(CTest) @@ -7,7 +6,7 @@ if (USEARCH_BUILD_TEST) add_test(NAME test_cpp COMMAND test_cpp) endif () -if (USEARCH_BUILD_BENCHMARK) +if (USEARCH_BUILD_BENCH_CPP) include(clipp) add_executable(bench_cpp bench.cpp) setup_target(bench_cpp) diff --git a/docs/compilation.md b/docs/compilation.md index ee0b4d1e..2b830f2f 100644 --- a/docs/compilation.md +++ b/docs/compilation.md @@ -19,10 +19,10 @@ cmake -B ./build_release \ -DUSEARCH_USE_OPENMP=1 \ -DUSEARCH_USE_SIMSIMD=1 \ -DUSEARCH_USE_JEMALLOC=1 \ - -DUSEARCH_BUILD_TEST=1 \ - -DUSEARCH_BUILD_BENCHMARK=1 \ - -DUSEARCH_BUILD_CTEST=1 \ - -DUSEARCH_BUILD_CLIB=1 \ + -DUSEARCH_BUILD_TEST_CPP=1 \ + -DUSEARCH_BUILD_BENCH_CPP=1 \ + -DUSEARCH_BUILD_LIB_C=1 \ + -DUSEARCH_BUILD_TEST_C=1 \ && \ make -C ./build_release -j ``` @@ -36,8 +36,8 @@ cmake -B ./build_release \ -DCMAKE_CXX_COMPILER="/opt/homebrew/opt/llvm/bin/clang++" \ -DUSEARCH_USE_OPENMP=1 \ -DUSEARCH_USE_SIMSIMD=1 \ - -DUSEARCH_BUILD_BENCHMARK=1 \ - -DUSEARCH_BUILD_TEST=1 \ + -DUSEARCH_BUILD_BENCH_CPP=1 \ + -DUSEARCH_BUILD_TEST_CPP=1 \ && \ make -C ./build_release -j ``` @@ -168,7 +168,7 @@ make USEARCH_USE_OPENMP=1 USEARCH_USE_SIMSIMD=1 -C ./c libusearch_c.so Using CMake: ```sh -cmake -B ./build_release -DUSEARCH_BUILD_CLIB=1 && make -C ./build_release -j +cmake -B ./build_release -DUSEARCH_BUILD_LIB_C=1 && make -C ./build_release -j ``` Testing on MacOS and Linux: