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

cargoLlvmCov produces different result in Nix derivation than a regular invocation #283

Open
phip1611 opened this issue Mar 29, 2023 · 5 comments
Labels
needs reproduction Missing a flake which easily reproduces the problem

Comments

@phip1611
Copy link

When I execute cargo llvm-cov directly, results seem to be fine. When I execute it in a Nix derivation using crane.cargoLlvmCov, it seems like it takes all dependencies into account as well. However, this is not something that you want. The difference is significant:

Without Nix: lines......: 65.5% (16880 of 25762 lines)
Within Nix: lines......: 22.4% (38873 of 173539 lines)

I suppose that in the regular workflow, llvm-cov filters out all dependencies (by some regex into the target folder), while in the Nix derivation the target folder is not within the same location as the src folder, hence, some regex probably doesn't match anymore.

I tried to workaround this with the --ignore-filenames-regex parameter of cargo-llvm-cov, but without success. I can't find the location where the build artifacts are stored. It is neither in $CARGO_TARGET_DIR nor in $CARGO_BUILD_TARGET_DIR

@ipetkov
Copy link
Owner

ipetkov commented Apr 2, 2023

I'm not entirely sure why that happens, maybe it's the default --output-path $out argument that we set?

cc @figsoda in case you have more context around this?

@figsoda
Copy link
Contributor

figsoda commented Apr 15, 2023

I'm not sure what could be causing this, could it have something to do with cargoArtifacts?

@dpc
Copy link
Contributor

dpc commented Apr 15, 2023

FWIW. In our CI we're doing:

  # Build only deps, but with llvm-cov so `workspaceCov` can reuse them cached
  workspaceDepsCov = craneLib.buildDepsOnly (commonArgsDepsOnly // {
    pnameSuffix = "-lcov-deps";
    version = "0.0.1";
    buildPhaseCargoCommand = "cargo llvm-cov --locked --workspace --profile $CARGO_PROFILE --no-report";
    cargoBuildCommand = "dontuse";
    cargoCheckCommand = "dontuse";
    nativeBuildInputs = commonArgs.nativeBuildInputs ++ [ cargo-llvm-cov ];
    doCheck = false;
  });

  workspaceCov = craneLib.buildPackage (commonArgs // {
    pnameSuffix = "-lcov";
    version = "0.0.1";
    cargoArtifacts = workspaceDepsCov;
    buildPhaseCargoCommand = "mkdir -p $out ; env RUST_LOG=info,timing=debug cargo llvm-cov --locked --workspace --profile $CARGO_PROFILE --lcov --all-targets --tests --output-path $out/lcov.info --  --test-threads=$(($(nproc) * 2))";
    installPhaseCommand = "true";
    nativeBuildInputs = commonArgs.nativeBuildInputs ++ [ cargo-llvm-cov ];
    doCheck = false;
  });

and it works fine, AFAICT, a 60% coverage.

@phip1611
Copy link
Author

and it works fine, AFAICT, a 60% coverage.

With and also without Nix?

@dpc
Copy link
Contributor

dpc commented Apr 18, 2023

We never run it locally, AFAICT. So with, in our CI. But by calling cargo llvm-cov directly, no with crane.cargoLlvmCov

@ipetkov ipetkov added the needs reproduction Missing a flake which easily reproduces the problem label Apr 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs reproduction Missing a flake which easily reproduces the problem
Projects
None yet
Development

No branches or pull requests

4 participants