Skip to content

Commit 713023c

Browse files
committed
fix build on Windows
1 parent 096df8d commit 713023c

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

build.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,28 @@ fn generate_pkgconfig(
175175

176176
fn generate_bindings(out_dir: &Path, include_dir: &Path) {
177177
let header_path = include_dir.join("nghttp2/nghttp2.h");
178+
let target = env::var("TARGET").expect("TARGET not set");
178179

179-
let bindings = bindgen::Builder::default()
180+
let mut builder = bindgen::Builder::default()
180181
.header(header_path.to_str().unwrap())
181182
.clang_arg(format!("-I{}", include_dir.display()))
182-
.clang_arg("-Inghttp2/lib/includes")
183+
.clang_arg("-Inghttp2/lib/includes");
184+
185+
// On Windows MSVC, define ssize_t for clang/bindgen
186+
if target.contains("windows") && target.contains("msvc") {
187+
let pointer_width = env::var("CARGO_CFG_TARGET_POINTER_WIDTH")
188+
.expect("CARGO_CFG_TARGET_POINTER_WIDTH not set");
189+
190+
let ssize_t_def = match pointer_width.as_str() {
191+
"64" => "ssize_t=long long",
192+
"32" => "ssize_t=long",
193+
width => panic!("Unsupported pointer width: {}", width),
194+
};
195+
196+
builder = builder.clang_arg(format!("-D{}", ssize_t_def));
197+
}
198+
199+
let bindings = builder
183200
// Only include nghttp2 symbols
184201
.allowlist_function("nghttp2_.*")
185202
.allowlist_type("nghttp2_.*")

0 commit comments

Comments
 (0)