From fde8cbbd196b2385d488389625e627e66c4a247a Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Sun, 5 Oct 2025 18:21:55 -0400 Subject: [PATCH 1/4] Clean up caches on closed PRs --- .github/workflows/cache-cleanup.yml | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/cache-cleanup.yml diff --git a/.github/workflows/cache-cleanup.yml b/.github/workflows/cache-cleanup.yml new file mode 100644 index 0000000000..98b2011cc2 --- /dev/null +++ b/.github/workflows/cache-cleanup.yml @@ -0,0 +1,33 @@ +# Modified from https://github.com/actions/cache/blob/main/tips-and-workarounds.md#force-deletion-of-caches-overriding-default-cache-eviction-policy +name: Clean up PR caches +on: + pull_request_target: + types: + - closed + +jobs: + cleanup: + runs-on: ubuntu-latest + permissions: + # `actions:write` permission is required to delete caches + # See also: https://docs.github.com/en/rest/actions/cache?apiVersion=2022-11-28#delete-a-github-actions-cache-for-a-repository-using-a-cache-id + actions: write + contents: read + steps: + - name: Clean up caches + run: | + ## Setting this to not fail the workflow while deleting cache keys. + set +e + for i in {1..10} + do + cacheIdsForPR=$(gh cache list -R $REPO -r $BRANCH -L 500 --sort size_in_bytes | cut -f 1 ) + for cacheId in $cacheIdsForPR + do + gh cache delete $cacheId -R $REPO + sleep 0.1 + done + done + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REPO: ${{ github.repository }} + BRANCH: refs/pull/${{ github.event.pull_request.number }}/merge From a08d1acfb016539ceea9e2afa3d23252bf370d92 Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Sun, 5 Oct 2025 18:22:15 -0400 Subject: [PATCH 2/4] Don't duplicate caches --- .github/workflows/vcpkg.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/vcpkg.yml b/.github/workflows/vcpkg.yml index ebd6b52434..9297efb329 100644 --- a/.github/workflows/vcpkg.yml +++ b/.github/workflows/vcpkg.yml @@ -45,6 +45,7 @@ jobs: uses: actions/checkout@v4 - name: Restore cache dependencies + id: cache-restore uses: actions/cache/restore@v3 with: path: ${{ matrix.binary_cache }} @@ -122,6 +123,8 @@ jobs: done - name: Save cache dependencies + # Don't save if it's the exact same + if: steps.cache-restore.outputs.cache-matched-key != format('{0}-{1}', matrix.os, hashFiles('vcpkg-info/*')) uses: actions/cache/save@v4 with: path: ${{ matrix.binary_cache }} From d26191ed5d37cb454384edc51b0c04eaf04c6ac8 Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Mon, 6 Oct 2025 21:16:32 -0400 Subject: [PATCH 3/4] Add option to disable precompiled headers --- cmake/GtsamAddPch.cmake | 4 ++-- cmake/HandleGeneralOptions.cmake | 4 ++++ cmake/HandlePrintConfiguration.cmake | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/cmake/GtsamAddPch.cmake b/cmake/GtsamAddPch.cmake index cb872e3612..88e23bedc2 100644 --- a/cmake/GtsamAddPch.cmake +++ b/cmake/GtsamAddPch.cmake @@ -14,7 +14,7 @@ macro(gtsamAddPch precompiledHeader precompiledSource sources) get_filename_component(pchBasename ${precompiledHeader} NAME_WE) SET(precompiledBinary "${CMAKE_CURRENT_BINARY_DIR}/${pchBasename}.pch") - IF(MSVC) + if(MSVC AND GTSAM_BUILD_WITH_PRECOMPILED_HEADERS) message(STATUS "Adding precompiled header for MSVC") set_source_files_properties(${precompiledSource} PROPERTIES COMPILE_FLAGS "/Yc\"${precompiledHeader}\" /Fp\"${precompiledBinary}\"" @@ -22,6 +22,6 @@ macro(gtsamAddPch precompiledHeader precompiledSource sources) set_source_files_properties(${sources} PROPERTIES COMPILE_FLAGS "/Yu\"${precompiledHeader}\" /FI\"${precompiledHeader}\" /Fp\"${precompiledBinary}\"" OBJECT_DEPENDS "${precompiledBinary}") - ENDIF(MSVC) + endif() endmacro(gtsamAddPch) diff --git a/cmake/HandleGeneralOptions.cmake b/cmake/HandleGeneralOptions.cmake index e5e2e194ac..c650c08578 100644 --- a/cmake/HandleGeneralOptions.cmake +++ b/cmake/HandleGeneralOptions.cmake @@ -20,6 +20,10 @@ if (NOT MSVC) option(GTSAM_BUILD_WITH_MARCH_NATIVE "Enable/Disable building with all instructions supported by native architecture (binary may not be portable!)" OFF) endif() +if(MSVC) + option(GTSAM_BUILD_WITH_PRECOMPILED_HEADERS "Enable/Disable building with precompiled headers" ON) +endif() + # Configurable Options option(BUILD_SHARED_LIBS "Build shared libraries" ON) if(GTSAM_UNSTABLE_AVAILABLE) diff --git a/cmake/HandlePrintConfiguration.cmake b/cmake/HandlePrintConfiguration.cmake index 300e594c40..56f7b4530e 100644 --- a/cmake/HandlePrintConfiguration.cmake +++ b/cmake/HandlePrintConfiguration.cmake @@ -22,6 +22,10 @@ if(GTSAM_UNSTABLE_AVAILABLE) print_enabled_config(${GTSAM_UNSTABLE_INSTALL_MATLAB_TOOLBOX} "Build MATLAB Toolbox for unstable") endif() +if(MSVC) + print_enabled_config(${GTSAM_BUILD_WITH_PRECOMPILED_HEADERS} "Build with precompiled headers") +endif() + if(NOT MSVC AND NOT XCODE_VERSION AND NOT QNX) print_enabled_config(${GTSAM_BUILD_WITH_MARCH_NATIVE} "Build for native architecture ") print_config("Build type" "${CMAKE_BUILD_TYPE}") From 2d797b5ae77cee0db889d635c2fa393316a94ec1 Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Sun, 5 Oct 2025 18:31:25 -0400 Subject: [PATCH 4/4] Use sccache for Windows release builds --- .github/workflows/build-windows.yml | 13 ++++++++++++- .github/workflows/vcpkg.yml | 13 +++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-windows.yml b/.github/workflows/build-windows.yml index bb689b8260..6a4408ce7a 100644 --- a/.github/workflows/build-windows.yml +++ b/.github/workflows/build-windows.yml @@ -6,6 +6,9 @@ on: - '**.md' - '**.ipynb' - 'myst.yml' + push: + # Runs on pushes targeting the develop branch + branches: [develop] # Cancels any in-progress workflow runs for the same PR when a new push is made, # allowing the runner to become available more quickly for the latest changes. @@ -25,6 +28,7 @@ jobs: GTSAM_BUILD_UNSTABLE: ${{ matrix.build_unstable }} BOOST_VERSION: 1.72.0 BOOST_EXE: boost_1_72_0-msvc-14.2 + SCCACHE_GHA_ENABLED: ON strategy: fail-fast: true @@ -93,6 +97,10 @@ jobs: # Set the BOOST_ROOT variable echo "BOOST_ROOT=$BOOST_PATH" >> $env:GITHUB_ENV + - name: Install sccache + if: matrix.build_type == 'Release' + uses: mozilla-actions/sccache-action@v0.0.9 + - name: Configuration shell: bash run: | @@ -106,9 +114,12 @@ jobs: -DGTSAM_ALLOW_DEPRECATED_SINCE_V43=OFF \ -DGTSAM_USE_BOOST_FEATURES=ON \ -DGTSAM_ENABLE_BOOST_SERIALIZATION=ON \ + -DGTSAM_BUILD_WITH_PRECOMPILED_HEADERS=OFF \ -DBOOST_ROOT="${BOOST_ROOT_UNIX}" \ -DBOOST_INCLUDEDIR="${BOOST_ROOT_UNIX}/include" \ - -DBOOST_LIBRARYDIR="${BOOST_ROOT_UNIX}/lib" + -DBOOST_LIBRARYDIR="${BOOST_ROOT_UNIX}/lib" \ + -DCMAKE_C_COMPILER_LAUNCHER=sccache \ + -DCMAKE_CXX_COMPILER_LAUNCHER=sccache else cmake -B build \ -DGTSAM_BUILD_EXAMPLES_ALWAYS=OFF \ diff --git a/.github/workflows/vcpkg.yml b/.github/workflows/vcpkg.yml index 9297efb329..4513138f8f 100644 --- a/.github/workflows/vcpkg.yml +++ b/.github/workflows/vcpkg.yml @@ -59,6 +59,18 @@ jobs: arch: x64 toolset: 14.40 + - name: Install sccache + if: runner.os == 'Windows' + uses: mozilla-actions/sccache-action@v0.0.9 + + - name: Use sccache + if: runner.os == 'Windows' + shell: bash + run: | + echo "SCCACHE_GHA_ENABLED=ON" >> "$GITHUB_ENV" + echo "CMAKE_C_COMPILER_LAUNCHER=sccache" >> "$GITHUB_ENV" + echo "CMAKE_CXX_COMPILER_LAUNCHER=sccache" >> "$GITHUB_ENV" + - name: cl version if: runner.os == 'Windows' shell: cmd @@ -149,6 +161,7 @@ jobs: -DVCPKG_HOST_TRIPLET=${{ matrix.triplet }} \ -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \ -DGTSAM_BUILD_EXAMPLES_ALWAYS=ON \ + -DGTSAM_BUILD_WITH_PRECOMPILED_HEADERS=OFF \ -DGTSAM_ROT3_EXPMAP=ON \ -DGTSAM_POSE3_EXPMAP=ON \ -DGTSAM_BUILD_PYTHON=ON \