RalfJung/cargo-careful

`build.rustflags` is ignored

RalfJung opened this issue · 6 comments

via reddit:

I'm using special flags, like:

$ cat .cargo/config.toml 
[build]
rustflags = ["--cfg", "tokio_unstable"]

cargo careful does not seem to use this flag.

This is probably because we are setting rustflags ourselves, cargo stops using the flags from the toml file.

It seems like the RUSTFLAGS environment variable is ignored too, so currently this can't be used with a sanitizer.

Would fixing this require handling escaped and quoted whitespace?

Sanitizer support is being worked on in #5, seems to be blocked on some macOS trouble.

RUSTFLAGS does not support escaping or quoting whitespace, we have to parse it the same way cargo does, or how Miri parses MIRIFLAGS:

    if let Ok(a) = env::var("MIRIFLAGS") {
        // This code is taken from `RUSTFLAGS` handling in cargo.
        let args = a.split(' ').map(str::trim).filter(|s| !s.is_empty()).map(str::to_string);

Once this is possible we probably want to revert #11.

One interesting question here is whether RUSTFLAGS should also be applied to the stdlib build. Usually of course that is not the case, and Miri also deliberately does not apply MIRIFLAGS to the stdlib build. If we want to allow setting stdlib flags, that should probably be a separate flag?

They should apply to the stdlib build. Not applying them would diverge from the behavior of -Zbuild-std, and if people are using RUSTFLAGS to turn on sanitizers, they will always want that option applied to the standard library as well.

We have -Zcareful-sanitizer for sanitizers.

But yeah we can only be consistent with regular builds or build-std.