[build] Add ccache support for C/C++ compilation (SONIC_CONFIG_USE_CCACHE)#25650
[build] Add ccache support for C/C++ compilation (SONIC_CONFIG_USE_CCACHE)#25650lihuay merged 1 commit intosonic-net:masterfrom
Conversation
|
@copilot review |
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
Adds an opt-in SONIC_CONFIG_USE_CCACHE build knob to integrate ccache into the SONiC build environment, aiming to speed up incremental C/C++ rebuilds by caching compilation outputs.
Changes:
- Introduces
SONIC_CONFIG_USE_CCACHEconfiguration option (defaultn). - Installs
ccachein the bookworm and trixie sonic-slave images. - Injects a
CCACHE_ENVprefix into Debian package build commands and addsccache-stats/ccache-clearhelper targets.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
rules/config |
Adds SONIC_CONFIG_USE_CCACHE knob and documentation comment. |
slave.mk |
Defines CCACHE_ENV, prefixes build commands, prints knob value, and adds ccache helper targets. |
sonic-slave-bookworm/Dockerfile.j2 |
Installs ccache in the bookworm build container. |
sonic-slave-trixie/Dockerfile.j2 |
Installs ccache in the trixie build container. |
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines successfully started running 1 pipeline(s). |
6faeb06 to
e85a3e6
Compare
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines successfully started running 1 pipeline(s). |
e85a3e6 to
ba589dc
Compare
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines successfully started running 1 pipeline(s). |
ba589dc to
02a21f5
Compare
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines successfully started running 1 pipeline(s). |
02a21f5 to
2ce38e7
Compare
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines successfully started running 1 pipeline(s). |
2ce38e7 to
0a346c7
Compare
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines successfully started running 1 pipeline(s). |
6b480a2 to
3ae64e4
Compare
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines successfully started running 1 pipeline(s). |
yejianquan
left a comment
There was a problem hiding this comment.
LGTM. Well-designed opt-in knob:
- Default off, zero impact when disabled (CCACHE_ENV is empty)
- /usr/lib/ccache PATH prepend is the standard ccache integration pattern
- Per-BLDENV cache dir prevents cross-contamination
- CCACHE_COMPILERCHECK=content handles compiler upgrades correctly
- Error check for missing ccache binary is good
- ccache-stats/ccache-clear helper targets are useful
The build-report target removal looks unrelated -- was that intentional?
🤖 Posted by DevAce, Jianquan's AI Agent, on his behalf.
9192ef7 to
fc11338
Compare
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines successfully started running 1 pipeline(s). |
fc11338 to
0841f03
Compare
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines successfully started running 1 pipeline(s). |
0841f03 to
94ef299
Compare
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines successfully started running 1 pipeline(s). |
…ACHE) Add optional ccache integration to speed up incremental C/C++ builds. When SONIC_CONFIG_USE_CCACHE=y is set in rules/config, ccache intercepts gcc/g++ calls via /usr/lib/ccache PATH prepend and caches compilation results under target/ccache/<distro>/. Changes: - rules/config: Add SONIC_CONFIG_USE_CCACHE knob (default: n) - slave.mk: Define CCACHE_ENV with PATH, CCACHE_DIR, CCACHE_BASEDIR, and CCACHE_COMPILERCHECK; inject into dpkg-buildpackage and make build commands; add ccache-stats and ccache-clear targets; print config status in build info - sonic-slave-bookworm/Dockerfile.j2: Install ccache package - sonic-slave-trixie/Dockerfile.j2: Install ccache package Benefits: - First build populates the cache (minimal overhead from ccache lookups) - Subsequent builds with unchanged sources: near-instant recompilation - Key packages on the critical path (libswsscommon 2m, libsairedis 3m, swss 5m) benefit most from cache hits during iterative development - Cache is per-distro (bookworm/trixie) to avoid cross-contamination - CCACHE_COMPILERCHECK=content ensures cache validity across compiler updates Usage: echo 'SONIC_CONFIG_USE_CCACHE = y' >> rules/config.user make ccache-stats # view hit/miss statistics make ccache-clear # wipe cache Signed-off-by: Rustiqly <[email protected]>
94ef299 to
7cf0db8
Compare
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Description
[agent]
Add optional ccache integration to dramatically speed up incremental C/C++ builds. When
SONIC_CONFIG_USE_CCACHE=yis set, ccache intercepts gcc/g++ calls and caches object files, making recompilation of unchanged source near-instant.Motivation
The critical build path includes three C++ heavy packages:
These packages are on the serial critical path (libswsscommon → libsairedis → swss = ~10m). With a warm ccache, incremental rebuilds (e.g., when only one file changes in swss) drop from minutes to seconds.
Changes
rules/configSONIC_CONFIG_USE_CCACHEknob (default:n)slave.mkCCACHE_ENV, inject into build commands, addccache-stats/ccache-cleartargetssonic-slave-bookworm/Dockerfile.j2ccachepackagesonic-slave-trixie/Dockerfile.j2ccachepackageHow it works
ccacheis installed in the sonic-slave container (adds ~1MB)/usr/lib/ccacheis prepended toPATH— this directory contains symlinks (gcc,g++,cc,c++) that route through ccachetarget/ccache/<distro>/— persists across builds, per-distro to avoid cross-contaminationCCACHE_COMPILERCHECK=contentensures cache invalidation on compiler upgradesCCACHE_ENVis empty — zero impactUsage
Expected Impact
Backward Compatibility
n— no behavior change unless explicitly enabledccachepackage is installed but dormant when not enabledSONIC_DPKG_CACHE_METHOD) is orthogonal and works alongside ccacheTesting
Full VS build test pending with CI.