From ad6e3ecde5b2c77c20982db5cc56a910bd63bfe0 Mon Sep 17 00:00:00 2001 From: kaju Date: Tue, 3 Mar 2026 10:18:10 +0000 Subject: [PATCH 1/3] fix: add rerun-if-changed to avoid unnecessary rebuilds The build script was missing cargo:rerun-if-changed directives, causing Cargo to rerun it on every build. Additionally, bindgen's CargoCallbacks was emitting rerun-if-changed for generated headers in OUT_DIR (whose path changes between builds) and system headers. Fixed by: 1. Adding explicit rerun-if-changed for all source files, headers, and template files 2. Removing CargoCallbacks from bindgen since we now manually track all relevant files --- build.rs | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 87 insertions(+), 1 deletion(-) diff --git a/build.rs b/build.rs index d6eb499..154df84 100644 --- a/build.rs +++ b/build.rs @@ -22,6 +22,89 @@ fn main() { generate_bindings(&out_dir, &include_dir); println!("cargo:root={}", install_dir.display()); + + // Emit rerun-if-changed directives to avoid unnecessary rebuilds + emit_rerun_if_changed(); +} + +fn emit_rerun_if_changed() { + // Build script itself + println!("cargo:rerun-if-changed=build.rs"); + + // Template files + println!("cargo:rerun-if-changed=nghttp2/lib/includes/nghttp2/nghttp2ver.h.in"); + println!("cargo:rerun-if-changed=nghttp2/lib/libnghttp2.pc.in"); + + // Header files + println!("cargo:rerun-if-changed=nghttp2/lib/includes/nghttp2/nghttp2.h"); + + // All source files + const SOURCES: &[&str] = &[ + "nghttp2/lib/sfparse.c", + "nghttp2/lib/nghttp2_alpn.c", + "nghttp2/lib/nghttp2_buf.c", + "nghttp2/lib/nghttp2_callbacks.c", + "nghttp2/lib/nghttp2_debug.c", + "nghttp2/lib/nghttp2_extpri.c", + "nghttp2/lib/nghttp2_frame.c", + "nghttp2/lib/nghttp2_hd.c", + "nghttp2/lib/nghttp2_hd_huffman.c", + "nghttp2/lib/nghttp2_hd_huffman_data.c", + "nghttp2/lib/nghttp2_helper.c", + "nghttp2/lib/nghttp2_http.c", + "nghttp2/lib/nghttp2_map.c", + "nghttp2/lib/nghttp2_mem.c", + "nghttp2/lib/nghttp2_option.c", + "nghttp2/lib/nghttp2_outbound_item.c", + "nghttp2/lib/nghttp2_pq.c", + "nghttp2/lib/nghttp2_priority_spec.c", + "nghttp2/lib/nghttp2_queue.c", + "nghttp2/lib/nghttp2_rcbuf.c", + "nghttp2/lib/nghttp2_session.c", + "nghttp2/lib/nghttp2_stream.c", + "nghttp2/lib/nghttp2_submit.c", + "nghttp2/lib/nghttp2_version.c", + "nghttp2/lib/nghttp2_ratelim.c", + "nghttp2/lib/nghttp2_time.c", + ]; + + for source in SOURCES { + println!("cargo:rerun-if-changed={}", source); + } + + // Header dependencies + const HEADERS: &[&str] = &[ + "nghttp2/lib/sfparse.h", + "nghttp2/lib/nghttp2_alpn.h", + "nghttp2/lib/nghttp2_buf.h", + "nghttp2/lib/nghttp2_callbacks.h", + "nghttp2/lib/nghttp2_debug.h", + "nghttp2/lib/nghttp2_extpri.h", + "nghttp2/lib/nghttp2_frame.h", + "nghttp2/lib/nghttp2_hd.h", + "nghttp2/lib/nghttp2_hd_huffman.h", + "nghttp2/lib/nghttp2_helper.h", + "nghttp2/lib/nghttp2_http.h", + "nghttp2/lib/nghttp2_int.h", + "nghttp2/lib/nghttp2_map.h", + "nghttp2/lib/nghttp2_mem.h", + "nghttp2/lib/nghttp2_net.h", + "nghttp2/lib/nghttp2_option.h", + "nghttp2/lib/nghttp2_outbound_item.h", + "nghttp2/lib/nghttp2_pq.h", + "nghttp2/lib/nghttp2_priority_spec.h", + "nghttp2/lib/nghttp2_queue.h", + "nghttp2/lib/nghttp2_ratelim.h", + "nghttp2/lib/nghttp2_rcbuf.h", + "nghttp2/lib/nghttp2_session.h", + "nghttp2/lib/nghttp2_stream.h", + "nghttp2/lib/nghttp2_submit.h", + "nghttp2/lib/nghttp2_time.h", + ]; + + for header in HEADERS { + println!("cargo:rerun-if-changed={}", header); + } } struct NgHttp2Version { @@ -201,6 +284,10 @@ fn generate_bindings(out_dir: &Path, include_dir: &Path) { builder = builder.clang_arg(format!("-D{}", ssize_t_def)); } + // Note: We don't use CargoCallbacks here because it would emit + // rerun-if-changed for generated headers in OUT_DIR (whose path changes + // between builds) and system headers. We manually emit rerun-if-changed + // for the source files in emit_rerun_if_changed() instead. let bindings = builder // Only include nghttp2 symbols .allowlist_function("nghttp2_.*") @@ -220,7 +307,6 @@ fn generate_bindings(out_dir: &Path, include_dir: &Path) { .blocklist_function(".*vprintf.*") .blocklist_type(".*va_list.*") .blocklist_type("nghttp2_debug_vprintf_callback") - .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) .generate() .expect("Failed to generate bindings"); From cd67eca4b285a908e8c5a336ea98ddea5c8eabfb Mon Sep 17 00:00:00 2001 From: kaju Date: Tue, 3 Mar 2026 10:49:58 +0000 Subject: [PATCH 2/3] refactor: deduplicate SOURCES/HEADERS constants --- build.rs | 151 ++++++++++++++++++++++--------------------------------- 1 file changed, 61 insertions(+), 90 deletions(-) diff --git a/build.rs b/build.rs index 154df84..2352ec2 100644 --- a/build.rs +++ b/build.rs @@ -2,6 +2,64 @@ use std::env; use std::fs; use std::path::{Path, PathBuf}; +const SOURCES: &[&str] = &[ + "nghttp2/lib/sfparse.c", + "nghttp2/lib/nghttp2_alpn.c", + "nghttp2/lib/nghttp2_buf.c", + "nghttp2/lib/nghttp2_callbacks.c", + "nghttp2/lib/nghttp2_debug.c", + "nghttp2/lib/nghttp2_extpri.c", + "nghttp2/lib/nghttp2_frame.c", + "nghttp2/lib/nghttp2_hd.c", + "nghttp2/lib/nghttp2_hd_huffman.c", + "nghttp2/lib/nghttp2_hd_huffman_data.c", + "nghttp2/lib/nghttp2_helper.c", + "nghttp2/lib/nghttp2_http.c", + "nghttp2/lib/nghttp2_map.c", + "nghttp2/lib/nghttp2_mem.c", + "nghttp2/lib/nghttp2_option.c", + "nghttp2/lib/nghttp2_outbound_item.c", + "nghttp2/lib/nghttp2_pq.c", + "nghttp2/lib/nghttp2_priority_spec.c", + "nghttp2/lib/nghttp2_queue.c", + "nghttp2/lib/nghttp2_rcbuf.c", + "nghttp2/lib/nghttp2_session.c", + "nghttp2/lib/nghttp2_stream.c", + "nghttp2/lib/nghttp2_submit.c", + "nghttp2/lib/nghttp2_version.c", + "nghttp2/lib/nghttp2_ratelim.c", + "nghttp2/lib/nghttp2_time.c", +]; + +const HEADERS: &[&str] = &[ + "nghttp2/lib/sfparse.h", + "nghttp2/lib/nghttp2_alpn.h", + "nghttp2/lib/nghttp2_buf.h", + "nghttp2/lib/nghttp2_callbacks.h", + "nghttp2/lib/nghttp2_debug.h", + "nghttp2/lib/nghttp2_extpri.h", + "nghttp2/lib/nghttp2_frame.h", + "nghttp2/lib/nghttp2_hd.h", + "nghttp2/lib/nghttp2_hd_huffman.h", + "nghttp2/lib/nghttp2_helper.h", + "nghttp2/lib/nghttp2_http.h", + "nghttp2/lib/nghttp2_int.h", + "nghttp2/lib/nghttp2_map.h", + "nghttp2/lib/nghttp2_mem.h", + "nghttp2/lib/nghttp2_net.h", + "nghttp2/lib/nghttp2_option.h", + "nghttp2/lib/nghttp2_outbound_item.h", + "nghttp2/lib/nghttp2_pq.h", + "nghttp2/lib/nghttp2_priority_spec.h", + "nghttp2/lib/nghttp2_queue.h", + "nghttp2/lib/nghttp2_ratelim.h", + "nghttp2/lib/nghttp2_rcbuf.h", + "nghttp2/lib/nghttp2_session.h", + "nghttp2/lib/nghttp2_stream.h", + "nghttp2/lib/nghttp2_submit.h", + "nghttp2/lib/nghttp2_time.h", +]; + fn main() { let out_dir = PathBuf::from(env::var_os("OUT_DIR").expect("OUT_DIR not set")); let target = env::var("TARGET").expect("TARGET not set"); @@ -35,73 +93,15 @@ fn emit_rerun_if_changed() { println!("cargo:rerun-if-changed=nghttp2/lib/includes/nghttp2/nghttp2ver.h.in"); println!("cargo:rerun-if-changed=nghttp2/lib/libnghttp2.pc.in"); - // Header files + // Header files (public) println!("cargo:rerun-if-changed=nghttp2/lib/includes/nghttp2/nghttp2.h"); - // All source files - const SOURCES: &[&str] = &[ - "nghttp2/lib/sfparse.c", - "nghttp2/lib/nghttp2_alpn.c", - "nghttp2/lib/nghttp2_buf.c", - "nghttp2/lib/nghttp2_callbacks.c", - "nghttp2/lib/nghttp2_debug.c", - "nghttp2/lib/nghttp2_extpri.c", - "nghttp2/lib/nghttp2_frame.c", - "nghttp2/lib/nghttp2_hd.c", - "nghttp2/lib/nghttp2_hd_huffman.c", - "nghttp2/lib/nghttp2_hd_huffman_data.c", - "nghttp2/lib/nghttp2_helper.c", - "nghttp2/lib/nghttp2_http.c", - "nghttp2/lib/nghttp2_map.c", - "nghttp2/lib/nghttp2_mem.c", - "nghttp2/lib/nghttp2_option.c", - "nghttp2/lib/nghttp2_outbound_item.c", - "nghttp2/lib/nghttp2_pq.c", - "nghttp2/lib/nghttp2_priority_spec.c", - "nghttp2/lib/nghttp2_queue.c", - "nghttp2/lib/nghttp2_rcbuf.c", - "nghttp2/lib/nghttp2_session.c", - "nghttp2/lib/nghttp2_stream.c", - "nghttp2/lib/nghttp2_submit.c", - "nghttp2/lib/nghttp2_version.c", - "nghttp2/lib/nghttp2_ratelim.c", - "nghttp2/lib/nghttp2_time.c", - ]; - + // Source files for source in SOURCES { println!("cargo:rerun-if-changed={}", source); } - // Header dependencies - const HEADERS: &[&str] = &[ - "nghttp2/lib/sfparse.h", - "nghttp2/lib/nghttp2_alpn.h", - "nghttp2/lib/nghttp2_buf.h", - "nghttp2/lib/nghttp2_callbacks.h", - "nghttp2/lib/nghttp2_debug.h", - "nghttp2/lib/nghttp2_extpri.h", - "nghttp2/lib/nghttp2_frame.h", - "nghttp2/lib/nghttp2_hd.h", - "nghttp2/lib/nghttp2_hd_huffman.h", - "nghttp2/lib/nghttp2_helper.h", - "nghttp2/lib/nghttp2_http.h", - "nghttp2/lib/nghttp2_int.h", - "nghttp2/lib/nghttp2_map.h", - "nghttp2/lib/nghttp2_mem.h", - "nghttp2/lib/nghttp2_net.h", - "nghttp2/lib/nghttp2_option.h", - "nghttp2/lib/nghttp2_outbound_item.h", - "nghttp2/lib/nghttp2_pq.h", - "nghttp2/lib/nghttp2_priority_spec.h", - "nghttp2/lib/nghttp2_queue.h", - "nghttp2/lib/nghttp2_ratelim.h", - "nghttp2/lib/nghttp2_rcbuf.h", - "nghttp2/lib/nghttp2_session.h", - "nghttp2/lib/nghttp2_stream.h", - "nghttp2/lib/nghttp2_submit.h", - "nghttp2/lib/nghttp2_time.h", - ]; - + // Header dependencies (internal) for header in HEADERS { println!("cargo:rerun-if-changed={}", header); } @@ -189,35 +189,6 @@ fn build_nghttp2(target: &str, include_dir: &Path, lib_dir: &Path) { } fn add_source_files(build: &mut cc::Build) { - const SOURCES: &[&str] = &[ - "nghttp2/lib/sfparse.c", - "nghttp2/lib/nghttp2_alpn.c", - "nghttp2/lib/nghttp2_buf.c", - "nghttp2/lib/nghttp2_callbacks.c", - "nghttp2/lib/nghttp2_debug.c", - "nghttp2/lib/nghttp2_extpri.c", - "nghttp2/lib/nghttp2_frame.c", - "nghttp2/lib/nghttp2_hd.c", - "nghttp2/lib/nghttp2_hd_huffman.c", - "nghttp2/lib/nghttp2_hd_huffman_data.c", - "nghttp2/lib/nghttp2_helper.c", - "nghttp2/lib/nghttp2_http.c", - "nghttp2/lib/nghttp2_map.c", - "nghttp2/lib/nghttp2_mem.c", - "nghttp2/lib/nghttp2_option.c", - "nghttp2/lib/nghttp2_outbound_item.c", - "nghttp2/lib/nghttp2_pq.c", - "nghttp2/lib/nghttp2_priority_spec.c", - "nghttp2/lib/nghttp2_queue.c", - "nghttp2/lib/nghttp2_rcbuf.c", - "nghttp2/lib/nghttp2_session.c", - "nghttp2/lib/nghttp2_stream.c", - "nghttp2/lib/nghttp2_submit.c", - "nghttp2/lib/nghttp2_version.c", - "nghttp2/lib/nghttp2_ratelim.c", - "nghttp2/lib/nghttp2_time.c", - ]; - for source in SOURCES { build.file(source); } From 3ef9ce80788ac5527ab6abaca58755736988734b Mon Sep 17 00:00:00 2001 From: kaju Date: Tue, 3 Mar 2026 11:09:40 +0000 Subject: [PATCH 3/3] fix: rustfmt formatting for long println --- build.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/build.rs b/build.rs index 2352ec2..2dcfe45 100644 --- a/build.rs +++ b/build.rs @@ -90,7 +90,9 @@ fn emit_rerun_if_changed() { println!("cargo:rerun-if-changed=build.rs"); // Template files - println!("cargo:rerun-if-changed=nghttp2/lib/includes/nghttp2/nghttp2ver.h.in"); + println!( + "cargo:rerun-if-changed=nghttp2/lib/includes/nghttp2/nghttp2ver.h.in" + ); println!("cargo:rerun-if-changed=nghttp2/lib/libnghttp2.pc.in"); // Header files (public)