How to convert warnings to errors in `build.rs`?

For code not in build script,
I can use environment variable CARGO_ENCODED_RUSTFLAGS="-D\x1fwarnings"
to convert warnings into errors.

But this does not work for build scripts because I do not find a similar env variable for them.
CARGO_ENCODED_RUSTFLAGS has no effect for build script.

I do not want to change the source code of build.rs

Any ideas?

For dependencies from crates.io all lints are capped to allow by cargo so they will never cause compilation to fail. For a local crate yoi can pass RUSTFLAGS or use #![deny(warnings)] at the top of your lib.rs or main.rs.

1 Like

RUSTFLAGS not work for build.rs
and I prefer not to #![deny(warnings] in source code,
so I can use different script wrapper (call cargo with different env vars),
to choose whether or not treat warnings as errors

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.