Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

readme: example uses -Zprofile which has been removed from Rust nightly #1240

Open
cakebaker opened this issue Nov 3, 2024 · 4 comments
Open

Comments

@cakebaker
Copy link
Contributor

Example: How to generate .gcda files for a Rust project in the readme uses -Zprofile which has been removed recently from Rust nightly (see rust-lang/rust#131829).

@marco-c
Copy link
Collaborator

marco-c commented Nov 5, 2024

Thanks, we should update the README to remove the mention to "-Zprofile".

@josecelano
Copy link

josecelano commented Nov 5, 2024

Could anyone tell me what the solution is?

It seems it does not work if I remove the -Z profile flag:

Original:

CARGO_INCREMENTAL: "0"
RUSTFLAGS: "-Z profile -C codegen-units=1 -C opt-level=0 -C link-dead-code -C overflow-checks=off -Z panic_abort_tests -C panic=abort"
RUSTDOCFLAGS: "-Z profile -C codegen-units=1 -C opt-level=0 -C link-dead-code -C overflow-checks=off -Z panic_abort_tests -C panic=abort"

I've tried without the -Z profile flag:

CARGO_INCREMENTAL: "0"
RUSTFLAGS: "-C codegen-units=1 -C opt-level=0 -C link-dead-code -C overflow-checks=off -Z panic_abort_tests -C panic=abort"
RUSTDOCFLAGS: "-C codegen-units=1 -C opt-level=0 -C link-dead-code -C overflow-checks=off -Z panic_abort_tests -C panic=abort"

@marco-c
Copy link
Collaborator

marco-c commented Nov 5, 2024

@josecelano
Copy link

@josecelano the solution is using source-based coverage, as described at https://github.com/mozilla/grcov?tab=readme-ov-file#example-how-to-generate-source-based-coverage-for-a-rust-project.

Thank you @marco-c; I'm trying to upload the generated report to codecov.io. I'm trying to figure out how to update my GitHub workflows. I'm just posting this here in case other people have the same problem. I haven't found the solution yet.

I was using the https://github.com/marketplace/actions/grcov-for-rust action to generate the coverage report and upload it to codecov with a workflow similar to this:

name: Coverage

on:
  push:
    branches:
      - develop

env:
  CARGO_TERM_COLOR: always

jobs:
  report:
    name: Report
    environment: coverage
    runs-on: ubuntu-latest
    env:
      CARGO_INCREMENTAL: "0"
      RUSTFLAGS: "-Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort"
      RUSTDOCFLAGS: "-Cpanic=abort"

    steps:
      - id: setup
        name: Setup Toolchain
        uses: dtolnay/rust-toolchain@nightly
        with:
          toolchain: nightly
          components: llvm-tools-preview

      - id: tools
        name: Install Tools
        uses: taiki-e/install-action@v2
        with:
          tool: grcov

      - id: coverage
        name: Generate Coverage Report
        uses: alekitto/[email protected]

      - id: upload
        name: Upload Coverage Report
        uses: codecov/codecov-action@v3
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          files: ${{ steps.coverage.outputs.report }}
          verbose: true
          fail_ci_if_error: true

The "alekitto/grcov" hasn't been updated for a while and I don't know what type of artefacts generating. Snice the action seems to be unmantained I'm trying to generate the report info manually with a workflow like this:

name: Coverage V2

on:
  push:
    branches:
      - develop

env:
  CARGO_TERM_COLOR: always

jobs:
  report:
    name: Report
    environment: coverage
    runs-on: ubuntu-latest
    env:
      CARGO_INCREMENTAL: "0"
      RUSTFLAGS: "-Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort"
      RUSTDOCFLAGS: "-Cpanic=abort"

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - id: setup
        name: Setup Toolchain
        uses: dtolnay/rust-toolchain@nightly
        with:
          toolchain: nightly
          components: llvm-tools-preview

      - id: cache
        name: Enable Workflow Cache
        uses: Swatinem/rust-cache@v2

      - id: tools
        name: Install Tools
        uses: taiki-e/install-action@v2
        with:
          tool: cargo-llvm-cov

      - id: coverage
        name: Generate Coverage Report
        run: |
          mkdir .coverage
          cargo llvm-cov --lcov --output-path=./.coverage/lcov.info

      - id: upload
        name: Upload Coverage Report
        uses: codecov/codecov-action@v4
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          file: ./.coverage/lcov.info
          verbose: true
          fail_ci_if_error: true

But I don't know why I needed grcov in the first version. lcov format seems to be supported by codecov.

Minoru added a commit to newsboat/newsboat that referenced this issue Nov 17, 2024
We used to rely on `-Zprofile`, but it was recently removed from Rust
Nightly: rust-lang/rust#131829 This commit
switches to a stable alternative; cf.
mozilla/grcov#1240

This change is accompanied by a change in the build environment: instead
of using Clang 18 with Rust Nightly, we now use Clang 18 with Rust 1.81.
That's the last Rust version based on LLVM 18. Previously we tried to
match LLVM versions between C++ and Rust to avoid weird coverage
results. Now, it's *required* to match them, otherwise no coverage is
gathered at all.

Fixes #2912.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants