Files
anki/tools/coverage/coverage-rust.bat
Fernando Lins f76fcec48f feat: add Rust test coverage (#4842)
## Linked issue

Closes #4839

## Summary / motivation

Adds `cargo-llvm-cov`-based test coverage for the full Rust workspace.
Introduces `just test-rust --coverage` and `just test-rust --coverage
--html`, and wires Rust into the `just test --coverage` umbrella.

`cargo-llvm-cov` is installed on demand into `out/bin/` to avoid
polluting the global cargo install. The `llvm-tools-preview` rustup
component is now installed in CI so the tool can instrument binaries.

## How to test (required)

```sh
# Existing behavior unchanged
just test-rust

# Terminal summary
just test-rust --coverage

# Terminal summary + HTML report under out/coverage/rust/html/
just test-rust --coverage --html

# Umbrella (Rust + Python)
just test --coverage
just test --coverage --html
```

Note: first run of `--coverage` will install `cargo-llvm-cov` into
`out/bin/` (~30s). Subsequent runs skip the install step.

### Checklist

- [x] I ran `./ninja check` or an equivalent relevant check locally.

### Details

- `cargo-llvm-cov` pinned at `0.8.4`, installed into `out/bin/` via
`cargo install --root out`.
- `--workspace --locked` measures all crates and respects the lockfile.
- `llvm-tools-preview` added to `setup-anki` action so CI can instrument
Rust binaries.
- Coverage runs are slower than plain `just test-rust` because
`cargo-llvm-cov` rebuilds with instrumentation — this is expected.

## Before / after behavior

Before: no `just test-rust`, no Rust coverage support.

After: `just test-rust` runs Rust tests via ninja; `just test-rust
--coverage` runs them with `cargo-llvm-cov`

---------

Co-authored-by: Abdo <abdo@abdnh.net>
2026-05-18 11:38:37 -03:00

29 lines
1009 B
Batchfile

@echo off
setlocal
rem cargo-llvm-cov's llvm-profdata uses the host toolchain, which is incompatible
rem with the profraw files produced when running on Windows ARM64.
if "%PROCESSOR_ARCHITECTURE%"=="ARM64" (
echo Rust coverage is not supported on Windows ARM64 ^(llvm-profdata format mismatch^).
echo Run on Linux or let CI enforce coverage.
exit /b 0
)
set "outdir=out\coverage\rust"
set "LLVMCOVPATH=out\bin"
if not exist %outdir% mkdir %outdir%
if not exist %LLVMCOVPATH% mkdir %LLVMCOVPATH%
if not exist %LLVMCOVPATH%\cargo-llvm-cov.exe (
cargo install cargo-llvm-cov --version 0.8.4 --locked --root out || exit /b 1
)
set "ANKI_TEST_MODE=1"
%LLVMCOVPATH%\cargo-llvm-cov llvm-cov --workspace --locked --json --summary-only ^
--output-path %outdir%\coverage-summary.json --fail-under-lines 60 || exit /b 1
if "%1"=="--html" (
%LLVMCOVPATH%\cargo-llvm-cov llvm-cov report --html --output-dir %outdir%\html || exit /b 1
echo Rust coverage report: %outdir%\html\index.html
)