Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ jobs:
linux-build:
runs-on: "warp-ubuntu-latest-x64-4x"
timeout-minutes: 60
strategy:
matrix:
toolchain:
- stable
env:
# Need up-to-date compilers for kernels
CC: clang
Expand All @@ -81,8 +77,8 @@ jobs:
# pin the toolchain version to avoid surprises
- name: Setup rust toolchain
run: |
rustup toolchain install ${{ matrix.toolchain }}
rustup default ${{ matrix.toolchain }}
rustup toolchain install nightly
rustup default nightly
- uses: rui314/setup-mold@v1
- uses: Swatinem/rust-cache@v2
- name: Install dependencies
Expand All @@ -94,12 +90,10 @@ jobs:
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: Run tests
if: ${{ matrix.toolchain == 'stable' }}
run: |
ALL_FEATURES=`cargo metadata --format-version=1 --no-deps | jq -r '.packages[] | .features | keys | .[]' | grep -v protoc | sort | uniq | paste -s -d "," -`
cargo llvm-cov --profile ci --locked --workspace --codecov --output-path coverage.codecov --features ${ALL_FEATURES}
cargo +nightly llvm-cov --profile ci --locked --workspace --codecov --output-path coverage.codecov --features ${ALL_FEATURES}
- name: Upload coverage to Codecov
if: ${{ matrix.toolchain == 'stable' }}
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
6 changes: 6 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ The project is organized as a Rust workspace with Python and Java bindings. Rust
* Run specific test: `cargo test -p <package> <test_name>`
* Lint: `cargo clippy --all --tests --benches -- -D warnings`
* Format: `cargo fmt --all`
* Output code coverage report for a crate: `cargo +nightly llvm-cov -q -p lance-core --branch`
* Create HTML coverage report for a crate: `cargo +nightly llvm-cov -q -p lance-core --branch --html`
* Print lines in file missing coverage: `cargo +nightly llvm-cov -q -p lance-core --show-missing-lines | grep rust/lance-core/src/datatypes/schema.rs`
* Show detailed coverage for a file: `python ci/coverage.py -p lance-core -f rust/lance-core/src/datatypes/schema.rs`

### Python Development

Expand Down Expand Up @@ -135,6 +139,8 @@ Tests:
/// # }
/// ```
```
* Code coverage can be skipped for test utilities and non-critical paths using
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way to just skip code coverage for anything in the test cfg? Or is that already done and this is for test utilities that are in main scope for some reason?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't seem like there's a particularly easy way. taiki-e/cargo-llvm-cov#123

But most of the time tests have their lines covered. It's just some edge cases like branches that only happen on test failures that get missed. I think that's okay.

`#[cfg_attr(coverage, coverage(off))]`.

## Review Guidelines

Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ debug-assertions = false
strip = "debuginfo"
incremental = false

[workspace.lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(coverage,coverage_nightly)'] }

[workspace.lints.clippy]
all = { level = "deny", priority = -1 }
style = { level = "deny", priority = -1 }
Expand Down
38 changes: 38 additions & 0 deletions ci/coverage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import argparse
import subprocess

parser = argparse.ArgumentParser(description="Run code coverage analysis.")
parser.add_argument("-p", "--package", type=str, help="The Rust crate to analyze.")
parser.add_argument(
"-f", "--file", type=str, help="The specific file to show coverage for."
)
args = parser.parse_args()

cmd = ["cargo", "+nightly", "llvm-cov", "-q", "--branch", "--text", "--color", "always"]
if args.package:
cmd += ["-p", args.package]

result = subprocess.run(cmd, capture_output=True)
if result.returncode != 0:
print("Error running coverage analysis:")
print(result.stderr.decode())
elif args.file:
# Look for the specific file's coverage details
# Section headers look like: /path/to/file.rs:
lines = result.stdout.splitlines()
in_file_section = False
file_bytes = args.file.encode()
for line in lines:
# Check if this is a section header (path ending with colon)
stripped = line.rstrip()
is_section_header = stripped.endswith(b":") and b"|" not in line
if is_section_header:
if file_bytes in line:
in_file_section = True
elif in_file_section:
# Hit a new section, stop
break
if in_file_section:
print(line.decode())
else:
print(result.stdout.decode())
1 change: 1 addition & 0 deletions rust/lance-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright The Lance Authors
#![cfg_attr(coverage, feature(coverage_attribute))]

use arrow_schema::{DataType, Field as ArrowField};
use std::sync::LazyLock;
Expand Down
1 change: 1 addition & 0 deletions rust/lance-core/src/utils/backoff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ mod tests {

#[test]
fn test_slot_backoff() {
#[cfg_attr(coverage, coverage(off))]
fn assert_in(value: u128, expected: &[u128]) {
assert!(
expected.contains(&value),
Expand Down