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 · 8 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/grcov@v0.2

      - 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.
henrybarreto added a commit to UpdateHub/updatehub that referenced this issue Nov 27, 2024
The profile option was removed from Rust nightly, so we need to remove
it from the CI. Unfortuanlly, currently `grcov`, tool used on the test
coverage, still doesn't support this change.

Refs: mozilla/grcov#1240
otavio pushed a commit to UpdateHub/updatehub that referenced this issue Nov 27, 2024
The profile option was removed from Rust nightly, so we need to remove
it from the CI. Unfortuanlly, currently `grcov`, tool used on the test
coverage, still doesn't support this change.

Refs: mozilla/grcov#1240
@leshow
Copy link

leshow commented Nov 30, 2024

did anyone figure this out? my action looks like this:

  coverage:
    name: Run coverage
    runs-on: ubuntu-latest
    strategy:
      matrix:
        rust:
          - nightly
    steps:
      - name: Checkout sources
        uses: actions/checkout@v2

      - name: Install toolchain
        uses: actions-rs/toolchain@v1
        with:
          toolchain: ${{ matrix.rust }}
          override: true
          components: llvm-tools-preview
      - name: Run coverage
        uses: actions-rs/cargo@v1
        with:
          command: test
          args: --all-features --exclude register_derive_impl --workspace --no-fail-fast
        env:
          CARGO_INCREMENTAL: "0"
          RUSTFLAGS: "-Zprofile -Ccodegen-units=1 -Cinstrument-coverage -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests"
          RUSTDOCFLAGS: "-Zprofile -Ccodegen-units=1 -Cinstrument-coverage -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests"
          SQLX_OFFLINE: true
      - name: rust-grcov
        id: coverage
        uses: actions-rs/grcov@v0.1.5
        env:
          SQLX_OFFLINE: true
          NODE_COVERALLS_DEBUG: true
      - name: Coveralls upload
        uses: coverallsapp/github-action@master
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          path-to-lcov: ${{ steps.coverage.outputs.report }}
          debug: true

blows up with this error:

   process didn't exit successfully: `/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc - --crate-name ___ --print=file-names -Zprofile -Ccodegen-units=1 -Cinstrument-coverage -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=split-debuginfo --print=crate-name --print=cfg` (exit status: 1)
  --- stderr
  warning: the `-Cinline-threshold` flag is deprecated and does nothing (consider using `-Cllvm-args=--inline-threshold=...`)

  error: unknown unstable option: `profile`

@josecelano
Copy link

Hi @leshow I'm doing this:

name: Coverage

on:
  push:
    branches:
      - develop

env:
  CARGO_TERM_COLOR: always

jobs:
  report:
    name: Generate Coverage Report
    environment: coverage
    runs-on: ubuntu-latest
    env:
      CARGO_INCREMENTAL: "0"
      RUSTFLAGS: "-Cinstrument-coverage"

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

      - name: Install LLVM tools
        run: sudo apt-get update && sudo apt-get install -y llvm

      - 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: grcov,cargo-llvm-cov

      - id: coverage
        name: Generate Coverage Report
        run: |
          cargo clean 
          cargo llvm-cov --all-features --workspace --codecov --output-path ./codecov.json

      - id: upload
        name: Upload Coverage Report
        uses: codecov/codecov-action@v5
        with:
          verbose: true
          token: ${{ secrets.CODECOV_TOKEN }}
          files: ${{ github.workspace }}/codecov.json
          fail_ci_if_error: true

I'm not using actions-rs/grcov becuase It's not mantained (the repo has been archived).

I'm generating the report with codecov format but I suppose you can easily change it for coveralls.

@leshow
Copy link

leshow commented Dec 2, 2024

thanks, I think i've got it working more of less the same but on the stable branch if you're interested:

  coverage:
    name: Run coverage
    runs-on: ubuntu-latest
    strategy:
      matrix:
        rust:
          - stable
    env:
      CARGO_INCREMENTAL: "0"
      RUSTFLAGS: "-Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off"
      SQLX_OFFLINE: true
    steps:
      - name: Checkout sources
        uses: actions/checkout@v2
      - name: Install toolchain
        uses: actions-rs/toolchain@v1
        with:
          toolchain: ${{ matrix.rust }}
          override: true
          components: llvm-tools-preview
      - name: Install cargo-llvm-cov
        uses: taiki-e/install-action@cargo-llvm-cov
      - name: Generate code coverage
        id: coverage
        run: cargo llvm-cov --all-features --exclude register_derive_impl --workspace --no-fail-fast --lcov --output-path lcov.info
        env:
          NODE_COVERALLS_DEBUG: true
      # - name: Upload coverage to Codecov
      #   uses: codecov/codecov-action@v3
      #   with:
      #     # token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
      #     files: lcov.info
      #     fail_ci_if_error: true
      - name: Coveralls upload
        uses: coverallsapp/github-action@master
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          path-to-lcov: lcov.info
          debug: true

if that helps anyone out, feel free to use it

@martinmr
Copy link

Thanks. This worked for me. The only thing I had to change was to run it in nightly to be able to turn coverage off for some code. Which means I lose grcov's ability to do it by line, but I'll have to do without for now.

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

5 participants