From 3b057d3ed1c48412866b373f35223bd2a2487c7f Mon Sep 17 00:00:00 2001 From: Joel Aschmann Date: Wed, 8 Feb 2023 13:04:36 +0100 Subject: [PATCH] Add warning on not replaced definitions --- build.rs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/build.rs b/build.rs index 67c8959..57f5d9f 100644 --- a/build.rs +++ b/build.rs @@ -463,11 +463,26 @@ fn main() { if env::var("CARGO_FEATURE_KEEP_EXTERN_TYPES").is_err() { // There's only one `pub type` usually, and that breaks use on stable, and src/inline.rs has a // workaround for that - rustcode = rustcode.replace("\n pub type __locale_t;", ""); - rustcode = rustcode.replace("\n pub type _IO_wide_data;", ""); - rustcode = rustcode.replace("\n pub type _IO_codecvt;", ""); - rustcode = rustcode.replace("\n pub type _IO_marker;", ""); - rustcode = rustcode.replace("\n pub type __lock;", ""); + let replacements = [ + ("\n pub type __locale_t;", ""), + ("\n pub type _IO_wide_data;", ""), + ("\n pub type _IO_codecvt;", ""), + ("\n pub type _IO_marker;", ""), + ("\n pub type __lock;", ""), + ]; + + let mut old_len = rustcode.len(); + + for (reg, repl) in replacements { + rustcode = rustcode.replace(reg, repl); + + if rustcode.len() != old_len { + eprintln!("Could not remove {reg} from generated rustcode.\ +This might lead to duplicate definitions. Consider using cargo feature \"keep-extern-types\" if this causes problems") + } + + old_len = rustcode.len(); + } } // Replace the function declarations with ... usually something pub, but special considerations