Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@saahu27
Copy link
Contributor

@saahu27 saahu27 commented Oct 1, 2025

Add comprehensive CI caching to speed up builds (fixes #1161)

Problem

Currently, the Python wheel build process rebuilds Boost, yaml-cpp, and CastXML from source for every Python version (3.10, 3.11, 3.12, 3.13) on every platform (Linux x86_64, Linux ARM64, macOS x86, macOS ARM64) on every CI run. Additionally, the main build & test workflow rebuilds everything from scratch on every push/PR. This results in unnecessarily long CI times.

Solution

This PR implements dependency caching for Python wheel builds (resolving issue #1161) and extends comprehensive caching to the build & test workflow to significantly reduce CI build times.

Expected Impact

Wheel Builds

  • First build: ~45 min (unchanged - cache miss)
  • Subsequent builds: ~10 min (was ~45 min)

Build & Test (PR/Push)

  • Incremental changes: ~4-6 min (was ~15 min)

Changes Made

1. .github/workflows/wheels.yaml:

  • Added cache restore step before building wheels
  • Added cache save step after building wheels (only when cache misses)
  • Cache is keyed by: deps-{platform}-boost-{version}-yaml-{version}-castxml-{version}
  • Different environment variable handling for Linux (containerized) vs macOS (native)

2. .github/workflows/before_build.sh:

  • Modified install_boost(), install_yaml_cpp(), and install_castxml() functions to check for cached dependencies
  • If cached dependencies exist, they are restored instead of being rebuilt
  • After building, dependencies are saved to cache for future use
  • Cache directory passed via OMPL_DEPS_CACHE_DIR environment variable

3. .github/workflows/build.yml:

Comprehensive caching for the main build & test workflow.

What's cached:

a. ccache

  • C++ object file caching across builds
  • 50-70% faster C++ compilation on cache hits
  • Uses hendrikmuhs/[email protected]
  • Configured CMake to use ccache via CMAKE_C_COMPILER_LAUNCHER and CMAKE_CXX_COMPILER_LAUNCHER

b. CMake build artifacts

  • Caches the entire build directory
  • Enables incremental builds (only rebuild changed files)
  • Keyed by CMakeLists.txt and src/** changes

c. Package manager caches

  • Linux: APT package cache (/var/cache/apt)
    • Saves 1-2 minutes per build
  • macOS: Homebrew cache + Cellar
    • Saves 3-5 minutes per build
    • Added HOMEBREW_NO_AUTO_UPDATE=1 to disable auto-update
    • Added HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 to speed up installs

Advantages

  • build time reduction: First build for each configuration still builds from source, but subsequent builds reuse cached dependencies
  • Cross-Python version efficiency: Each Python version (3.10-3.13) can share the same cached Boost build specific to that version
  • Platform-specific caching: Separate caches for each OS/architecture combination
  • Backward compatible: If caching fails or cache is unavailable, builds fall back to building from source
  • Reduced CI costs: Less compute time per build

Technical Details

Cache Keys

# Wheel builds
deps-{platform}-boost-1.87.0-yaml-0.8.0-castxml-0.6.11

# Build artifacts
cmake-build-{platform}-{hash(CMakeLists.txt,src/**)}

# Package managers
apt-{platform}-{hash(build.yml)}
brew-{platform}-{hash(build.yml)}

# ccache
{platform}-ccache-{branch}

All caches use restore-keys for partial matches to maximize cache hit rates.

Testing

  • Cache miss scenario: Dependencies built from source (current behavior)
  • Cache hit scenario: Dependencies restored from cache
  • Fallback behavior: Works without OMPL_DEPS_CACHE_DIR set

Related Issues

Fixes #1161

Files Changed

  • .github/workflows/wheels.yaml - Python wheel caching
  • .github/workflows/before_build.sh - Dependency caching logic
  • .github/workflows/build.yml - Build & test caching

- Add GitHub Actions cache for Boost, yaml-cpp, and CastXML dependencies
- Cache is keyed by OS, architecture, and dependency versions
- Modified before_build.sh to check for cached dependencies before building
- Significant build time reduction expected for wheel builds across multiple Python versions
- Fixes issue ompl#1161: Use cache to speed up CI for Python wheels
- Add ccache for C++ compilation (50-70% faster on cache hits)
- Cache CMake build artifacts for incremental builds
- Cache APT packages (Linux) to avoid re-downloading
- Cache Homebrew packages (macOS) to speed up dependency installation
- Disable Homebrew auto-update to save time
- Configure CMake to use ccache compiler launcher

Expected impact:
- 40-60% faster build times for incremental changes
- 3-5 minutes saved on macOS builds
- 1-2 minutes saved on Linux builds
- Faster PR feedback for developers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use cache to speed up CI for Python wheels

1 participant