I have a workspace with two crates: lib and app, where I want to use code from lib in app.
Additionally, I want to have the following Cargo config only in the lib crate to insturment the lib crate with LLVMs SanitizeCoverage (I provide the callback functions of the SanitizeCoverage in the app crate, because they must not be instrumented, otherwise there would be a stack overflow):
[build]
rustflags = [
"-Cpasses=sancov-module",
"-Cllvm-args=-sanitizer-coverage-level=1",
"-Cllvm-args=-sanitizer-coverage-trace-pc-guard",
]
Unfortunately, Cargo does not use this config file if it is included in lib/.cargo/config.toml.
I tried to pass the config with a build.rs of the lib crate:
pub fn main() {
println!("cargo:rustc-env=RUSTFLAGS=\"-Cpasses=sancov-module -Cllvm-args=-sanitizer-coverage-level=1 -Cllvm-args=-sanitizer-coverage-trace-pc-guard\"");
}
But this also does not work (The code is not instrumented, as I've checked with the disassembly afterwards).
Is there any way to do this? I also tried to create two different crates, without a workspace, but then the Cargo config file of the lib crate is also ignored. I also tried to manually create a rlib and link to it manually, but while this works more or less, it is really problematic as I have to export a C interface in that case. Also, this fails if I want to execute it in the Fortanix SGX framework (which is my ultimate goal).