Skip to content

Commit 4e50bb3

Browse files
committed
Cache Rust builds with BoringCache
1 parent eea0399 commit 4e50bb3

4 files changed

Lines changed: 215 additions & 24 deletions

File tree

‎.boringcache.toml‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
workspace = "boringcache/nu"
2+
3+
[entries.cargo-registry-cache]
4+
tag = "cargo-registry-cache"
5+
6+
[entries.cargo-registry-index]
7+
tag = "cargo-registry-index"
8+
9+
[entries.cargo-git-db]
10+
tag = "cargo-git-db"
11+
12+
[entries.cargo-target]
13+
kind = "cargo-target"
14+
tag = "cargo-target-incremental"
15+
path = "target"
16+
17+
[entries.lint-cargo-registry-cache]
18+
tag = "lint-cargo-registry-cache"
19+
path = "~/.cargo/registry/cache"
20+
21+
[entries.lint-cargo-registry-index]
22+
tag = "lint-cargo-registry-index"
23+
path = "~/.cargo/registry/index"
24+
25+
[entries.lint-cargo-git-db]
26+
tag = "lint-cargo-git-db"
27+
path = "~/.cargo/git/db"
28+
29+
[entries.lint-cargo-target]
30+
kind = "cargo-target"
31+
tag = "lint-cargo-target-incremental"
32+
path = "target"
33+
34+
[entries.wasm-cargo-registry-cache]
35+
tag = "wasm-cargo-registry-cache"
36+
path = "~/.cargo/registry/cache"
37+
38+
[entries.wasm-cargo-registry-index]
39+
tag = "wasm-cargo-registry-index"
40+
path = "~/.cargo/registry/index"
41+
42+
[entries.wasm-cargo-git-db]
43+
tag = "wasm-cargo-git-db"
44+
path = "~/.cargo/git/db"
45+
46+
[entries.wasm-cargo-target]
47+
kind = "cargo-target"
48+
tag = "wasm-cargo-target-incremental"
49+
path = "target"
50+
51+
[profiles.cargo-target]
52+
entries = ["cargo-target"]
53+
54+
[profiles.cargo]
55+
entries = ["cargo-registry-cache", "cargo-registry-index", "cargo-git-db", "cargo-target"]
56+
57+
[profiles.lint-deps]
58+
entries = ["lint-cargo-registry-cache", "lint-cargo-registry-index", "lint-cargo-git-db"]
59+
60+
[profiles.lint-target]
61+
entries = ["lint-cargo-target"]
62+
63+
[profiles.wasm-deps]
64+
entries = ["wasm-cargo-registry-cache", "wasm-cargo-registry-index", "wasm-cargo-git-db"]
65+
66+
[profiles.wasm-target]
67+
entries = ["wasm-cargo-target"]
68+
69+
[adapters.cargo]
70+
profiles = ["cargo"]
71+
compiler-cache = "none"
72+
target-budget = "40GiB"

‎.github/workflows/ci.yml‎

Lines changed: 91 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
branches:
66
- main
77
- 'patch-release-*'
8+
- boringcache
89

910
name: Continuous Integration
1011

@@ -16,6 +17,7 @@ env:
1617
NU_LOG_LEVEL: DEBUG
1718
NU_TEST_SKIP_DEPS_BUILD: true
1819
NUSHELL_CARGO_PROFILE: ci
20+
CARGO_INCREMENTAL: "1"
1921

2022
concurrency:
2123
group: ${{ github.workflow }}-${{ github.head_ref && github.ref || github.run_id }}
@@ -33,6 +35,9 @@ jobs:
3335
github.event.pull_request.stack.position ==
3436
github.event.pull_request.stack.size
3537
)
38+
permissions:
39+
contents: read
40+
id-token: write
3641
env:
3742
build-target: ${{ matrix.platform.target }}
3843
working-directory: ${{ github.workspace }}
@@ -42,16 +47,25 @@ jobs:
4247
matrix:
4348
platform: &platforms
4449
- name: Linux
45-
runner: &runner_linux incredibuild-ubuntu-2204
50+
runner: &runner_linux ubuntu-22.04
4651
target: &target_linux x86_64-unknown-linux-gnu
4752
- name: Windows
4853
runner: &runner_windows incredibuild-windows-2022
4954
target: &target_windows x86_64-pc-windows-msvc
5055
- name: MacOS
51-
runner: &runner_macos incredibuild-macos-latest
52-
target: &target_macos x86_64-apple-darwin
56+
runner: &runner_macos macos-15
57+
target: &target_macos aarch64-apple-darwin
5358
steps:
5459

