Skip to content

Commit bd4eafe

Browse files
committed
ci: cache native dependency builds in Verify jobs
Verify restores the dependency builds that a new Rust Build Cache workflow saves on main, so pull requests stop rebuilding polyglot-sql and the other dependencies from scratch. The linux-x86_64 wheel job records cargo build timing reports.
1 parent bb1c502 commit bd4eafe

3 files changed

Lines changed: 205 additions & 2 deletions

File tree

‎.github/workflows/build-distributions.yml‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,29 @@ jobs:
124124
if: inputs.prebuilt-run-id == ''
125125
with:
126126
command: build
127-
args: --release --out dist --features extension-module
127+
# One platform records a cargo build timing report for build time work.
128+
args: >-
129+
--release --out dist --features extension-module
130+
${{ matrix.platform.name == 'linux-x86_64' && '--timings' || '' }}
128131
target: ${{ matrix.platform.target }}
129132
manylinux: auto
130133
- uses: PyO3/maturin-action@v1
131134
if: inputs.prebuilt-run-id == ''
132135
with:
133136
command: build
134-
args: --release --out dist --manifest-path crates/sqlbuild-cli/Cargo.toml
137+
args: >-
138+
--release --out dist --manifest-path crates/sqlbuild-cli/Cargo.toml
139+
${{ matrix.platform.name == 'linux-x86_64' && '--timings' || '' }}
135140
target: ${{ matrix.platform.target }}
136141
manylinux: auto
142+
- name: Upload the cargo build timing reports
143+
if: inputs.prebuilt-run-id == '' && matrix.platform.name == 'linux-x86_64'
144+
uses: actions/upload-artifact@v4
145+
with:
146+
name: cargo-timings-${{ matrix.platform.name }}
147+
path: target/cargo-timings/cargo-timing-*.html
148+
if-no-files-found: warn
149+
retention-days: 30
137150
- name: Download prebuilt wheels
138151
if: inputs.prebuilt-run-id != ''
139152
uses: actions/download-artifact@v4

‎.github/workflows/rust-cache.yml‎

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
name: Rust Build Cache
2+
3+
# Saves the native dependency builds that Verify restores. Verify never saves its own: a cache saved
4+
# by a pull request or merge queue run is visible only to that ref, while one saved on main is
5+
# visible to every pull request. Each job runs the same cargo builds as the Verify jobs sharing its
6+
# key, so the cached artifacts match theirs, and builds only when main has no cache for the current
7+
# lockfile and toolchain. Release distributions never use these caches.
8+
on:
9+
push:
10+
branches: [main]
11+
# A new stable toolchain changes the key without a push to main.
12+
schedule:
13+
- cron: "30 4 * * *"
14+
workflow_dispatch:
15+
16+
permissions:
17+
contents: read
18+
19+
concurrency:
20+
group: rust-cache-${{ github.ref }}
21+
cancel-in-progress: false
22+
23+
jobs:
24+
linux:
25+
name: Linux extension
26+
runs-on: ubuntu-24.04
27+
timeout-minutes: 60
28+
steps:
29+
- uses: actions/checkout@v4
30+
- uses: astral-sh/setup-uv@v5
31+
with:
32+
version: "0.12.3"
33+
- uses: dtolnay/rust-toolchain@master
34+
with:
35+
toolchain: stable
36+
- name: Look up the cache
37+
id: lookup
38+
uses: Swatinem/rust-cache@v2
39+
with:
40+
shared-key: verify-linux
41+
lookup-only: true
42+
save-if: false
43+
- name: Restore the closest cache
44+
if: steps.lookup.outputs.cache-hit != 'true'
45+
uses: Swatinem/rust-cache@v2
46+
with:
47+
shared-key: verify-linux
48+
- name: Install Python
49+
if: steps.lookup.outputs.cache-hit != 'true'
50+
run: uv python install 3.12
51+
- name: Build the extension as Verify does
52+
if: steps.lookup.outputs.cache-hit != 'true'
53+
run: uv sync --locked --all-groups --all-extras
54+
55+
checks:
56+
name: Linux extension and native checks
57+
runs-on: ubuntu-24.04
58+
timeout-minutes: 60
59+
steps:
60+
- uses: actions/checkout@v4
61+
- uses: astral-sh/setup-uv@v5
62+
with:
63+
version: "0.12.3"
64+
- uses: dtolnay/rust-toolchain@master
65+
with:
66+
toolchain: stable
67+
- name: Look up the cache
68+
id: lookup
69+
uses: Swatinem/rust-cache@v2
70+
with:
71+
shared-key: verify-checks
72+
lookup-only: true
73+
save-if: false
74+
- name: Restore the closest cache
75+
if: steps.lookup.outputs.cache-hit != 'true'
76+
uses: Swatinem/rust-cache@v2
77+
with:
78+
shared-key: verify-checks
79+
- name: Install Python
80+
if: steps.lookup.outputs.cache-hit != 'true'
81+
run: uv python install 3.12
82+
- name: Build the extension as Verify does
83+
if: steps.lookup.outputs.cache-hit != 'true'
84+
run: uv sync --locked --all-groups --all-extras
85+
- name: Build the native checks as make rust-check does
86+
if: steps.lookup.outputs.cache-hit != 'true'
87+
run: |
88+
cargo clippy --workspace --all-targets --all-features -- -D warnings
89+
cargo test --workspace --all-features --no-run
90+
91+
windows:
92+
name: Windows extension
93+
runs-on: windows-2025
94+
timeout-minutes: 60
95+
defaults:
96+
run:
97+
shell: bash
98+
steps:
99+
- uses: actions/checkout@v4
100+
- uses: astral-sh/setup-uv@v5
101+
with:
102+
version: "0.12.3"
103+
- uses: dtolnay/rust-toolchain@master
104+
with:
105+
toolchain: stable
106+
- name: Look up the cache
107+
id: lookup
108+
uses: Swatinem/rust-cache@v2
109+
with:
110+
shared-key: verify-windows
111+
lookup-only: true
112+
save-if: false
113+
- name: Restore the closest cache
114+
if: steps.lookup.outputs.cache-hit != 'true'
115+
uses: Swatinem/rust-cache@v2
116+
with:
117+
shared-key: verify-windows
118+
- name: Build the native discovery tests as Verify does
119+
if: steps.lookup.outputs.cache-hit != 'true'
120+
run: cargo test --locked -p sqlbuild-discovery --no-run
121+
- name: Install Python
122+
if: steps.lookup.outputs.cache-hit != 'true'
123+
run: uv python install 3.12
124+
- name: Build the extension as Verify does
125+
if: steps.lookup.outputs.cache-hit != 'true'
126+
run: uv sync --locked --no-dev --python 3.12

