Skip to content

Commit 3dae4bf

Browse files
committed
fix(rust): Fix Rust bindings compilation on Windows
- Fix formatting issues (trailing spaces in doc comments) - Fix Windows MSVC linker errors by: * Always compiling ccap_convert_neon.cpp (provides hasNEON() symbol) * Using MSVC-compatible flags (/arch:AVX2) for AVX2 builds * Removing -mavx2/-mfma flags that are GCC/Clang specific The hasNEON() function is needed on all platforms (returns false on non-ARM). Previously it was only compiled on aarch64, causing undefined symbol errors on Windows x86_64.
1 parent 1f01fe6 commit 3dae4bf

2 files changed

Lines changed: 28 additions & 11 deletions

File tree

bindings/rust/build.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,37 @@ fn main() {
9090
.include(ccap_root.join("include"))
9191
.include(ccap_root.join("src"))
9292
.cpp(true)
93-
.std("c++17")
94-
.flag("-mavx2")
95-
.flag("-mfma")
96-
.compile("ccap_avx2");
93+
.std("c++17");
94+
95+
// Only add SIMD flags on non-MSVC compilers
96+
if !avx2_build.get_compiler().is_like_msvc() {
97+
avx2_build.flag("-mavx2").flag("-mfma");
98+
} else {
99+
// MSVC uses /arch:AVX2
100+
avx2_build.flag("/arch:AVX2");
101+
}
102+
103+
avx2_build.compile("ccap_avx2");
97104
}
98105

99-
#[cfg(target_arch = "aarch64")]
106+
// Always build neon file for hasNEON() symbol
107+
// On non-ARM architectures, ENABLE_NEON_IMP will be 0 and function returns false
100108
{
101109
let mut neon_build = cc::Build::new();
102110
neon_build
103111
.file(ccap_root.join("src/ccap_convert_neon.cpp"))
104112
.include(ccap_root.join("include"))
105113
.include(ccap_root.join("src"))
106114
.cpp(true)
107-
.std("c++17")
108-
.compile("ccap_neon");
115+
.std("c++17");
116+
117+
// Only add NEON flags on aarch64
118+
#[cfg(target_arch = "aarch64")]
119+
{
120+
// NEON is always available on aarch64, no special flags needed
121+
}
122+
123+
neon_build.compile("ccap_neon");
109124
}
110125

111126
println!("cargo:warning=Building ccap from source...");

bindings/rust/src/provider.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,13 @@ impl Provider {
328328
}
329329

330330
/// Set error callback for camera errors
331-
///
331+
///
332332
/// # Memory Safety
333-
///
333+
///
334334
/// This is a **global** callback that persists for the lifetime of the program.
335335
/// The callback memory is intentionally leaked as it's meant to be set once
336336
/// and used throughout the application lifetime.
337-
///
337+
///
338338
/// If you need to change or remove the callback, consider using instance-level
339339
/// callbacks via `set_new_frame_callback` instead.
340340
pub fn set_error_callback<F>(callback: F)
@@ -453,7 +453,9 @@ impl Provider {
453453
unsafe {
454454
let _ = Box::from_raw(callback_ptr);
455455
}
456-
Err(CcapError::InvalidParameter("Failed to set frame callback".to_string()))
456+
Err(CcapError::InvalidParameter(
457+
"Failed to set frame callback".to_string(),
458+
))
457459
}
458460
}
459461

0 commit comments

Comments
 (0)