Skip to content

Commit 9f02966

Browse files
committed
Merge branch 'feature/ci_with_cargo_vendor' into develop
Instead of downloading sources once per job, or trying to keep cargo caches for them separately, use *one* dependency cache that is generated with `cargo vendor`. The vendored sources are platform-independent and support all targets and all features. This is a substantial speed boost for our Docker Actions on non-x86_64 platforms, and it is also a workaround for docker/build-push-action#621. See Also 1. <docker/build-push-action#621>
2 parents 8602c0d + f736ab5 commit 9f02966

7 files changed

Lines changed: 174 additions & 57 deletions

File tree

.cargo/.directory_intentionally_empty

Whitespace-only changes.

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Opinionated default for line endings
2+
* text=auto eol=lf

.github/workflows/rust_release.yml

Lines changed: 76 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,53 @@ env:
1313
RUST_BACKTRACE: 1
1414

1515
jobs:
16+
# run `cargo vendor` and cache it
17+
vendor_sources:
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- uses: actions/checkout@v3
22+
23+
- uses: actions/cache@v3
24+
name: Update crate cargo-vendor cache
25+
id: vendor_cache
26+
with:
27+
path: |
28+
.cargo
29+
vendor
30+
key: cargo-vendor-release-${{ hashFiles('**/Cargo.lock') }}
31+
restore-keys: |
32+
cargo-vendor-release
33+
cargo-vendor
34+
enableCrossOsArchive: true
35+
36+
- uses: actions/cache@v3
37+
name: Update cargo registry cache
38+
if: steps.vendor_cache.outputs.cache-hit != 'true'
39+
with:
40+
path: |
41+
~/.cargo/bin/
42+
~/.cargo/registry/index/
43+
~/.cargo/registry/cache/
44+
~/.cargo/git/db/
45+
key: ${{ runner.os }}-cargo-cache-release-${{ hashFiles('**/Cargo.lock') }}
46+
restore-keys: |
47+
${{ runner.os }}-cargo-cache-release
48+
${{ runner.os }}-cargo-cache
49+
50+
- name: Vendor sources
51+
if: steps.vendor_cache.outputs.cache-hit != 'true'
52+
run: |
53+
mkdir -p .cargo
54+
mkdir -p vendor
55+
cargo vendor --versioned-dirs --locked >.cargo/config.toml
56+
1657
# Linux builds, with Docker and qemu as required
1758
release_linux:
1859
runs-on: ubuntu-latest
1960

61+
needs: vendor_sources
62+
2063
env:
2164
# See <https://hub.docker.com/_/rust> for list of tags
2265
BUILD_RUST_TAG: 1.67.0
@@ -49,6 +92,16 @@ jobs:
4992
steps:
5093
- uses: actions/checkout@v3
5194

95+
- uses: actions/cache/restore@v3
96+
name: Restore crate cargo-vendor cache
97+
with:
98+
path: |
99+
.cargo
100+
vendor
101+
key: cargo-vendor-release-${{ hashFiles('**/Cargo.lock') }}
102+
enableCrossOsArchive: true
103+
fail-on-cache-miss: true
104+
52105
- name: Workaround for https://github.com/rust-lang/cargo/issues/8719
53106
run: |
54107
sudo mkdir -p /var/lib/docker
@@ -84,6 +137,7 @@ jobs:
84137
target: localfile
85138
build-args: |
86139
CARGO_BUILD_TARGET=${{ matrix.rust }}
140+
CARGO_NET_OFFLINE=true
87141
BUILD_OS_TAG=${{ matrix.os }}
88142
BUILD_RUST_TAG=${{ env.BUILD_RUST_TAG }}
89143
platforms: ${{ matrix.docker }}
@@ -131,9 +185,12 @@ jobs:
131185
release_windows:
132186
runs-on: windows-latest
133187

188+
needs: vendor_sources
189+
134190
env:
135191
CARGO_BUILD_TARGET: x86_64-pc-windows-msvc
136-
CARGO_INSTALL_ROOT: 'install/'
192+
CARGO_NET_OFFLINE: "true"
193+
CARGO_INSTALL_ROOT: "install/"
137194
RUSTFLAGS: '-C strip=symbols -C target-feature=+crt-static'
138195
samedec_exe: 'install/bin/samedec.exe'
139196
samedec_target_exe: install/bin/samedec-x86_64-pc-windows-msvc.exe
@@ -145,22 +202,20 @@ jobs:
145202
shell: bash
146203
run: cargo version
147204

148-
- uses: actions/cache@v3
149-
name: Restore Rust cache
205+
- uses: actions/cache/restore@v3
206+
name: Restore crate cargo-vendor cache
150207
with:
151208
path: |
152-
~/.cargo/bin/
153-
~/.cargo/registry/index/
154-
~/.cargo/registry/cache/
155-
~/.cargo/git/db/
156-
target/
157-
key: ${{ runner.os }}-cargo-release-${{ hashFiles('**/Cargo.lock') }}
209+
.cargo
210+
vendor
211+
key: cargo-vendor-release-${{ hashFiles('**/Cargo.lock') }}
212+
enableCrossOsArchive: true
213+
fail-on-cache-miss: true
158214

159215
- name: Build
160216
shell: bash
161217
run: |
162218
mkdir -p 'install' &&
163-
cargo fetch --locked &&
164219
cargo build --offline --tests --frozen --release --workspace
165220
166221
- name: Test and install
@@ -218,9 +273,12 @@ jobs:
218273
release_macos:
219274
runs-on: macos-latest
220275

