Skip to content

Commit e8eba5f

Browse files
committed
chore(ci):为 Rust 工作流添加 cargo 缓存支持
- 在所有 Rust 相关作业中添加缓存步骤 - 缓存 cargo registry 和 git依赖 - 缓存编译目标目录以加速构建 - 使用 Cargo.lock 文件哈希作为缓存键 - 支持 Linux、macOS 和 Android 目标平台- 减少重复依赖下载和编译时间
1 parent 11ff6a8 commit e8eba5f

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

.github/workflows/rust.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ jobs:
1919
- uses: actions/checkout@v4
2020
- name: Install Rust
2121
uses: dtolnay/rust-toolchain@stable
22+
- name: Cache cargo registry
23+
uses: actions/cache@v4
24+
with:
25+
path: |
26+
~/.cargo/registry
27+
~/.cargo/git
28+
target
29+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
2230
- name: Install dependencies (Linux)
2331
run: |
2432
sudo apt-get update
@@ -33,6 +41,14 @@ jobs:
3341
- uses: actions/checkout@v4
3442
- name: Install Rust
3543
uses: dtolnay/rust-toolchain@stable
44+
- name: Cache cargo registry
45+
uses: actions/cache@v4
46+
with:
47+
path: |
48+
~/.cargo/registry
49+
~/.cargo/git
50+
target
51+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
3652
- name: Install vcpkg
3753
run: |
3854
git clone https://github.com/Microsoft/vcpkg.git
@@ -57,6 +73,14 @@ jobs:
5773
- uses: actions/checkout@v4
5874
- name: Install Rust
5975
uses: dtolnay/rust-toolchain@stable
76+
- name: Cache cargo registry
77+
uses: actions/cache@v4
78+
with:
79+
path: |
80+
~/.cargo/registry
81+
~/.cargo/git
82+
target
83+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
6084
- name: Install dependencies (macOS)
6185
run: |
6286
brew install sqlite3
@@ -75,6 +99,14 @@ jobs:
7599
- uses: actions/checkout@v4
76100
- name: Install Rust
77101
uses: dtolnay/rust-toolchain@stable
102+
- name: Cache cargo registry
103+
uses: actions/cache@v4
104+
with:
105+
path: |
106+
~/.cargo/registry
107+
~/.cargo/git
108+
target
109+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
78110
- name: Install Android targets
79111
run: |
80112
rustup target add aarch64-linux-android armv7-linux-androideabi x86_64-linux-android i686-linux-android
@@ -130,6 +162,14 @@ jobs:
130162
uses: dtolnay/rust-toolchain@stable
131163
with:
132164
targets: ${{ matrix.target }}
165+
- name: Cache cargo registry
166+
uses: actions/cache@v4
167+
with:
168+
path: |
169+
~/.cargo/registry
170+
~/.cargo/git
171+
target
172+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
133173
- name: Install dependencies (Linux)
134174
run: |
135175
sudo apt-get update
@@ -189,6 +229,14 @@ jobs:
189229
uses: dtolnay/rust-toolchain@stable
190230
with:
191231
targets: ${{ matrix.target }}
232+
- name: Cache cargo registry
233+
uses: actions/cache@v4
234+
with:
235+
path: |
236+
~/.cargo/registry
237+
~/.cargo/git
238+
target
239+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
192240
- name: Install vcpkg
193241
run: |
194242
git clone https://github.com/Microsoft/vcpkg.git
@@ -239,6 +287,14 @@ jobs:
239287
uses: dtolnay/rust-toolchain@stable
240288
with:
241289
targets: ${{ matrix.target }}
290+
- name: Cache cargo registry
291+
uses: actions/cache@v4
292+
with:
293+
path: |
294+
~/.cargo/registry
295+
~/.cargo/git
296+
target
297+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
242298
- name: Install dependencies (macOS)
243299
run: |
244300
brew install sqlite3

0 commit comments

Comments
 (0)