rust-lang / cargo

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

How can debuginfo be detected from a build.rs ? #5891

Open gnzlbg opened 6 years ago

gnzlbg commented 6 years ago

Does cargo define an environment variable with its value from the profile ? (I couldn't find any).

If so, is this value updated with the RUSTFLAGS/ ./cargo/config ?

The most portable way I can think of, of doing this correctly, is probably to just invoke cargo metadata from the build.rs, and just scan it for debuginfo=PAT and parse that.

gnzlbg commented 6 years ago

So the DEBUG environment variable allows detecting whether in the profile debug={true,false}, but this does not allow detecting whether -C debuginfo={0,1,2} was passed via RUSTFLAGS, .cargo/config, etc.

alexcrichton commented 6 years ago

I think we should probably add something liek CARGO_DEBUG_LEVEL=1 which is unconditionally set for build scripts which ferries over the 0/1/2 level into build scripts, but currently this is not done for build scripts AFAIK.

epage commented 11 months ago

To evaluate this, it would help i we had more information on the use case.