276+
needs: vendor_sources
277+
221278
env:
222279
CARGO_BUILD_TARGET: x86_64-apple-darwin
223-
CARGO_INSTALL_ROOT: 'install/'
280+
CARGO_NET_OFFLINE: "true"
281+
CARGO_INSTALL_ROOT: "install/"
224282
RUSTFLAGS: '-C strip=symbols'
225283
samedec_exe: 'install/bin/samedec'
226284
samedec_target_exe: install/bin/samedec-x86_64-apple-darwin
@@ -231,16 +289,15 @@ jobs:
231289
- name: Record environment
232290
run: cargo version
233291

234-
- uses: actions/cache@v3
235-
name: Restore Rust cache
292+
- uses: actions/cache/restore@v3
293+
name: Restore crate cargo-vendor cache
236294
with:
237295
path: |
238-
~/.cargo/bin/
239-
~/.cargo/registry/index/
240-
~/.cargo/registry/cache/
241-
~/.cargo/git/db/
242-
target/
243-
key: ${{ runner.os }}-cargo-release-${{ hashFiles('**/Cargo.lock') }}
296+
.cargo
297+
vendor
298+
key: cargo-vendor-release-${{ hashFiles('**/Cargo.lock') }}
299+
enableCrossOsArchive: true
300+
fail-on-cache-miss: true
244301

245302
- name: Build
246303
run: |

.github/workflows/rust_test.yml

Lines changed: 65 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,45 @@ env:
1111
RUST_BACKTRACE: 1
1212

1313
jobs:
14+
# run `cargo vendor` and cache it
15+
vendor_sources:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- uses: actions/checkout@v3
20+
21+
- uses: actions/cache@v3
22+
name: Update crate cargo-vendor cache
23+
id: vendor_cache
24+
with:
25+
path: |
26+
.cargo
27+
vendor
28+
key: cargo-vendor-${{ hashFiles('**/Cargo.lock') }}
29+
restore-keys: |
30+
cargo-vendor
31+
enableCrossOsArchive: true
32+
33+
- uses: actions/cache@v3
34+
name: Update cargo registry cache
35+
if: steps.vendor_cache.outputs.cache-hit != 'true'
36+
with:
37+
path: |
38+
~/.cargo/bin/
39+
~/.cargo/registry/index/
40+
~/.cargo/registry/cache/
41+
~/.cargo/git/db/
42+
key: ${{ runner.os }}-cargo-cache-${{ hashFiles('**/Cargo.lock') }}
43+
restore-keys: |
44+
${{ runner.os }}-cargo-cache
45+
46+
- name: Vendor sources
47+
if: steps.vendor_cache.outputs.cache-hit != 'true'
48+
run: |
49+
mkdir -p .cargo
50+
mkdir -p vendor
51+
cargo vendor --versioned-dirs --locked >.cargo/config.toml
52+
1453
test_sameold:
1554
strategy:
1655
matrix:
@@ -19,28 +58,32 @@ jobs:
1958

2059
runs-on: ${{ matrix.os }}
2160

61+
needs: vendor_sources
62+
63+
env:
64+
CARGO_NET_OFFLINE: "true"
65+
2266
steps:
2367
- uses: actions/checkout@v3
2468

2569
- name: Record environment
2670
shell: bash
2771
run: cargo version
2872

29-
- uses: actions/cache@v3
30-
name: Restore Rust cache
73+
- uses: actions/cache/restore@v3
74+
name: Restore crate cargo-vendor cache
3175
with:
3276
path: |
33-
~/.cargo/bin/
34-
~/.cargo/registry/index/
35-
~/.cargo/registry/cache/
36-
~/.cargo/git/db/
37-
target/
38-
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
77+
.cargo
78+
vendor
79+
key: cargo-vendor-${{ hashFiles('**/Cargo.lock') }}
80+
enableCrossOsArchive: true
81+
fail-on-cache-miss: true
3982

4083
- name: Build and test sameold
4184
shell: bash
4285
run: |
43-
cargo test -p sameold --verbose --no-default-features --features "${{ matrix.features }}"
86+
cargo test --frozen -p sameold --verbose --no-default-features --features "${{ matrix.features }}"
4487
4588
test_samedec:
4689
strategy:
@@ -49,28 +92,32 @@ jobs:
4992

5093
runs-on: ${{ matrix.os }}
5194

95+
needs: vendor_sources
96+
97+
env:
98+
CARGO_NET_OFFLINE: "true"
99+
52100
steps:
53101
- uses: actions/checkout@v3
54102

55103
- name: Record environment
56104
shell: bash
57105
run: cargo version
58106

59-
- uses: actions/cache@v3
60-
name: Restore Rust cache
107+
- uses: actions/cache/restore@v3
108+
name: Restore crate cargo-vendor cache
61109
with:
62110
path: |
63-
~/.cargo/bin/
64-
~/.cargo/registry/index/
65-
~/.cargo/registry/cache/
66-
~/.cargo/git/db/
67-
target/
68-
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
111+
.cargo
112+
vendor
113+
key: cargo-vendor-${{ hashFiles('**/Cargo.lock') }}
114+
enableCrossOsArchive: true
115+
fail-on-cache-miss: true
69116

70117
- name: Build and test samedec
71118
shell: bash
72119
run: |
73-
cargo test -p samedec --verbose
120+
cargo test --frozen -p samedec --verbose
74121
75122
- name: Run integration tests
76123
shell: bash

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@
22
**/*.rs.bk
33
*.iml
44
/.idea
5+
6+
# containerized build can use vendoring on the host side,
7+
# but we would prefer that this not be committed.
8+
.cargo
9+
/vendor

0 commit comments

Comments
 (0)