@@ -325,6 +325,11 @@ impl Builder {
325
325
. map ( String :: into_boxed_str) ,
326
326
) ;
327
327
328
+ for header in & self . options . input_headers {
329
+ self . options
330
+ . for_each_callback ( |cb| cb. header_file ( header. as_ref ( ) ) ) ;
331
+ }
332
+
328
333
// Transform input headers to arguments on the clang command line.
329
334
self . options . clang_args . extend (
330
335
self . options . input_headers
@@ -566,6 +571,10 @@ impl BindgenOptions {
566
571
. collect ( )
567
572
}
568
573
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
+
569
578
fn process_comment ( & self , comment : & str ) -> String {
570
579
let comment = comment:: preprocess ( comment) ;
571
580
self . parse_callbacks
@@ -1232,9 +1241,50 @@ fn get_target_dependent_env_var(
1232
1241
/// .generate();
1233
1242
/// ```
1234
1243
#[ 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
+ }
1236
1280
1237
1281
impl 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
+
1238
1288
fn include_file ( & self , filename : & str ) {
1239
1289
println ! ( "cargo:rerun-if-changed={}" , filename) ;
1240
1290
}
0 commit comments