Skip to content

Commit

Permalink
coverage: apply -Cinstrument-coverage to workspace crates only (#10239
Browse files Browse the repository at this point in the history
)

When collecting coverage we want to instrument only the crates in our
workspace, and not the external dependencies. There is no value in doing
otherwise – we don’t run tests for our dependencies anyway. Furthermore,
instrumenting the external dependencies runs a risk of significant
performance regressions, such as seen in #10201.
  • Loading branch information
nagisa authored Nov 23, 2023
1 parent 431ae41 commit 91a223d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
19 changes: 12 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ jobs:
with:
prefix-key: "0" # change this to invalidate CI cache
shared-key: "cargo_nextest-${{ matrix.cache_id }}"
- run: cargo llvm-cov show-env | tr -d "'" >> "$GITHUB_ENV"

- run: cargo llvm-cov show-env | grep -v RUSTFLAGS | tr -d "'" >> "$GITHUB_ENV"
- run: echo "RUSTC_WORKSPACE_WRAPPER=$PWD/scripts/rustc-coverage-wrapper.sh" >> "$GITHUB_ENV"
# Run unit tests
- run: cargo nextest run --locked --workspace --exclude integration-tests --cargo-profile dev-release --profile ci ${{ matrix.flags }}
env:
Expand Down Expand Up @@ -115,7 +115,8 @@ jobs:
shared-key: "cargo_nextest-linux"
save-if: "false" # use the cache from nextest, but don’t double-save
- run: pip3 install --user -r pytest/requirements.txt
- run: cargo llvm-cov show-env | tr -d "'" >> "$GITHUB_ENV"
- run: cargo llvm-cov show-env | grep -v RUSTFLAGS | tr -d "'" >> "$GITHUB_ENV"
- run: echo "RUSTC_WORKSPACE_WRAPPER=$PWD/scripts/rustc-coverage-wrapper.sh" >> "$GITHUB_ENV"
- run: cargo build --locked --profile dev-release -p neard --bin neard
- run: echo "CURRENT_NEARD=$PWD/target/dev-release/neard" >> "$GITHUB_ENV"
- run: cd pytest && python3 tests/sanity/backward_compatible.py
Expand Down Expand Up @@ -145,7 +146,8 @@ jobs:
shared-key: "cargo_nextest-linux"
save-if: "false" # use the cache from nextest, but don’t double-save
- run: pip3 install --user -r pytest/requirements.txt
- run: cargo llvm-cov show-env | tr -d "'" >> "$GITHUB_ENV"
- run: cargo llvm-cov show-env | grep -v RUSTFLAGS | tr -d "'" >> "$GITHUB_ENV"
- run: echo "RUSTC_WORKSPACE_WRAPPER=$PWD/scripts/rustc-coverage-wrapper.sh" >> "$GITHUB_ENV"
- run: cargo build --locked --profile dev-release -p neard --bin neard
- run: echo "CURRENT_NEARD=$PWD/target/dev-release/neard" >> "$GITHUB_ENV"
- run: echo "NEAR_ROOT=$PWD" >> "$GITHUB_ENV"
Expand Down Expand Up @@ -181,7 +183,8 @@ jobs:
- run: pip3 install --user -r pytest/requirements.txt
# This is the only job that uses `--features nightly` so we build this in-line instead of a
# separate job like done with the regular neard.
- run: cargo llvm-cov show-env | tr -d "'" >> "$GITHUB_ENV"
- run: cargo llvm-cov show-env | grep -v RUSTFLAGS | tr -d "'" >> "$GITHUB_ENV"
- run: echo "RUSTC_WORKSPACE_WRAPPER=$PWD/scripts/rustc-coverage-wrapper.sh" >> "$GITHUB_ENV"
- run: cargo build --profile dev-release -p neard --bin neard --features nightly
# Note: We're not running spin_up_cluster.py for non-nightly
# because spinning up non-nightly clusters is already covered
Expand Down Expand Up @@ -215,7 +218,8 @@ jobs:
shared-key: "cargo_nextest-linux"
save-if: "false" # use the cache from nextest, but don’t double-save
- run: pip3 install --user -r pytest/requirements.txt
- run: cargo llvm-cov show-env | tr -d "'" >> "$GITHUB_ENV"
- run: cargo llvm-cov show-env | grep -v RUSTFLAGS | tr -d "'" >> "$GITHUB_ENV"
- run: echo "RUSTC_WORKSPACE_WRAPPER=$PWD/scripts/rustc-coverage-wrapper.sh" >> "$GITHUB_ENV"
- run: cargo build --locked --profile dev-release -p neard --bin neard
- run: echo "CURRENT_NEARD=$PWD/target/dev-release/neard" >> "$GITHUB_ENV"
- run: python3 scripts/state/update_res.py check
Expand Down Expand Up @@ -260,7 +264,8 @@ jobs:
shared-key: "cargo_nextest-linux"
save-if: "false" # use the cache from nextest, but don’t double-save
- run: pip3 install --user -r pytest/requirements.txt
- run: cargo llvm-cov show-env | tr -d "'" >> "$GITHUB_ENV"
- run: cargo llvm-cov show-env | grep -v RUSTFLAGS | tr -d "'" >> "$GITHUB_ENV"
- run: echo "RUSTC_WORKSPACE_WRAPPER=$PWD/scripts/rustc-coverage-wrapper.sh" >> "$GITHUB_ENV"
- run: cargo build --locked --profile dev-release -p neard --bin neard
- run: echo "CURRENT_NEARD=$PWD/target/dev-release/neard" >> "$GITHUB_ENV"
- run: cd pytest && python3 tests/sanity/upgradable.py
Expand Down
1 change: 1 addition & 0 deletions runtime/near-test-contracts/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ fn cargo_build_cmd(target_dir: &std::path::Path) -> Command {

res.env_remove("CARGO_BUILD_RUSTFLAGS");
res.env_remove("CARGO_ENCODED_RUSTFLAGS");
res.env_remove("RUSTC_WORKSPACE_WRAPPER");

res.env("RUSTFLAGS", "-Dwarnings");
res.env("CARGO_TARGET_DIR", target_dir);
Expand Down
9 changes: 9 additions & 0 deletions scripts/rustc-coverage-wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

## When collecting coverage we want to instrument only the crates in our workspace, and not the
## external dependencies (there is no value in doing so – we don’t run tests for our dependencies
## anyway.) Furthermore, instrumenting the crates like these run a risk of significant performance
## regressions, such as seen in #10201

RUSTC="$1"; shift
exec "$RUSTC" -Cinstrument-coverage --cfg=coverage "$@"

0 comments on commit 91a223d

Please sign in to comment.