From aee1c8a1b86ccce39bda77ab83b952ce2623fb2e Mon Sep 17 00:00:00 2001 From: Yasel Quintero Date: Wed, 6 Mar 2024 21:16:31 +0100 Subject: [PATCH 1/2] Use ccache to speed up the GitHub Actions workflow build process ccache works out of the box for the GNU compilers in Ubuntu and the Clang compiler in MacOS. The MSVC compilers require an extra configuration step which was added to the CMakeLists file. --- .github/workflows/build_and_test.yml | 16 +++++++++++----- CMakeLists.txt | 25 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index b32235d65e..a95cffc5db 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -124,6 +124,11 @@ jobs: run: | echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" + - name: Setup ccache + # This third party action will setup ccache on the runner and restore any previously saved cache. Caches are saved automatically by the action after a build. + uses: hendrikmuhs/ccache-action@v1.2.12 + with: + key: ${{ matrix.os }}-${{ matrix.type }} - name: Configure CMake # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. @@ -131,18 +136,19 @@ jobs: shell: bash -l {0} run: > cmake -B "${{ steps.strings.outputs.build-output-dir }}" + -S "${{ github.workspace }}" + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} - -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} - -S "${{ github.workspace }}" - - + -DCMAKE_C_COMPILER_LAUNCHER=ccache + -DTUDAT_BUILD_GITHUB_ACTIONS=ON + - name: Build # Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). Use multiple cpu cores available in the runner. shell: bash -l {0} run: cmake --build "${{ steps.strings.outputs.build-output-dir }}" --config "${{ matrix.build_type }}" -j4 - - name: Test working-directory: ${{ steps.strings.outputs.build-output-dir }} # Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). diff --git a/CMakeLists.txt b/CMakeLists.txt index ba7e2f837e..217e82a328 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,6 +86,31 @@ else() option(TUDAT_BUILD_WITH_EXTENDED_PRECISION_PROPAGATION_TOOLS "Build tudat with extended precision propagation tools." OFF) endif() +# Build as part of a GitHub Actions workflow +# Option enables the use of ccache by MSVC +# see https://github.com/ccache/ccache/wiki/MS-Visual-Studio +option(TUDAT_BUILD_GITHUB_ACTIONS "Build as part of GitHub Actions workflow." OFF) +if (TUDAT_BUILD_GITHUB_ACTIONS AND MSVC) + find_program(ccache_exe ccache) + if(ccache_exe) + message(STATUS "CONFIGURING MSVC FOR CCACHE") + file(COPY_FILE ${ccache_exe} ${CMAKE_BINARY_DIR}/cl.exe ONLY_IF_DIFFERENT) + + # By default Visual Studio generators will use /Zi which is not compatible + # with ccache, so tell Visual Studio to use /Z7 instead. + message(STATUS "Setting MSVC debug information format to 'Embedded'") + set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<$:Embedded>") + + set(CMAKE_VS_GLOBALS + "CLToolExe=cl.exe" + "CLToolPath=${CMAKE_BINARY_DIR}" + "TrackFileAccess=false" + "UseMultiToolTask=true" + "DebugInformationFormat=OldStyle" + ) + endif() +endif() + message(STATUS "******************** BUILD CONFIGURATION ********************") message(STATUS "TUDAT_BUILD_TESTS ${TUDAT_BUILD_TESTS}") message(STATUS "TUDAT_BUILD_WITH_PROPAGATION_TESTS ${TUDAT_BUILD_WITH_PROPAGATION_TESTS}") From c7628e89372cd1e21d1ad549fa14229d78d2b21c Mon Sep 17 00:00:00 2001 From: Yasel Quintero Date: Wed, 13 Mar 2024 14:26:27 +0100 Subject: [PATCH 2/2] Remove 'Set reusable strings' step from workflow --- .github/workflows/build_and_test.yml | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index a95cffc5db..7d5859b870 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -117,25 +117,19 @@ jobs: run: cmd /c "curl -fsSL https://raw.githubusercontent.com/tudat-team/tudat-resources-feedstock/master/recipe/post-link.bat | cmd" - - name: Set reusable strings - # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file. - id: strings - shell: bash -l {0} - run: | - echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" - - name: Setup ccache # This third party action will setup ccache on the runner and restore any previously saved cache. Caches are saved automatically by the action after a build. uses: hendrikmuhs/ccache-action@v1.2.12 with: key: ${{ matrix.os }}-${{ matrix.type }} + - name: Configure CMake # 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 shell: bash -l {0} run: > - cmake -B "${{ steps.strings.outputs.build-output-dir }}" + cmake -B "${{ github.workspace }}/build" -S "${{ github.workspace }}" -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} @@ -143,14 +137,16 @@ jobs: -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} -DCMAKE_C_COMPILER_LAUNCHER=ccache -DTUDAT_BUILD_GITHUB_ACTIONS=ON - + + - name: Build # Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). Use multiple cpu cores available in the runner. shell: bash -l {0} - run: cmake --build "${{ steps.strings.outputs.build-output-dir }}" --config "${{ matrix.build_type }}" -j4 + run: cmake --build "${{ github.workspace }}/build" --config "${{ matrix.build_type }}" -j4 + - name: Test - working-directory: ${{ steps.strings.outputs.build-output-dir }} + working-directory: "${{ github.workspace }}/build" # Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail # Prevent the action from failing if any of the tests fail by using `|| true`. This is placed temporarily because currently, some tests fail on MacOS, and if the action fails, the cache is not updated, which prevents testing of the cache feature on MacOS.