Skip to content

ci: fix sccache C++ caching on Windows for Python builds#174

Merged
cpsievert merged 7 commits intoposit-dev:mainfrom
cpsievert:ci/python-build-once-test-many
Mar 6, 2026
Merged

ci: fix sccache C++ caching on Windows for Python builds#174
cpsievert merged 7 commits intoposit-dev:mainfrom
cpsievert:ci/python-build-once-test-many

Conversation

@cpsievert
Copy link
Collaborator

@cpsievert cpsievert commented Mar 6, 2026

Summary

  • Fix sccache not caching C/C++ compilations (DuckDB) on Windows by adding ilammy/msvc-dev-cmd and setting CC/CXX='sccache cl'
  • Remove path filters so Python tests run on all repo changes (justified by the speed improvements below)

Problem

Windows Python builds take ~30 minutes vs ~7 min on other platforms. Investigation of sccache stats revealed that Windows gets zero C/C++ cache hits while Ubuntu gets ~350:

Ubuntu Windows (before)
sccache C/C++ hits 243 0
sccache C/C++ misses 106 0
Build time ~5 min ~27 min

The root cause: the cc crate's MSVC cl.exe detection (via find_msvc_tools) bypasses the RUSTC_WRAPPER-based sccache fallback that works automatically on Linux/macOS. The libduckdb-sys C++ build (~350 source files) was compiling from scratch every run.

Fix

Two additions to the workflow:

  1. ilammy/msvc-dev-cmd — Runs vcvarsall.bat to put cl.exe on PATH
  2. CC/CXX='sccache cl' (Windows only) — Makes the cc crate's env_tool parser recognize sccache as a known wrapper and cl as the compiler

Results

After the sccache cache was seeded (first run: 350 C/C++ misses, 0 write errors), the next run showed:

Before fix After fix
C/C++ cache hits 0 325 (93%)
Rust cache hits 232 (53%) 241 (55%)
Build time ~25 min ~12.5 min
Total job time ~30 min ~15 min

The Rust sccache is still warming up (55% hit rate), so further improvement is expected on subsequent runs as more Rust compilation results are cached.

Path filter removal

Previously the Python workflow only ran on changes to ggsql-python/ and the workflow file itself. Since the Python bindings depend on the core Rust library, changes elsewhere (parser, writer, reader) could break them silently. With Windows builds cut in half (~15 min and improving), running Python tests on all changes is now practical.

Test plan

  • Verify sccache sees C/C++ compilations on Windows (350 misses on seeding run)
  • Verify 0 sccache write errors (cache successfully stored)
  • Verify C/C++ cache hits on subsequent run (325 hits, 93% hit rate)
  • Verify Windows build time reduced (~30 min → ~15 min)
  • Verify Linux/macOS builds are unaffected

🤖 Generated with Claude Code

cpsievert and others added 3 commits March 6, 2026 09:40
Split the Python CI workflow into build and test phases. The build
job compiles the abi3 wheel once per OS, then test jobs download
and install it across Python 3.10-3.13. This avoids redundant Rust
compilation — particularly on Windows where builds take ~30 min each.

Also removes path filters so Python tests run on all repo changes,
since the build overhead is now minimal.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@cpsievert cpsievert marked this pull request as draft March 6, 2026 17:00
sccache sees zero C/C++ compilations on Windows because the cc crate
doesn't auto-detect sccache as a compiler wrapper with MSVC. Setting
CC_WRAPPER=sccache explicitly routes cl.exe calls through sccache,
enabling caching of DuckDB and other C/C++ dependency builds.

The first run will still be slow (all cache misses), but subsequent
runs should benefit from ~300 cached C/C++ compilation results.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@cpsievert cpsievert changed the title ci: build Python wheel once per OS, test across Python versions ci(python): Speed up Python wheel building on Windows Mar 6, 2026
cpsievert and others added 3 commits March 6, 2026 11:33
CC_WRAPPER didn't work because the cc crate doesn't check that env var.
The real issue: when the cc crate finds MSVC cl.exe via find_msvc_tools,
it bypasses the RUSTC_WRAPPER-based sccache fallback that works on Linux.

Setting CC/CXX='sccache cl' on Windows makes the cc crate's env_tool
parser recognize "sccache" as a known wrapper and "cl" as the compiler.
This routes the ~21-minute libduckdb-sys C++ build through sccache.

First run will still be slow (cache seeding), but subsequent runs should
see C/C++ cache hits and significantly faster Windows builds.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The previous attempt failed because sccache couldn't find bare 'cl' -
MSVC tools aren't on PATH by default. ilammy/msvc-dev-cmd runs vcvarsall
to set up the MSVC environment, putting cl.exe on PATH so that
'sccache cl' works as a CC/CXX wrapper.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…indows

Remove the build/test split since sccache should make Windows builds
fast enough (~5 min) that compiling per Python version is acceptable.

The diff from main is now minimal: remove path filters, add MSVC setup
+ CC/CXX env vars for sccache C++ caching on Windows.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@cpsievert cpsievert changed the title ci(python): Speed up Python wheel building on Windows ci: fix sccache C++ caching on Windows for Python builds Mar 6, 2026
@cpsievert cpsievert marked this pull request as ready for review March 6, 2026 20:49
@cpsievert cpsievert merged commit 84fa30f into posit-dev:main Mar 6, 2026
30 checks passed
@cpsievert cpsievert deleted the ci/python-build-once-test-many branch March 6, 2026 20:53
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.

1 participant