From f7f62ba01c75a8839634bc0b92e063089bf40d6a Mon Sep 17 00:00:00 2001 From: Ewan Miller Date: Tue, 13 Aug 2024 18:01:53 +0100 Subject: [PATCH] Workflow more ci platforms (#42) * Update CI-build-and-test.yml to include windows and clang * Update CI-build-and-test.yml to actually set the os and c++ compiler * Hopefully more system agnostic way to install protoc * Use both of the cores in the runner * Remove as this causes windows to be sad, dont think it actually did anything anyway * Seems like ubuntu and windows will need different ways to install protoc, oh well * Link math library to test targets as this seems to be needed for clang * Gcc, clang -> g++, clang++ * Use dictionary to set c and cpp compilers separately in matrix job * ' -> " * Attempt some nasty hacking to try to get install working on windows * Update CI-build-and-test.yml to fix indents * Update CI-build-and-test.yml to correct OS check * Do the spaces matter? * Dont need test coverage for every platform * This???? * The slashes seem upsetting for windows * Update CI-build-and-test.yml * Whoops, variable name was wrong lol * Update CI-build-and-test.yml * Update CI-build-and-test.yml * Update CI-build-and-test.yml --- .github/workflows/CI-build-and-test.yml | 49 +++++++++++++++++++++---- tests/CMakeLists.txt | 4 +- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/.github/workflows/CI-build-and-test.yml b/.github/workflows/CI-build-and-test.yml index 31f6d4e..b655aca 100644 --- a/.github/workflows/CI-build-and-test.yml +++ b/.github/workflows/CI-build-and-test.yml @@ -18,16 +18,31 @@ jobs: # The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac. # You can convert this to a matrix build if you need cross-platform coverage. # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix - runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + OS: [ ubuntu-latest, windows-latest ] + compiler: [ {cpp: g++, c: gcc}, {cpp: clang++, c: clang} ] + + name: Build & Test ${{ matrix.os }} ${{ matrix.compiler.c }} + + runs-on: ${{ matrix.os }} + + env: + CC: ${{ matrix.compiler.c }} + CXX: ${{ matrix.compiler.cpp }} + steps: # this Action should follow steps to set up Python build environment - uses: actions/checkout@v4 - - name: Set Flags - run: export USE_CUDA=0 + - name: Install Protoc Windows + if: ${{ startsWith(matrix.OS, 'windows') }} + uses: arduino/setup-protoc@v3 - - name: Install Protobuf + - name: Install Protoc Ubuntu + if: ${{ startsWith(matrix.OS, 'ubuntu') }} run: sudo apt install protobuf-compiler - name: Install Python dependencies @@ -35,14 +50,30 @@ jobs: with: path: "PyTorch_requirements.txt" - - name: Configure CMake + - name: Configure CMake ubuntu + if: ${{ startsWith(matrix.OS, 'ubuntu') }} # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type - run: cmake -DNT_TEST_COVERAGE=ON -DCMAKE_PREFIX_PATH=`python3 -c 'import torch;print(torch.utils.cmake_prefix_path)'` -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + run: | + cmake \ + -DNT_TEST_COVERAGE=ON \ + -DCMAKE_PREFIX_PATH=`python3 -c "import torch;print(torch.utils.cmake_prefix_path)"` \ + -B ${{github.workspace}}/build \ + -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + - name: Configure CMake windows + if: ${{ startsWith(matrix.OS, 'windows') }} + # on windows to get the pytorch config we have to + # run the same python command as before but now save it + # to a file then read from the file into a variable to pass to cmake + run: | + $Torch_DIR = python3 -c "import torch;print(torch.utils.cmake_prefix_path)" + echo "torch location: $Torch_DIR" + cmake -DNT_TEST_COVERAGE=ON -DCMAKE_PREFIX_PATH="$Torch_DIR" -B ${{github.workspace}}\build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + - name: Build # Build your program with the given configuration - run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --parallel 2 - name: Test working-directory: ${{github.workspace}}/build @@ -51,10 +82,14 @@ jobs: run: ctest -C ${{env.BUILD_TYPE}} - name: Generate Coverage Report + # only need to do this for one combination of OS and compiler + if: ${{ matrix.OS == 'ubuntu-latest' && matrix.compiler.c == 'gcc' }} working-directory: ${{github.workspace}}/build run: gcovr --json -o nuTens_coverage.json -r .. -f "../nuTens/*" - name: Upload coverage reports to Codecov + # only need to do this for one combination of OS and compiler + if: ${{ matrix.OS == 'ubuntu-latest' && matrix.compiler.c == 'gcc' }} uses: codecov/codecov-action@v4.0.1 with: verbose: true diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2820247..06b49fa 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,6 +1,6 @@ add_library(test-utils test-utils.hpp barger-propagator.hpp) -target_link_libraries(test-utils PUBLIC constants) +target_link_libraries(test-utils PUBLIC constants m) set_target_properties(test-utils PROPERTIES LINKER_LANGUAGE CXX) foreach(TESTNAME @@ -13,7 +13,7 @@ foreach(TESTNAME target_precompile_headers("${TESTNAME}" REUSE_FROM tensor) ENDIF() - target_link_libraries("${TESTNAME}" PUBLIC test-utils tensor propagator instrumentation) + target_link_libraries("${TESTNAME}" PUBLIC test-utils tensor propagator instrumentation m) target_include_directories("${TESTNAME}" PUBLIC "${CMAKE_SOURCE_DIR}") add_test(NAME "${TESTNAME}-test" COMMAND "${TESTNAME}")