Skip to content

Commit a8d28e3

Browse files
committed
Add a check for 32bit Windows to target nightly Rust.
Previously, compiling with non-nightly Rust meant 32bit Windows would fail to generate bindings - bindgen will not use the "thiscall" ABI unless using nightly Rust. The bindings would therefore have (almost) nothing in them, so any calls would fail. Now at least there will be a warning, and if using nightly Rust, this will work!
1 parent 8cde811 commit a8d28e3

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

build.rs

+24-2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ fn is_debug() -> bool {
4545
env::var("DEBUG").unwrap() == "true"
4646
}
4747

48+
fn is_32_bit() -> bool {
49+
env::var("TARGET")
50+
.expect("TARGET should be provided by Cargo.")
51+
.contains("i686")
52+
}
53+
54+
fn is_nightly() -> bool {
55+
env::var("RUSTUP_TOOLCHAIN")
56+
.expect("RUSTUP_TOOLCHAIN should be provided by Cargo.")
57+
.starts_with("nightly")
58+
}
59+
4860
fn lib_names() -> Vec<String> {
4961
let mut root_names = Vec::new();
5062
#[cfg(feature = "recast")]
@@ -175,7 +187,7 @@ fn generate_recast_bindings(
175187
add_to_builder: impl Fn(bindgen::Builder) -> bindgen::Builder,
176188
out_file: PathBuf,
177189
) {
178-
let builder = bindgen::Builder::default()
190+
let mut builder = bindgen::Builder::default()
179191
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
180192
.clang_args(["-x", "c++"].iter())
181193
.clang_args(
@@ -190,8 +202,18 @@ fn generate_recast_bindings(
190202
.blocklist_file(".*stddef\\.h")
191203
.blocklist_type("max_align_t");
192204

205+
if is_windows() && is_32_bit() {
206+
if is_nightly() {
207+
builder = builder.rust_target(bindgen::RustTarget::Nightly);
208+
} else {
209+
println!("cargo:warning=Windows 32 bit uses the \"thiscall\" ABI. This feature is not enabled, so compilation may fail!");
210+
}
211+
}
212+
193213
#[cfg(feature = "detour_large_nav_meshes")]
194-
let builder = builder.clang_args(["-DDT_POLYREF64"]);
214+
{
215+
builder = builder.clang_args(["-DDT_POLYREF64"]);
216+
}
195217

196218
let bindings =
197219
add_to_builder(builder).generate().expect("Unable to generate bindings.");

0 commit comments

Comments
 (0)