Skip to content

Commit e43a696

Browse files
authored
Merge pull request #1 from knqiufan/feat/rust-build-test-optimization
build: Rust 构建与测试效率优化(P0/P2)
2 parents 9a4af9c + 363e81b commit e43a696

16 files changed

Lines changed: 701 additions & 53 deletions

File tree

.github/workflows/ci.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ jobs:
6565
with:
6666
workspaces: src-tauri
6767

68+
- uses: taiki-e/install-action@nextest
69+
6870
- name: Check formatting
6971
working-directory: src-tauri
7072
run: cargo fmt --check
@@ -75,7 +77,13 @@ jobs:
7577

7678
- name: Run tests
7779
working-directory: src-tauri
78-
run: cargo test --all-features
80+
env:
81+
# GitHub Linux runners can crash GNU ld when linking many large Tauri
82+
# integration test binaries concurrently. Keep test compilation serial
83+
# and omit debug info to reduce linker pressure.
84+
CARGO_BUILD_JOBS: 1
85+
CARGO_PROFILE_TEST_DEBUG: 0
86+
run: cargo nextest run --all-features --profile ci
7987

8088
- name: Build check
8189
working-directory: src-tauri

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ===== Rust =====
22
src-tauri/target/
3-
.cargo/
3+
/.cargo/
44

55
# ===== Node / Frontend =====
66
node_modules/

AGENTS.md

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -95,40 +95,35 @@ If dependency APIs change across minors, prefer checking the manifest first, the
9595
# Frontend only
9696
npm run dev # Vite dev server on :1420
9797

98-
# Full app (frontend + Rust backend): clean Rust artifacts first, then dev
99-
cd src-tauri
100-
cargo clean
101-
cd ..
98+
# Full app (frontend + Rust backend)
10299
npm run tauri dev # Tauri dev mode
103100

104101
# Build
105102
npm run build # Frontend production build
106-
107-
# Full app build: clean Rust artifacts first
108-
cd src-tauri
109-
cargo clean
110-
cd ..
111103
npm run tauri build # Full app build
112104

113105
# Python sidecar
114106
cd agent
115107
python -m uvicorn app.main:app --port 9527
116108

117-
# Rust checks (always from src-tauri/): clean before any cargo workflow
109+
# Rust checks (from src-tauri/; use incremental compile — do not cargo clean routinely)
118110
cd src-tauri
119-
cargo clean
120111
cargo check # Fast compile check
121-
122-
cd src-tauri
123-
cargo clean
124-
cargo test # Run tests
125-
126-
cd src-tauri
127-
cargo clean
112+
cargo test --test crypto_tests # Targeted test during daily work (see mapping in docs/guides/rust-build-test-optimization.md §4.2)
113+
cargo nextest run --test crypto_tests # Same, faster parallel runner (requires: cargo install cargo-nextest)
114+
cargo test --features test-private --test chat_commands_tests # Commands tests that need test-private
115+
cargo nextest run --all-features --profile ci # Full suite (preferred before commit)
116+
cargo test # Full suite fallback if nextest not installed
128117
cargo build # Standalone Rust build when not using npm wrapper
129118
```
130119

131-
**Cargo hygiene:** Before `cargo check`, `cargo test`, `cargo build`, or npm scripts that invoke the Tauri/Rust build (`tauri dev`, `tauri build`), run `cargo clean` inside `src-tauri/` so stale `target/` artifacts do not accumulate across iterations.
120+
**Optional P2 tooling** (see [`docs/guides/rust-build-test-optimization.md`](docs/guides/rust-build-test-optimization.md) §5):
121+
122+
- `cargo install cargo-nextest --locked` — parallel test runner; config in `src-tauri/.config/nextest.toml`
123+
- `cargo install sccache` — compile cache; then uncomment `rustc-wrapper = "sccache"` in `src-tauri/.cargo/config.toml`
124+
- Build tuning defaults live in `src-tauri/.cargo/config.toml` (`dev` dependency `opt-level`, optional `sccache` / linker)
125+
126+
**Cargo hygiene:** Do **not** run `cargo clean` before routine `cargo check`, `cargo test`, `cargo build`, `tauri dev`, or `tauri build` — incremental compile is intentional and much faster. Run `cargo clean` in `src-tauri/` only when troubleshooting: link errors, metadata mismatch, unexplained failures after a branch switch, or Rust toolchain / major dependency upgrades. See [`docs/guides/rust-build-test-optimization.md`](docs/guides/rust-build-test-optimization.md).
132127

133128
## Environment Setup
134129

CLAUDE.md

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -95,40 +95,35 @@ If dependency APIs change across minors, prefer checking the manifest first, the
9595
# Frontend only
9696
npm run dev # Vite dev server on :1420
9797

98-
# Full app (frontend + Rust backend): clean Rust artifacts first, then dev
99-
cd src-tauri
100-
cargo clean
101-
cd ..
98+
# Full app (frontend + Rust backend)
10299
npm run tauri dev # Tauri dev mode
103100

104101
# Build
105102
npm run build # Frontend production build
106-
107-
# Full app build: clean Rust artifacts first
108-
cd src-tauri
109-
cargo clean
110-
cd ..
111103
npm run tauri build # Full app build
112104

113105
# Python sidecar
114106
cd agent
115107
python -m uvicorn app.main:app --port 9527
116108

117-
# Rust checks (always from src-tauri/): clean before any cargo workflow
109+
# Rust checks (from src-tauri/; use incremental compile — do not cargo clean routinely)
118110
cd src-tauri
119-
cargo clean
120111
cargo check # Fast compile check
121-
122-
cd src-tauri
123-
cargo clean
124-
cargo test # Run tests
125-
126-
cd src-tauri
127-
cargo clean
112+
cargo test --test crypto_tests # Targeted test during daily work (see mapping in docs/guides/rust-build-test-optimization.md §4.2)
113+
cargo nextest run --test crypto_tests # Same, faster parallel runner (requires: cargo install cargo-nextest)
114+
cargo test --features test-private --test chat_commands_tests # Commands tests that need test-private
115+
cargo nextest run --all-features --profile ci # Full suite (preferred before commit)
116+
cargo test # Full suite fallback if nextest not installed
128117
cargo build # Standalone Rust build when not using npm wrapper
129118
```
130119

