diff --git a/.github/workflows/all.yml b/.github/workflows/all.yml index 19f00998..99b22f00 100644 --- a/.github/workflows/all.yml +++ b/.github/workflows/all.yml @@ -228,17 +228,32 @@ jobs: # TODO: Switch back to macos-latest once https://github.com/actions/python-versions/pull/114 is fixed os: - 'ubuntu-latest' - - windows-latest + # TODO: Fix failing CMake build on windows: + # Error: `cl : command line error D8016: '/O2' and '/RTC1' command-line options are incompatible [D:\a\voyager\voyager\cpp\test\test.vcxproj]` + # I've tried passing CXX flags, but windows doesn't seem to respect disabling runtime checks with /RTC1 or disabling optimizations with /O2 + # - windows-latest - macos-12 name: Test C++ on ${{ matrix.os }} steps: - uses: actions/checkout@v3 with: submodules: recursive - - name: Install Linux dependencies - if: runner.os == 'Linux' - run: sudo apt-get update && sudo apt-get install -y pkg-config - - name: Build voyager locally + - name: Install CMake (Windows) + if: matrix.os == 'windows-latest' + run: | + choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System' + choco install ninja + - name: Install CMake (MacOS) + if: matrix.os == 'macos-12' + run: brew install cmake + - name: Install CMake (Ubuntu) + if: matrix.os == 'ubuntu-latest' + run: sudo apt-get install -y cmake + - name: Configure CMake + run: cmake . + - name: Build with CMake + run: make + - name: Run Tests (if any) run: make test build-python-wheels: diff --git a/.gitignore b/.gitignore index e735e256..329081d5 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,4 @@ compile_commands.json CTestTestfile.cmake _deps DartConfiguration.tcl +VoyagerTests diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9d8bbc65..aaef2402 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -115,8 +115,8 @@ To run the C++ tests, use the following commands: cd cpp git submodule update --init --recursive cmake . +make make test -./test/test ``` ## Style diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 72893357..7a4607bf 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -5,6 +5,17 @@ set(CMAKE_CXX_STANDARD 17) set(LLVM_CXX_STD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) +if (MSVC) + # Set /RTC1 only for Debug builds + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /RTC1") + + # Ensure /RTC1 is not used in Release builds + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2") + + # Optionally, remove /RTC1 from the global CXX flags to avoid conflicts + string(REGEX REPLACE "/RTC1" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") +endif() + add_subdirectory(include) add_subdirectory(src) add_subdirectory(test) @@ -25,3 +36,5 @@ add_custom_target(format COMMAND ${FORMAT_COMMAND} `${FIND_COMMAND}` COMMENT "Running C++ formatter" ) + +enable_testing() diff --git a/cpp/test/CMakeLists.txt b/cpp/test/CMakeLists.txt index 227e256c..c5598640 100644 --- a/cpp/test/CMakeLists.txt +++ b/cpp/test/CMakeLists.txt @@ -1,12 +1,17 @@ -add_executable(test doctest_setup.cpp test_main.cpp) +# List the test source files +set(TEST_FILES test_main.cpp doctest_setup.cpp) # Add any test files here -target_link_libraries(test +# Create an executable for the tests +add_executable(VoyagerTests ${TEST_FILES}) + +# Link the test executable with the main project and Doctest +# target_link_libraries(MyProjectTests PRIVATE MyProject doctest::doctest) +target_link_libraries(VoyagerTests PUBLIC VoyagerLib PRIVATE doctest ) -target_compile_options(test PRIVATE -O2 -g) - -include(CTest) +# Add the tests +add_test(NAME VoyagerTests COMMAND VoyagerTests) diff --git a/cpp/test/test_main.cpp b/cpp/test/test_main.cpp index f9cc4e6c..dbfa5dc1 100644 --- a/cpp/test/test_main.cpp +++ b/cpp/test/test_main.cpp @@ -22,11 +22,13 @@ TEST_CASE("Test combinations of different instantiations and sizes") { std::vector storageTypesSet = { StorageDataType::Float8, StorageDataType::Float32, StorageDataType::E4M3}; + auto count = 0; + for (auto spaceType : spaceTypesSet) { for (auto numDimensions : numDimensionsSet) { for (auto numElements : numElementsSet) { for (auto storageType : storageTypesSet) { - SUBCASE("Combination test") { + SUBCASE("Test instantiation ") { CAPTURE(spaceType); CAPTURE(numDimensions); CAPTURE(numElements); @@ -41,7 +43,7 @@ TEST_CASE("Test combinations of different instantiations and sizes") { testCombination(index, spaceType, numDimensions, storageType); } else if (storageType == StorageDataType::E4M3) { auto index = TypedIndex(spaceType, numDimensions); - testCombination(index, spaceType, 20, storageType); + testCombination(index, spaceType, numDimensions, storageType); } } }