rust-lang / cargo

The Rust package manager
https://doc.rust-lang.org/cargo
Apache License 2.0
12.71k stars 2.42k forks source link

Export sanitizer settings in `cargo` CLI #14523

Open Kixunil opened 1 month ago

Kixunil commented 1 month ago

Problem

Using sanitizers currently requires RUSTFLAGS this is not discoverable.

Proposed Solution

Expose sanitizer settings in cargo's CLI.

Notes

I've opened this as requested in https://github.com/rust-lang/cargo/issues/12739#issuecomment-2338147752

epage commented 1 month ago

Could you provide more details on this as it doesn't provide enough background to understand requirements. Which sanitizer settings? How do you use them?

Kixunil commented 1 month ago

For instance, we currently set these flags in CI: RUSTFLAGS='-Zsanitizer=address -Clinker=clang -Cforce-frame-pointers=yes'

Having something like cargo test --sanitize=address would be more discoverable and easier to type.

epage commented 1 month ago

As in you'd want cargo test --sanitize=address to mean RUSTFLAGS='-Zsanitizer=address or RUSTFLAGS='-Zsanitizer=address -Clinker=clang -Cforce-frame-pointers=yes'?

If the latter, why is that specific policy the one we should set on users behalf? It especially seems worrisome to override the linker as that would be surprising.

Could you go into:

How do you use them?

What is important for us to understand is the requirements behind this. You suggested this to be in the CLI but is that the right place? Would this be better as a profile config? Understanding how people would expect to use it will help in understanding how to abstract these rustc features.

Kixunil commented 1 month ago

I'm not super knowledgeable about sanitizer specifics but IIRC without the linker flag it doesn't work at all and without -Cforce-frame-pointers=yes the backtraces are messed up and it's hard to understand what went wrong, so it likely should be the defaul.

How do you use them?

Each sanitizer is ran in a separate process (because it requires different recompilation). I think it could work with custom profiles, though requiring everyone to set the same profiles (possibly polluting Cargo.toml) seems too much to me. If only one sanitizer existed I guess I would be more open to it but since there's multiple of them and people likely want to use more than one it's quite some boilerplate.