Enable "verbose output" for build.rs

Hi - I'm working on a project that uses a build.rs. I'd like some way to enable verbose output for it. (In my case, I want to pass the verbose flag onto cmake.)

I was hoping to piggy-back off of rust's term.verbose configuration value, but I can't see a way to access that value from inside build.rs:

  • it's not listed in Environment variables Cargo sets for crates

  • when I inspect std::env::vars() from inside build.rs, CARGO_TERM_VERBOSE is not set, even if I have

    [term]
    verbose = true
    

    ...inside my .cargo/config.toml

In general, how do people provide configurable behavior for build.rs? Do people just use env vars, or is there something more rust / cargo specific?

You can always output verbose output from your build.rs script, because Cargo will capture it and not print anything during normal successful builds. You can then use cargo build -vvv to print the whole output.

If you need it to be conditional, then I don't think there's anything in Cargo right now. You can always check for your own env variable.

2 Likes