@@ -22,6 +22,89 @@ fn main() {
2222 generate_bindings ( & out_dir, & include_dir) ;
2323
2424 println ! ( "cargo:root={}" , install_dir. display( ) ) ;
25+
26+ // Emit rerun-if-changed directives to avoid unnecessary rebuilds
27+ emit_rerun_if_changed ( ) ;
28+ }
29+
30+ fn emit_rerun_if_changed ( ) {
31+ // Build script itself
32+ println ! ( "cargo:rerun-if-changed=build.rs" ) ;
33+
34+ // Template files
35+ println ! ( "cargo:rerun-if-changed=nghttp2/lib/includes/nghttp2/nghttp2ver.h.in" ) ;
36+ println ! ( "cargo:rerun-if-changed=nghttp2/lib/libnghttp2.pc.in" ) ;
37+
38+ // Header files
39+ println ! ( "cargo:rerun-if-changed=nghttp2/lib/includes/nghttp2/nghttp2.h" ) ;
40+
41+ // All source files
42+ const SOURCES : & [ & str ] = & [
43+ "nghttp2/lib/sfparse.c" ,
44+ "nghttp2/lib/nghttp2_alpn.c" ,
45+ "nghttp2/lib/nghttp2_buf.c" ,
46+ "nghttp2/lib/nghttp2_callbacks.c" ,
47+ "nghttp2/lib/nghttp2_debug.c" ,
48+ "nghttp2/lib/nghttp2_extpri.c" ,
49+ "nghttp2/lib/nghttp2_frame.c" ,
50+ "nghttp2/lib/nghttp2_hd.c" ,
51+ "nghttp2/lib/nghttp2_hd_huffman.c" ,
52+ "nghttp2/lib/nghttp2_hd_huffman_data.c" ,
53+ "nghttp2/lib/nghttp2_helper.c" ,
54+ "nghttp2/lib/nghttp2_http.c" ,
55+ "nghttp2/lib/nghttp2_map.c" ,
56+ "nghttp2/lib/nghttp2_mem.c" ,
57+ "nghttp2/lib/nghttp2_option.c" ,
58+ "nghttp2/lib/nghttp2_outbound_item.c" ,
59+ "nghttp2/lib/nghttp2_pq.c" ,
60+ "nghttp2/lib/nghttp2_priority_spec.c" ,
61+ "nghttp2/lib/nghttp2_queue.c" ,
62+ "nghttp2/lib/nghttp2_rcbuf.c" ,
63+ "nghttp2/lib/nghttp2_session.c" ,
64+ "nghttp2/lib/nghttp2_stream.c" ,
65+ "nghttp2/lib/nghttp2_submit.c" ,
66+ "nghttp2/lib/nghttp2_version.c" ,
67+ "nghttp2/lib/nghttp2_ratelim.c" ,
68+ "nghttp2/lib/nghttp2_time.c" ,
69+ ] ;
70+
71+ for source in SOURCES {
72+ println ! ( "cargo:rerun-if-changed={}" , source) ;
73+ }
74+
75+ // Header dependencies
76+ const HEADERS : & [ & str ] = & [
77+ "nghttp2/lib/sfparse.h" ,
78+ "nghttp2/lib/nghttp2_alpn.h" ,
79+ "nghttp2/lib/nghttp2_buf.h" ,
80+ "nghttp2/lib/nghttp2_callbacks.h" ,
81+ "nghttp2/lib/nghttp2_debug.h" ,
82+ "nghttp2/lib/nghttp2_extpri.h" ,
83+ "nghttp2/lib/nghttp2_frame.h" ,
84+ "nghttp2/lib/nghttp2_hd.h" ,
85+ "nghttp2/lib/nghttp2_hd_huffman.h" ,
86+ "nghttp2/lib/nghttp2_helper.h" ,
87+ "nghttp2/lib/nghttp2_http.h" ,
88+ "nghttp2/lib/nghttp2_int.h" ,
89+ "nghttp2/lib/nghttp2_map.h" ,
90+ "nghttp2/lib/nghttp2_mem.h" ,
91+ "nghttp2/lib/nghttp2_net.h" ,
92+ "nghttp2/lib/nghttp2_option.h" ,
93+ "nghttp2/lib/nghttp2_outbound_item.h" ,
94+ "nghttp2/lib/nghttp2_pq.h" ,
95+ "nghttp2/lib/nghttp2_priority_spec.h" ,
96+ "nghttp2/lib/nghttp2_queue.h" ,
97+ "nghttp2/lib/nghttp2_ratelim.h" ,
98+ "nghttp2/lib/nghttp2_rcbuf.h" ,
99+ "nghttp2/lib/nghttp2_session.h" ,
100+ "nghttp2/lib/nghttp2_stream.h" ,
101+ "nghttp2/lib/nghttp2_submit.h" ,
102+ "nghttp2/lib/nghttp2_time.h" ,
103+ ] ;
104+
105+ for header in HEADERS {
106+ println ! ( "cargo:rerun-if-changed={}" , header) ;
107+ }
25108}
26109
27110struct NgHttp2Version {
@@ -201,6 +284,10 @@ fn generate_bindings(out_dir: &Path, include_dir: &Path) {
201284 builder = builder. clang_arg ( format ! ( "-D{}" , ssize_t_def) ) ;
202285 }
203286
287+ // Note: We don't use CargoCallbacks here because it would emit
288+ // rerun-if-changed for generated headers in OUT_DIR (whose path changes
289+ // between builds) and system headers. We manually emit rerun-if-changed
290+ // for the source files in emit_rerun_if_changed() instead.
204291 let bindings = builder
205292 // Only include nghttp2 symbols
206293 . allowlist_function ( "nghttp2_.*" )
@@ -220,7 +307,6 @@ fn generate_bindings(out_dir: &Path, include_dir: &Path) {
220307 . blocklist_function ( ".*vprintf.*" )
221308 . blocklist_type ( ".*va_list.*" )
222309 . blocklist_type ( "nghttp2_debug_vprintf_callback" )
223- . parse_callbacks ( Box :: new ( bindgen:: CargoCallbacks :: new ( ) ) )
224310 . generate ( )
225311 . expect ( "Failed to generate bindings" ) ;
226312
0 commit comments