rust-lang / cc-rs

Rust library for build scripts to compile C/C++ code into a Rust library
https://docs.rs/cc
Apache License 2.0
1.81k stars 436 forks source link

Build C/C++ code with the same sanitizer as Rust #563

Open alexeyr opened 3 years ago

alexeyr commented 3 years ago

When using -Zsanitizer= I think it might be a good idea to pass corresponding option to the C/C++ compiler as well (if it supports it). It's easy to check if it's in RUSTFLAGS, but I don't know if that's enough.

dot-asm commented 2 years ago

The sanitizer relies on code instrumentation and corresponding run-time. This means that mix-n-matching Rust and C compiler versions is unlikely to work. Same LLVM version from Rust and Clang should work, but one shouldn't hold the breath for any other combination. Given the uncertainties it's probably safer to leave it to the user. All you'll need to do is to set additional environment variable, e.g. env RUSTFLAGS=-Zsanitizer=address CFLAGS=-fsanitize=address cargo ....