Skip to content

Commit fcaa4b1

Browse files
authored
Add optimizations for CI tests (#720)
* Add sccache to CI tests * Separate lint, build, and test CI's
1 parent e186995 commit fcaa4b1

File tree

1 file changed

+87
-21
lines changed

1 file changed

+87
-21
lines changed

.circleci/config.yml

Lines changed: 87 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,45 @@
11
version: 2.1
2+
commands:
3+
setup-and-restore-sccache-cache:
4+
steps:
5+
- run:
6+
name: Install sccache
7+
command: |
8+
wget https://github.com/mozilla/sccache/releases/download/v0.4.2/sccache-v0.4.2-x86_64-unknown-linux-musl.tar.gz \
9+
&& tar xzf sccache-v0.4.2-x86_64-unknown-linux-musl.tar.gz \
10+
&& mkdir -p $HOME/.local/bin\
11+
&& mv sccache-v0.4.2-x86_64-unknown-linux-musl/sccache $HOME/.local/bin/sccache \
12+
&& chmod +x $HOME/.local/bin/sccache
13+
# This configures Rust to use sccache.
14+
echo 'export "RUSTC_WRAPPER"="$HOME/.local/bin/sccache"' >> $BASH_ENV
15+
# This is the maximum space sccache cache will use on disk.
16+
echo 'export "SCCACHE_CACHE_SIZE"="1G"' >> $BASH_ENV
17+
$HOME/.local/bin/sccache --version
18+
- restore_cache:
19+
name: Restore sccache cache
20+
key: sccache-cache-stable-{{ arch }}-{{ .Environment.CIRCLE_JOB }}
21+
save-sccache-cache:
22+
steps:
23+
- save_cache:
24+
name: Save sccache cache
25+
# We use {{ epoch }} to always upload a fresh cache:
26+
# Of course, restore_cache will not find this exact key,
27+
# but it will fall back to the closest key (aka the most recent).
28+
# See https://discuss.circleci.com/t/add-mechanism-to-update-existing-cache-key/9014/13
29+
key: sccache-cache-stable-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ epoch }}
30+
paths:
31+
- "~/.cache/sccache"
32+
install-depends:
33+
steps:
34+
- run:
35+
name: Prepare for apt upgrades
36+
command: sudo apt update
37+
- run:
38+
name: Install libssl-dev for openssl-sys
39+
command: sudo apt install -y libssl-dev
40+
- run:
41+
name: Install libclang for rocksdb
42+
command: sudo apt install clang
243
orbs:
344
rust: circleci/[email protected]
445
executors:
@@ -73,9 +114,9 @@ jobs:
73114
command: |
74115
echo "$DOCKERHUB_PASS" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin
75116
docker push $IMAGE_NAME:latest-bridge
76-
lint-build-test:
117+
lint:
77118
description: |
78-
Check linting with Clippy and rustfmt, build the crate, and run tests.
119+
Check linting with Clippy and rustfmt.
79120
resource_class: xlarge
80121
executor:
81122
name: rust/default
@@ -85,18 +126,7 @@ jobs:
85126
RUST_LOG: 'debug'
86127
steps:
87128
- checkout
88-
- run:
89-
name: Prepare for apt upgrades
90-
command: sudo apt update
91-
- run:
92-
name: Install libssl-dev for openssl-sys
93-
command: sudo apt install -y libssl-dev
94-
- run:
95-
name: Install libclang for rocksdb
96-
command: sudo apt install clang
97-
- run:
98-
name: Install rustfmt
99-
command: rustup component add rustfmt
129+
- install-depends
100130
- run:
101131
name: Validate release notes entry
102132
command: ./newsfragments/validate_files.py
@@ -106,15 +136,47 @@ jobs:
106136
- run:
107137
name: Install Clippy
108138
command: rustup component add clippy
139+
- setup-and-restore-sccache-cache
109140
- run:
110141
name: Run Clippy
111142
command: cargo clippy --all --all-targets --all-features --no-deps -- --deny warnings
112-
- run:
113-
name: Build Trin workspace
114-
command: cargo build --workspace
115-
- run:
116-
name: Test Trin workspace
117-
command: cargo test --workspace -- --nocapture
143+
- save-sccache-cache
144+
build:
145+
description: |
146+
Build the crate.
147+
resource_class: xlarge
148+
executor:
149+
name: rust/default
150+
tag: 1.66.1
151+
environment:
152+
RUSTFLAGS: '-D warnings'
153+
RUST_LOG: 'debug'
154+
steps:
155+
- checkout
156+
- install-depends
157+
- setup-and-restore-sccache-cache
158+
- run:
159+
name: Build Trin workspace
160+
command: cargo build --workspace
161+
- save-sccache-cache
162+
test:
163+
description: |
164+
Run tests.
165+
resource_class: xlarge
166+
executor:
167+
name: rust/default
168+
tag: 1.66.1
169+
environment:
170+
RUSTFLAGS: '-D warnings'
171+
RUST_LOG: 'debug'
172+
steps:
173+
- checkout
174+
- install-depends
175+
- setup-and-restore-sccache-cache
176+
- run:
177+
name: Test Trin workspace
178+
command: cargo test --workspace -- --nocapture
179+
- save-sccache-cache
118180
utp-test:
119181
description: |
120182
Run uTP network simulator
@@ -144,9 +206,11 @@ jobs:
144206
- run:
145207
name: Install Rust
146208
command: curl https://sh.rustup.rs -sSf | sh -s -- -y
209+
- setup-and-restore-sccache-cache
147210
- run:
148211
name: Build utp-testing package
149212
command: cargo build --workspace --release
213+
- save-sccache-cache
150214
- run:
151215
name: Move docker artifacts
152216
command: mv -t utp-testing/docker/circleci/ target/release/utp-test-app utp-testing/docker/run_endpoint.sh utp-testing/docker/setup.sh
@@ -192,5 +256,7 @@ workflows:
192256
filters:
193257
branches:
194258
only: master
195-
- lint-build-test
259+
- lint
260+
- build
261+
- test
196262
- utp-test

0 commit comments

Comments
 (0)