-
Notifications
You must be signed in to change notification settings - Fork 1.6k
ci: Use ccache to cache build objects for speeding up building #6104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 27 commits
aec131b
30d2f70
89ea91a
5ca0577
efd2a33
ac71a5f
73ef462
a07399d
22ee2f5
6942b03
b38c500
b343926
ac96150
dd3c7d5
9cb4b78
22517d6
a5b944a
a621f02
4fed8fd
4efef6a
5570cc3
4f2b96f
1ada914
d1b928b
d3f1bbd
dde20ec
9c6fb66
e18eb78
e234117
a724ef4
40516a4
2c9556c
7d7e774
69fc941
d426525
9e4f769
9a91e42
a423a18
2e218fb
0adec9c
543e023
b1478f8
b2c896e
163faa7
40cbe13
f54db31
8c0543f
923e44d
e260a4f
364f04f
bc70a96
d387880
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,8 +66,9 @@ jobs: | |
| container: ${{ inputs.image != '' && inputs.image || null }} | ||
| timeout-minutes: 60 | ||
| env: | ||
| ENABLED_VOIDSTAR: ${{ contains(inputs.cmake_args, '-Dvoidstar=ON') }} | ||
| ENABLED_COVERAGE: ${{ contains(inputs.cmake_args, '-Dcoverage=ON') }} | ||
| CCACHE_ENABLED: ${{ github.event_name == 'pull_request' }} | ||
| COVERAGE_ENABLED: ${{ contains(inputs.cmake_args, '-Dcoverage=ON') }} | ||
| VOIDSTAR_ENABLED: ${{ contains(inputs.cmake_args, '-Dvoidstar=ON') }} | ||
| steps: | ||
| - name: Cleanup workspace (macOS and Windows) | ||
| if: ${{ runner.os == 'macOS' || runner.os == 'Windows' }} | ||
|
|
@@ -79,7 +80,7 @@ jobs: | |
| - name: Prepare runner | ||
| uses: XRPLF/actions/.github/actions/prepare-runner@99685816bb60a95a66852f212f382580e180df3a | ||
| with: | ||
| disable_ccache: false | ||
| disable_ccache: ${{ env.CCACHE_ENABLED == 'false' }} | ||
|
|
||
| - name: Print build environment | ||
| uses: ./.github/actions/print-env | ||
|
|
@@ -116,6 +117,17 @@ jobs: | |
| ${CMAKE_ARGS} \ | ||
| .. | ||
|
|
||
| - name: Restore ccache | ||
| if: ${{ env.CCACHE_ENABLED == 'true' }} | ||
| uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 | ||
| with: | ||
| path: ${{ env.CCACHE_DIR }} | ||
| key: ${{ inputs.config_name }} | ||
|
|
||
| - name: Show ccache statistics before building | ||
| if: ${{ env.CCACHE_ENABLED == 'true' }} | ||
| run: ccache --show-stats ${{ runner.debug && '-vv' || '' }} | ||
|
||
|
|
||
| - name: Build the binary | ||
| working-directory: ${{ inputs.build_dir }} | ||
| env: | ||
|
|
@@ -129,14 +141,25 @@ jobs: | |
| --parallel "${BUILD_NPROC}" \ | ||
| --target "${CMAKE_TARGET}" | ||
|
|
||
| - name: Show and reset ccache statistics after building | ||
| if: ${{ env.CCACHE_ENABLED == 'true' }} | ||
| run: | | ||
| ccache --show-stats ${{ runner.debug && '-vv' || '' }} | ||
| ccache --zero-stats | ||
|
|
||
| - name: Save ccache | ||
| if: ${{ env.CCACHE_ENABLED == 'true' }} | ||
| uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 | ||
|
||
| with: | ||
| path: ${{ env.CCACHE_DIR }} | ||
| key: ${{ inputs.config_name }} | ||
|
||
|
|
||
| - name: Upload rippled artifact (Linux) | ||
| if: ${{ github.repository_owner == 'XRPLF' && runner.os == 'Linux' }} | ||
| uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 | ||
| env: | ||
| BUILD_DIR: ${{ inputs.build_dir }} | ||
| with: | ||
| name: rippled-${{ inputs.config_name }} | ||
| path: ${{ env.BUILD_DIR }}/rippled | ||
| path: ${{ inputs.build_dir }}/rippled | ||
| retention-days: 3 | ||
| if-no-files-found: error | ||
|
|
||
|
|
@@ -153,7 +176,7 @@ jobs: | |
| fi | ||
|
|
||
| - name: Verify presence of instrumentation (Linux) | ||
| if: ${{ runner.os == 'Linux' && env.ENABLED_VOIDSTAR == 'true' }} | ||
| if: ${{ runner.os == 'Linux' && env.VOIDSTAR_ENABLED == 'true' }} | ||
| working-directory: ${{ inputs.build_dir }} | ||
| run: | | ||
| ./rippled --version | grep libvoidstar | ||
|
|
@@ -188,7 +211,7 @@ jobs: | |
| netstat -an | ||
|
|
||
| - name: Prepare coverage report | ||
| if: ${{ !inputs.build_only && env.ENABLED_COVERAGE == 'true' }} | ||
| if: ${{ !inputs.build_only && env.COVERAGE_ENABLED == 'true' }} | ||
| working-directory: ${{ inputs.build_dir }} | ||
| env: | ||
| BUILD_NPROC: ${{ steps.nproc.outputs.nproc }} | ||
|
|
@@ -201,7 +224,7 @@ jobs: | |
| --target coverage | ||
|
|
||
| - name: Upload coverage report | ||
| if: ${{ github.repository_owner == 'XRPLF' && !inputs.build_only && env.ENABLED_COVERAGE == 'true' }} | ||
| if: ${{ github.repository_owner == 'XRPLF' && !inputs.build_only && env.COVERAGE_ENABLED == 'true' }} | ||
| uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3 | ||
| with: | ||
| disable_search: true | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| find_program(CCACHE_PATH "ccache") | ||
| if (CCACHE_PATH) | ||
mathbunnyru marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (MSVC) | ||
| # Chocolatey uses a shim executable that we cannot use directly, in | ||
|
||
| # which case we have to find the executable it points to. If we cannot | ||
| # find the target executable then we cannot use ccache. | ||
| message(STATUS "Ccache path: ${CCACHE_PATH}") | ||
| if ("${CCACHE_PATH}" MATCHES "chocolatey") | ||
| find_program(BASH_PATH "bash") | ||
| if (NOT BASH_PATH) | ||
| message(WARNING "Could not find bash.") | ||
| return() | ||
| endif () | ||
| execute_process( | ||
| COMMAND bash -c "export LC_ALL='en_US.UTF-8'; ${CCACHE_PATH} --shimgen-noop | grep -oP 'path to executable: \\K.+' | head -c -1" | ||
| OUTPUT_VARIABLE CCACHE_PATH) | ||
| if (NOT CCACHE_PATH) | ||
| message(WARNING "Could not find ccache target.") | ||
| return() | ||
| endif () | ||
| file(TO_CMAKE_PATH "${CCACHE_PATH}" CCACHE_PATH) | ||
| endif () | ||
|
|
||
| # Tell cmake to use ccache for compiling with Visual Studio. | ||
| file(COPY_FILE | ||
| ${CCACHE_PATH} ${CMAKE_BINARY_DIR}/cl.exe | ||
| ONLY_IF_DIFFERENT) | ||
| set(CMAKE_VS_GLOBALS | ||
| "CLToolExe=cl.exe" | ||
| "CLToolPath=${CMAKE_BINARY_DIR}" | ||
| "TrackFileAccess=false" | ||
| "UseMultiToolTask=true") | ||
mathbunnyru marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # By default Visual Studio generators will use /Zi, which is not | ||
| # compatible with ccache, so tell it to use /Z7 instead. When running in | ||
| # CI the /Zi option will have already been stripped out, in which case | ||
| # the following will be a no-op, see XrplCompiler.cmake. | ||
mathbunnyru marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<$<CONFIG:Debug,RelWithDebInfo>:Embedded>") | ||
| else () | ||
| # For Linux and macOS we can use the ccache binary directly. | ||
| set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PATH}") | ||
| set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PATH}") | ||
| endif () | ||
| message(STATUS "Using ccache: ${CCACHE_PATH}") | ||
| endif () | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You always download cache, add files to it (while building new code), and then upload a bigger cache.
This will eventually grow the cache size, and make it useless
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I had hoped it would be more like Bazel/BuildBuddy where the least recently used files would be dropped automatically once a certain time/size limit was reached, but here the caches are considered as a whole unit and dropped entirely.
My original idea was to use ccache for caching across PRs, so unchanged files wouldn't need to be built again. It seems like that is not possible with the current set up. Should a separate cache be used per PR?
Per actions/cache#1071, one comment states "This functioning is expected and cache is built on the principle that "each key uniquely identifies a cache". if a cache contents have changed and you need to update it, its key should also reflect that.". So would this mean that each commit that modifies some source files needs its own cache? That entirely defeats the purpose...
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if that would work well in rippled's case, because it depends on how active people are pushing their PRs.
I think if there are many active PRs and they override the same cache, it's rarely going to work.
Clio doesn't create caches on PRs, only on commits on develop.
This also solves the problem with fork/non-fork.
And we add a commit hash to the cache id.