@@ -325,6 +325,11 @@ impl Builder {
325325 . map ( String :: into_boxed_str) ,
326326 ) ;
327327
328+ for header in & self . options . input_headers {
329+ self . options
330+ . for_each_callback ( |cb| cb. header_file ( header. as_ref ( ) ) ) ;
331+ }
332+
328333 // Transform input headers to arguments on the clang command line.
329334 self . options . clang_args . extend (
330335 self . options . input_headers
@@ -566,6 +571,10 @@ impl BindgenOptions {
566571 . collect ( )
567572 }
568573
574+ fn for_each_callback ( & self , f : impl Fn ( & dyn callbacks:: ParseCallbacks ) ) {
575+ self . parse_callbacks . iter ( ) . for_each ( |cb| f ( cb. as_ref ( ) ) ) ;
576+ }
577+
569578 fn process_comment ( & self , comment : & str ) -> String {
570579 let comment = comment:: preprocess ( comment) ;
571580 self . parse_callbacks
@@ -1232,9 +1241,50 @@ fn get_target_dependent_env_var(
12321241/// .generate();
12331242/// ```
12341243#[ derive( Debug ) ]
1235- pub struct CargoCallbacks ;
1244+ pub struct CargoCallbacks {
1245+ rerun_on_header_files : bool ,
1246+ }
1247+
1248+ /// Create a new `CargoCallbacks` value with [`CargoCallbacks::rerun_on_header_files`] disabled.
1249+ ///
1250+ /// This constructor has been deprecated in favor of [`CargoCallbacks::new`] where
1251+ /// [`CargoCallbacks::rerun_on_header_files`] is enabled by default.
1252+ #[ deprecated = "Use `CargoCallbacks::new()` instead. Please, check the documentation for further information." ]
1253+ pub const CargoCallbacks : CargoCallbacks = CargoCallbacks {
1254+ rerun_on_header_files : false ,
1255+ } ;
1256+
1257+ impl CargoCallbacks {
1258+ /// Create a new `CargoCallbacks` value.
1259+ pub fn new ( ) -> Self {
1260+ Self {
1261+ rerun_on_header_files : true ,
1262+ }
1263+ }
1264+
1265+ /// Whether Cargo should re-run the build script if any of the input header files has changed.
1266+ ///
1267+ /// This option is enabled by default unless the deprecated [`const@CargoCallbacks`]
1268+ /// constructor is used.
1269+ pub fn rerun_on_header_files ( mut self , doit : bool ) -> Self {
1270+ self . rerun_on_header_files = doit;
1271+ self
1272+ }
1273+ }
1274+
1275+ impl Default for CargoCallbacks {
1276+ fn default ( ) -> Self {
1277+ Self :: new ( )
1278+ }
1279+ }
12361280
12371281impl callbacks:: ParseCallbacks for CargoCallbacks {
1282+ fn header_file ( & self , filename : & str ) {
1283+ if self . rerun_on_header_files {
1284+ println ! ( "cargo:rerun-if-changed={}" , filename) ;
1285+ }
1286+ }
1287+
12381288 fn include_file ( & self , filename : & str ) {
12391289 println ! ( "cargo:rerun-if-changed={}" , filename) ;
12401290 }
0 commit comments