Skip to content

Commit 62667d7

Browse files
committed
rust: Apply -Werror if -Dwarnings
If user enables -Dwarnings via RUSTFLAGS also enable -Werror for C code compiled by cargo/build.rs.
1 parent 579a2eb commit 62667d7

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/rust/bitbox02-sys/build.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ pub fn main() -> Result<(), &'static str> {
270270
let arm_sysroot = env::var("CMAKE_SYSROOT").unwrap_or("/usr/local/arm-none-eabi".to_string());
271271
let arm_sysroot = format!("--sysroot={arm_sysroot}");
272272

273-
let extra_flags = if cross_compiling {
273+
let mut extra_flags = if cross_compiling {
274274
vec![
275275
"-D__SAMD51J20A__",
276276
"--target=thumbv7em-none-eabi",
@@ -284,6 +284,15 @@ pub fn main() -> Result<(), &'static str> {
284284
vec!["-DTESTING", "-D_UNIT_TEST_", "-DPRODUCT_BITBOX_MULTI=1"]
285285
};
286286

287+
// If user enables -Dwarnings for rust we also want to enable -Werror for C.
288+
if let Ok(rustflags) = std::env::var("CARGO_ENCODED_RUSTFLAGS") {
289+
for flag in rustflags.split('\x1f') {
290+
if flag == "-Dwarnings" {
291+
extra_flags.push("-Werror");
292+
}
293+
}
294+
}
295+
287296
let mut includes = vec![
288297
// $INCLUDES
289298
"../..",

0 commit comments

Comments
 (0)