60+
- name: Runner Hardware
61+
shell: bash
62+
run: |
63+
case "$RUNNER_OS" in
64+
Linux) lscpu | grep -E '^(Model name|CPU\(s\)):'; free -h | head -2 ;;
65+
macOS) sysctl -n machdep.cpu.brand_string hw.ncpu hw.memsize ;;
66+
Windows) powershell -NoProfile -Command 'Get-CimInstance Win32_Processor | Format-List Name,NumberOfCores,NumberOfLogicalProcessors; Get-CimInstance Win32_ComputerSystem | Format-List TotalPhysicalMemory' ;;
67+
esac
68+
5569
- &step_checkout_repo
5670
name: Checkout Repo
5771
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
@@ -61,40 +75,49 @@ jobs:
6175
run: rustup target add ${{ env.build-target }}
6276
working-directory: ${{ env.working-directory }}
6377

64-
- &step_cache_rust
78+
- &step_cache_boringcache
6579
name: Cache Rust
66-
uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3
80+
uses: boringcache/one@1781572d7b3ec5aef652f8ba479b981439b2776b # v1.48.2
6781
with:
68-
workspaces: ${{ env.working-directory }} -> target
69-
cache-all-crates: true
70-
# Workspace crates are recompiled after an exact cache hit anyway (fingerprint
71-
# mismatch), while restoring them dominates Cache Rust on Windows (~2.8 GB, ~54s).
72-
# Cache dependencies only so restores stay small and useful.
73-
cache-workspace-crates: false
82+
mode: cargo
83+
working-directory: ${{ env.working-directory }}
7484

7585
# Fmt and Clippy run in the parallel lint job so they stay off the build/test critical path.
7686

7787
- &step_build
7888
name: Build
7989
working-directory: ${{ env.working-directory }}
8090
run: >-
81-
cargo --config "${{ github.workspace }}/.cargo/ci.toml"
91+
boringcache cargo --verbose --profile cargo-target
92+
--target-scope "root-${{ github.run_id }}-${{ github.run_attempt }}" --skip-restore --skip-save --
93+
--config "${{ github.workspace }}/.cargo/ci.toml"
8294
build ${{ env.cargo-options }}
8395
--profile ${{ env.profile }}
8496
8597
- &step_test
8698
name: Test
8799
working-directory: ${{ env.working-directory }}
88100
run: >-
89-
cargo --config "${{ github.workspace }}/.cargo/ci.toml"
101+
boringcache cargo --verbose --profile cargo-target
102+
--target-scope "root-${{ github.run_id }}-${{ github.run_attempt }}" --skip-restore --skip-save --
103+
--config "${{ github.workspace }}/.cargo/ci.toml"
90104
test ${{ env.cargo-options }}
91105
--profile ${{ env.profile }}
92106
107+
- name: Plugin process state on Linux failure
108+
if: failure() && runner.os == 'Linux'
109+
shell: bash
110+
run: >-
111+
ps -eo pid,ppid,stat,etimes,comm |
112+
awk 'NR == 1 || $1 == 1 || $5 == "nu_plugin_inc"'
113+
93114
- &step_doctest
94115
name: Doctest
95116
working-directory: ${{ env.working-directory }}
96117
run: >-
97-
cargo --config "${{ github.workspace }}/.cargo/ci.toml"
118+
boringcache cargo --verbose --profile cargo-target
119+
--target-scope "root-${{ github.run_id }}-${{ github.run_attempt }}" --skip-restore --skip-save --
120+
--config "${{ github.workspace }}/.cargo/ci.toml"
98121
test --workspace --doc
99122
--profile ${{ env.profile }}
100123
@@ -155,6 +178,9 @@ jobs:
155178
name: ${{ matrix.platform.name }} / lint
156179
runs-on: ${{ matrix.platform.runner }}
157180
if: *job_if
181+
permissions:
182+
contents: read
183+
id-token: write
158184
env:
159185
build-target: ${{ matrix.platform.target }}
160186
working-directory: ${{ github.workspace }}
@@ -166,7 +192,13 @@ jobs:
166192
steps:
167193
- *step_checkout_repo
168194
- *step_setup_rust_toolchain
169-
- *step_cache_rust
195+
196+
- name: Cache Rust
197+
uses: boringcache/one@1781572d7b3ec5aef652f8ba479b981439b2776b # v1.48.2
198+
with:
199+
mode: archive
200+
cache-profiles: lint-deps
201+
working-directory: ${{ env.working-directory }}
170202

