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

How to configure compilation flags? #395

Closed
recmo opened this issue Apr 12, 2020 · 7 comments
Closed

How to configure compilation flags? #395

recmo opened this issue Apr 12, 2020 · 7 comments

Comments

@recmo
Copy link

recmo commented Apr 12, 2020

I'm struggling to see which compilation flags tarpaulin applies to build dependencies and tests.

In my mid-sized project I have the following in the workspace Cargo.toml:

# Compilation profile for any non-workspace member.
# We want deps to always be build optimized, otherwise tests will run very slow.
[profile.dev.package."*"]
opt-level = 3

By default, cargo in test or dev profile will not optimize dependencies (in both cases they are build using the dev profile). One of my dependencies is a mathy computational library that absolutely needs opt-level > 0 to have any performance. Without it, the tests run about 90x slower.

I also don't care about coverage in dependencies, so if possible, I'd like the coverage related flags like to be disabled there.

Related issue: With cargo I can run cargo -vvv and see exactly which rust flags are applied to each crate. Unfortunately, non of tarpaulin's options seem to give me this insight. I don't even know if it uses cargo under the hood.

This may be related to #340

@recmo recmo changed the title How to configure compliation flags? How to configure compilation flags? Apr 12, 2020
@xd009642
Copy link
Owner

So the coverage related options are mainly just linker ones, although I do set -C opt-level=0 in the rustflags for the build, I could potentially remove that though or try to set it in a smarter fashion. Unfortunately, there's not really a way to set linker flags etc for just the package in question and not dependencies (which can cause issues elsewhere). Not sure if that would overwrite the dev profile though, there is also --release to run tests in release mode which speeds things up.

--debug might give you enough printouts to figure out what's happening. Do you have an open source project for me to test this on?

@recmo
Copy link
Author

recmo commented Apr 13, 2020

--debug might give you enough printouts to figure out what's happening. Do you have an open source project for me to test this on?

It shows a lot, but not the compilation flags. This works however:

CARGO_TERM_VERBOSE=true cargo tarpaulin --verbose

The first thing I notice is that -C opt-level=0 is supplied (overriding the crates -C opt-level=3 which is also supplied), even when calling tarpaulin with --release:

root@c030e58e2c87:/volume/starkdex# CARGO_TERM_VERBOSE=true cargo tarpaulin -v --ignore-tests --timeout 300 --release
[INFO tarpaulin] Creating config
[INFO tarpaulin] Running Tarpaulin
[INFO tarpaulin] Building project
   Compiling libc v0.2.66
   Compiling cfg-if v0.1.10
   Compiling proc-macro2 v1.0.10
   Compiling unicode-xid v0.2.0
   Compiling semver-parser v0.7.0
   Compiling syn v1.0.13
   Compiling spin v0.5.2
   Compiling autocfg v0.1.7
     Running `rustc --crate-name build_script_build /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.66/build.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C opt-level=3 --cfg 'feature="default"' --cfg 'feature="std"' -C metadata=516556f2d4245440 -C extra-filename=-516556f2d4245440 --out-dir /volume/target/release/build/libc-516556f2d4245440 -L dependency=/volume/target/release/deps --cap-lints allow -C relocation-model=dynamic-no-pic -C link-dead-code -C opt-level=0 -C debuginfo=2 -C debug-assertions=off`
     Running `rustc --crate-name build_script_build --edition=2018 /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/syn-1.0.13/build.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C opt-level=3 --cfg 'feature="clone-impls"' --cfg 'feature="default"' --cfg 'feature="derive"' --cfg 'feature="full"' --cfg 'feature="parsing"' --cfg 'feature="printing"' --cfg 'feature="proc-macro"' --cfg 'feature="quote"' --cfg 'feature="visit"' -C metadata=aa0d523eb56b704e -C extra-filename=-aa0d523eb56b704e --out-dir /volume/target/release/build/syn-aa0d523eb56b704e -L dependency=/volume/target/release/deps --cap-lints allow -C relocation-model=dynamic-no-pic -C link-dead-code -C opt-level=0 -C debuginfo=2 -C debug-assertions=off`
     Running `rustc --crate-name build_script_build --edition=2018 /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-1.0.10/build.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C opt-level=3 --cfg 'feature="default"' --cfg 'feature="proc-macro"' -C metadata=5b0bc64aa61de0ae -C extra-filename=-5b0bc64aa61de0ae --out-dir /volume/target/release/build/proc-macro2-5b0bc64aa61de0ae -L dependency=/volume/target/release/deps --cap-lints allow -C relocation-model=dynamic-no-pic -C link-dead-code -C opt-level=0 -C debuginfo=2 -C debug-assertions=off`
     Running `rustc --crate-name cfg_if --edition=2018 /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/cfg-if-0.1.10/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C metadata=c1e0a4bead896f93 -C extra-filename=-c1e0a4bead896f93 --out-dir /volume/target/release/deps -L dependency=/volume/target/release/deps --cap-lints allow -C relocation-model=dynamic-no-pic -C link-dead-code -C opt-level=0 -C debuginfo=2 -C debug-assertions=off`

@recmo
Copy link
Author

recmo commented Apr 13, 2020

I'm surprised that I don't see -Z profile in there. How does tarpaulin collect execution traces?

@xd009642
Copy link
Owner

So tarpaulin was created before the -Z profile option was added and works similar to kcov in that it uses breakpoint style instrumentation to find coverage stats instead of adding instructions to the binary like gcov does.

There's been some other improvements in the code to find instructions to instrument so I'll remove the opt-level flag as that was largely a pessimistic attempt to give more surface area to attach to, and then test on a few larger projects to make sure it doesn't affect the accuracy of the results. I'll also all some debug printouts to show the flags cargo is ran with as well.

@xd009642
Copy link
Owner

There's something pushed to develop if you want to try it out

@xd009642
Copy link
Owner

so the opt-level overriding is removed in the latest version and verbosity of cargo is now increased for --debug. I've also got a new released version with these changes so let me know if this solves your issues 👍

@xd009642
Copy link
Owner

xd009642 commented Jun 6, 2020

Since tarpaulin no longer overrides the opt-level and I haven't heard anything else I'm just going to close this. Let me know if you have any other issues

@xd009642 xd009642 closed this as completed Jun 6, 2020
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

2 participants