‎.github/workflows/verify.yml‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,13 @@ jobs:
268268
- uses: dtolnay/rust-toolchain@master
269269
with:
270270
toolchain: stable
271+
# Restores the native dependency builds that rust-cache.yml saves on main; workspace crates
272+
# always build from source. Verify never saves: a pull request or merge queue cache is
273+
# visible only to its own ref. Jobs that run the same cargo builds share a key.
274+
- uses: Swatinem/rust-cache@v2
275+
with:
276+
shared-key: verify-checks
277+
save-if: false
271278
- name: Install Python
272279
run: uv python install 3.12
273280
- name: Install dependencies
@@ -315,6 +322,10 @@ jobs:
315322
- uses: dtolnay/rust-toolchain@master
316323
with:
317324
toolchain: stable
325+
- uses: Swatinem/rust-cache@v2
326+
with:
327+
shared-key: verify-linux
328+
save-if: false
318329
- name: Install Python
319330
run: uv python install 3.12
320331
- name: Install dependencies
@@ -355,6 +366,10 @@ jobs:
355366
- uses: dtolnay/rust-toolchain@master
356367
with:
357368
toolchain: stable
369+
- uses: Swatinem/rust-cache@v2
370+
with:
371+
shared-key: verify-linux
372+
save-if: false
358373
- name: Install Python
359374
run: uv python install 3.12
360375
- name: Install dependencies
@@ -398,6 +413,10 @@ jobs:
398413
- uses: dtolnay/rust-toolchain@master
399414
with:
400415
toolchain: stable
416+
- uses: Swatinem/rust-cache@v2
417+
with:
418+
shared-key: verify-linux
419+
save-if: false
401420
- name: Install Python
402421
run: uv python install ${{ matrix.python }}
403422
- name: Install dependencies
@@ -431,6 +450,10 @@ jobs:
431450
- uses: dtolnay/rust-toolchain@master
432451
with:
433452
toolchain: stable
453+
- uses: Swatinem/rust-cache@v2
454+
with:
455+
shared-key: verify-windows
456+
save-if: false
434457
- name: Test the native discovery crate (walk, junctions, ordering, read errors)
435458
run: cargo test --locked -p sqlbuild-discovery
436459
- name: Install Python
@@ -481,6 +504,10 @@ jobs:
481504
- uses: dtolnay/rust-toolchain@master
482505
with:
483506
toolchain: stable
507+
- uses: Swatinem/rust-cache@v2
508+
with:
509+
shared-key: verify-linux
510+
save-if: false
484511
- name: Install Python
485512
run: uv python install 3.12
486513
- name: Install dependencies
@@ -512,6 +539,10 @@ jobs:
512539
- uses: dtolnay/rust-toolchain@master
513540
with:
514541
toolchain: stable
542+
- uses: Swatinem/rust-cache@v2
543+
with:
544+
shared-key: verify-linux
545+
save-if: false
515546
- name: Install Python
516547
run: uv python install 3.12
517548
- name: Install dependencies
@@ -541,6 +572,10 @@ jobs:
541572
- uses: dtolnay/rust-toolchain@master
542573
with:
543574
toolchain: stable
575+
- uses: Swatinem/rust-cache@v2
576+
with:
577+
shared-key: verify-linux
578+
save-if: false
544579
- name: Install Python
545580
run: uv python install 3.12
546581
- name: Install dependencies
@@ -589,6 +624,10 @@ jobs:
589624
- uses: dtolnay/rust-toolchain@master
590625
with:
591626
toolchain: stable
627+
- uses: Swatinem/rust-cache@v2
628+
with:
629+
shared-key: verify-linux
630+
save-if: false
592631
- name: Install Python
593632
run: uv python install 3.12
594633
- name: Install dependencies
@@ -668,8 +707,17 @@ jobs:
668707
- uses: dtolnay/rust-toolchain@master
669708
with:
670709
toolchain: stable
710+
- uses: Swatinem/rust-cache@v2
711+
with:
712+
shared-key: verify-linux
713+
save-if: false
671714
- name: Install Python
672715
run: uv python install 3.12
716+
- name: Seed the base build directory with the cached dependency builds
717+
run: |
718+
if [[ -d target ]]; then
719+
cp -a target base/target
720+
fi
673721
- name: Install head dependencies
674722
run: uv sync --locked --all-groups --all-extras
675723
- name: Install base dependencies
@@ -734,6 +782,10 @@ jobs:
734782
- uses: dtolnay/rust-toolchain@master
735783
with:
736784
toolchain: stable
785+
- uses: Swatinem/rust-cache@v2
786+
with:
787+
shared-key: verify-linux
788+
save-if: false
737789
- name: Install Python
738790
run: uv python install 3.12
739791
- name: Install dependencies
@@ -801,6 +853,10 @@ jobs:
801853
- uses: dtolnay/rust-toolchain@master
802854
with:
803855
toolchain: stable
856+
- uses: Swatinem/rust-cache@v2
857+
with:
858+
shared-key: verify-linux
859+
save-if: false
804860
- name: Install Python
805861
run: uv python install 3.12
806862
- name: Install dependencies
@@ -847,6 +903,10 @@ jobs:
847903
- uses: dtolnay/rust-toolchain@master
848904
with:
849905
toolchain: stable
906+
- uses: Swatinem/rust-cache@v2
907+
with:
908+
shared-key: verify-linux
909+
save-if: false
850910
- name: Install Python
851911
run: uv python install 3.12
852912
- name: Install dependencies
@@ -880,6 +940,10 @@ jobs:
880940
- uses: dtolnay/rust-toolchain@master
881941
with:
882942
toolchain: stable
943+
- uses: Swatinem/rust-cache@v2
944+
with:
945+
shared-key: verify-linux
946+
save-if: false
883947
- name: Install Python
884948
run: uv python install 3.12
885949
- name: Install dependencies

0 commit comments

Comments
 (0)