171203
- &step_fmt
172204
name: Fmt
@@ -175,16 +207,17 @@ jobs:
175207
rustup component add rustfmt
176208
cargo fmt --all --check
177209
178-
- &step_clippy
179-
name: Clippy
210+
- name: Clippy
211+
shell: bash
180212
env:
181213
CARGO_BUILD_WARNINGS: deny
182214
working-directory: ${{ env.working-directory }}
183215
run: >-
184216
rustup component add clippy
185217
186-
cargo --config "${{ github.workspace }}/.cargo/ci.toml"
187-
clippy ${{ env.cargo-options }}
218+
boringcache cargo --verbose --profile lint-target --
219+
--config "${{ github.workspace }}/.cargo/ci.toml"
220+
clippy ${{ env.cargo-options }}
188221
--profile ${{ env.profile }}
189222
190223
- *step_assert_clean_repo
@@ -193,6 +226,9 @@ jobs:
193226
name: WASM / root
194227
runs-on: *runner_linux
195228
if: *job_if
229+
permissions:
230+
contents: read
231+
id-token: write
196232
env:
197233
build-target: wasm32-unknown-unknown
198234
working-directory: ${{ github.workspace }}
@@ -222,21 +258,41 @@ jobs:
222258
steps:
223259
- *step_checkout_repo
224260
- *step_setup_rust_toolchain
225-
- *step_cache_rust
261+
- name: Cache Rust
262+
uses: boringcache/one@1781572d7b3ec5aef652f8ba479b981439b2776b # v1.48.2
263+
with:
264+
mode: archive
265+
cache-profiles: wasm-deps
266+
working-directory: ${{ env.working-directory }}
226267
- name: Check
268+
shell: bash
227269
working-directory: ${{ env.working-directory }}
228270
run: >-
229-
cargo --config "${{ github.workspace }}/.cargo/ci.toml"
271+
boringcache cargo --verbose --profile wasm-target
272+
--target-scope "wasm-${{ github.run_id }}-${{ github.run_attempt }}" --skip-save --
273+
--config "${{ github.workspace }}/.cargo/ci.toml"
230274
check ${{ env.cargo-options }}
231275
--profile ${{ env.profile }}
232276
233-
- *step_build
277+
- name: Build
278+
shell: bash
279+
working-directory: ${{ env.working-directory }}
280+
run: >-
281+
boringcache cargo --verbose --profile wasm-target
282+
--target-scope "wasm-${{ github.run_id }}-${{ github.run_attempt }}" --skip-restore --
283+
--config "${{ github.workspace }}/.cargo/ci.toml"
284+
build ${{ env.cargo-options }}
285+
--profile ${{ env.profile }}
286+
234287
- *step_assert_clean_repo
235288

236289
fuzz:
237290
name: ${{ matrix.platform.name }} / ${{ matrix.crate }} / fuzz
238291
runs-on: ${{ matrix.platform.runner }}
239292
if: *job_if
293+
permissions:
294+
contents: read
295+
id-token: write
240296
env:
241297
build-target: ${{ matrix.platform.target }}
242298
working-directory: ${{ github.workspace }}/crates/${{ matrix.crate }}/fuzz
@@ -251,7 +307,18 @@ jobs:
251307
steps:
252308
- *step_checkout_repo
253309
- *step_setup_rust_toolchain
254-
- *step_cache_rust
310+
- *step_cache_boringcache
255311
- *step_fmt
256-
- *step_clippy
312+
- &step_clippy
313+
name: Clippy
314+
env:
315+
CARGO_BUILD_WARNINGS: deny
316+
working-directory: ${{ env.working-directory }}
317+
run: >-
318+
rustup component add clippy
319+
320+
boringcache cargo --verbose --profile cargo-target --skip-restore --skip-save --
321+
--config "${{ github.workspace }}/.cargo/ci.toml"
322+
clippy ${{ env.cargo-options }}
323+
--profile ${{ env.profile }}
257324
- *step_assert_clean_repo
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
workspace = "boringcache/nu"
2+
3+
[entries.cargo-registry-cache]
4+
tag = "fuzz-nu-parser-cargo-registry-cache"
5+
6+
[entries.cargo-registry-index]
7+
tag = "fuzz-nu-parser-cargo-registry-index"
8+
9+
[entries.cargo-git-db]
10+
tag = "fuzz-nu-parser-cargo-git-db"
11+
12+
[entries.cargo-target]
13+
kind = "cargo-target"
14+
tag = "fuzz-nu-parser-cargo-target-incremental"
15+
path = "target"
16+
17+
[profiles.cargo-target]
18+
entries = ["cargo-target"]
19+
20+
[profiles.cargo]
21+
entries = ["cargo-registry-cache", "cargo-registry-index", "cargo-git-db", "cargo-target"]
22+
23+
[adapters.cargo]
24+
profiles = ["cargo"]
25+
compiler-cache = "none"
26+
target-budget = "40GiB"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
workspace = "boringcache/nu"
2+
3+
[entries.cargo-registry-cache]
4+
tag = "fuzz-nu-path-cargo-registry-cache"
5+
6+
[entries.cargo-registry-index]
7+
tag = "fuzz-nu-path-cargo-registry-index"
8+
9+
[entries.cargo-git-db]
10+
tag = "fuzz-nu-path-cargo-git-db"
11+
12+
[entries.cargo-target]
13+
kind = "cargo-target"
14+
tag = "fuzz-nu-path-cargo-target-incremental"
15+
path = "target"
16+
17+
[profiles.cargo-target]
18+
entries = ["cargo-target"]
19+
20+
[profiles.cargo]
21+
entries = ["cargo-registry-cache", "cargo-registry-index", "cargo-git-db", "cargo-target"]
22+
23+
[adapters.cargo]
24+
profiles = ["cargo"]
25+
compiler-cache = "none"
26+
target-budget = "40GiB"

0 commit comments

Comments
 (0)