131-
**Cargo hygiene:** Before `cargo check`, `cargo test`, `cargo build`, or npm scripts that invoke the Tauri/Rust build (`tauri dev`, `tauri build`), run `cargo clean` inside `src-tauri/` so stale `target/` artifacts do not accumulate across iterations.
120+
**Optional P2 tooling** (see [`docs/guides/rust-build-test-optimization.md`](docs/guides/rust-build-test-optimization.md) §5):
121+
122+
- `cargo install cargo-nextest --locked` — parallel test runner; config in `src-tauri/.config/nextest.toml`
123+
- `cargo install sccache` — compile cache; then uncomment `rustc-wrapper = "sccache"` in `src-tauri/.cargo/config.toml`
124+
- Build tuning defaults live in `src-tauri/.cargo/config.toml` (`dev` dependency `opt-level`, optional `sccache` / linker)
125+
126+
**Cargo hygiene:** Do **not** run `cargo clean` before routine `cargo check`, `cargo test`, `cargo build`, `tauri dev`, or `tauri build` — incremental compile is intentional and much faster. Run `cargo clean` in `src-tauri/` only when troubleshooting: link errors, metadata mismatch, unexplained failures after a branch switch, or Rust toolchain / major dependency upgrades. See [`docs/guides/rust-build-test-optimization.md`](docs/guides/rust-build-test-optimization.md).
132127

133128
## Environment Setup
134129

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,6 @@ pip install -r requirements.txt
116116

117117
```bash
118118
# 完整桌面应用(推荐)
119-
cd src-tauri
120-
cargo clean
121-
cd ..
122119
npm run tauri dev
123120

124121
# 仅前端(浏览器调试,无 Tauri IPC)
@@ -138,11 +135,14 @@ npm run build # 前端生产构建
138135
npm test # 前端 Vitest
139136

140137
cd src-tauri
141-
cargo clean
142-
cargo check # Rust 编译检查
143-
cargo test # Rust 集成测试
138+
cargo check # Rust 编译检查(日常依赖增量编译,勿先 cargo clean)
139+
cargo test --test crypto_tests # 日常:按改动模块跑精准测试(映射表见优化指南 §4.2)
140+
cargo nextest run --all-features --profile ci # 提交前:全量测试(推荐,需 cargo install cargo-nextest)
141+
cargo test # 提交前:全量测试(未装 nextest 时的后备)
144142
```
145143

144+
若 Rust 编译出现链接错误、metadata 异常或切分支后无法解释的失败,再在 `src-tauri/` 下按需执行 `cargo clean` 后重试。详见 [`docs/guides/rust-build-test-optimization.md`](docs/guides/rust-build-test-optimization.md)
145+
146146
## 目录结构
147147

148148
```

0 commit comments

Comments
 (0)