Ignoring RUSTFLAGS in one part of the dependency tree

I have an application which I want to instrument with LLVM SanitizerCoverage. I can do this with the rust compiler flags INSTRUMENTATION_OPTIONS="-Cpasses=sancov-module -Cllvm-args=-sanitizer-coverage-level=1 -Cllvm-args=-sanitizer-coverage-trace-pc-guard".

The problem is that I need to exempt one part of the dependency tree from this instrumentation, because it provides the callback functions. This is included in a package instrument which is included in the workspace. This package also has some dependencies, which must not be instrumented. This package is then a dependency of the main package.

I've managed to do this by compiling the instrument package first with cargo rustc -p instrument, and afterwards compiling the main binary with cargo rustc -p mainapp -- $INSTRUMENTATION_OPTIONS. Unfortunately, this only instruments the mainapp package, and not it's dependencies.

If I set RUSTFLAGS=$INSTRUMENTATION_OPTIONS, it will pass the compiler options to all dependencies during compilation, but then causing the instrument to be recompiled as well, with the instrumentation.

Is there any way to have cargo not recompile the package and it's dependencies? I also thought about parsing cargo metadata and recompiling every package manually, but somehow I think then I'll end up in reimplementing cargo.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.