jean-pierreBoth / hnswlib-rs

Rust implementation of the HNSW algorithm (Malkov-Yashunin)
Other
158 stars 21 forks source link

Fix build failure on Windows 11 #8

Closed ruqqq closed 1 year ago

ruqqq commented 1 year ago

While building on x64 windows 11, with x86_64 stable rust, met with an error related to trying to fit a u64 into u32. Fixed by changing the types to use c_ulong instead of u64.

jean-pierreBoth commented 1 year ago

It seems it could be c_ulonglong see rustdoc to have a chance to run as it needs to be a 64 bit integer

ruqqq commented 1 year ago

Make sense, made the change. Will be testing the integration with my app to confirm it works.

jianshu93 commented 1 year ago

Hello All,

I have exactly the same problem with cross compiling using cargo-xwin:

error[E0308]: mismatched types --> /Users/jianshuzhao/Github/hnswlib-rs/src/libext.rs:439:39 439 let c_dist = DistCFFI::::new(c_func); -------------------- ^^^^^^ expected u32, found u64
arguments to this function are incorrect
= note: expected fn pointer `extern "C" fn(_, _, u32) -> _`
           found fn pointer `extern "C" fn(_, _, u64) -> _`

note: associated function defined here --> /Users/jianshuzhao/Github/hnswlib-rs/src/dist.rs:990:12 | 990 | pub fn new(f:DistCFnPtr) -> Self { | ^^^ ---------------

error[E0308]: mismatched types --> /Users/jianshuzhao/Github/hnswlib-rs/src/libext.rs:570:39 570 let c_dist = DistCFFI::::new(c_func); -------------------- ^^^^^^ expected u32, found u64
arguments to this function are incorrect
= note: expected fn pointer `extern "C" fn(_, _, u32) -> _`
           found fn pointer `extern "C" fn(_, _, u64) -> _`

note: associated function defined here --> /Users/jianshuzhao/Github/hnswlib-rs/src/dist.rs:990:12 | 990 | pub fn new(f:DistCFnPtr) -> Self { | ^^^ ---------------

error[E0308]: mismatched types --> /Users/jianshuzhao/Github/hnswlib-rs/src/libext.rs:629:39 629 let c_dist = DistCFFI::::new(c_func); -------------------- ^^^^^^ expected u32, found u64
arguments to this function are incorrect
= note: expected fn pointer `extern "C" fn(_, _, u32) -> _`
           found fn pointer `extern "C" fn(_, _, u64) -> _`

note: associated function defined here --> /Users/jianshuzhao/Github/hnswlib-rs/src/dist.rs:990:12 | 990 | pub fn new(f:DistCFnPtr) -> Self { | ^^^ ---------------

error[E0308]: mismatched types --> /Users/jianshuzhao/Github/hnswlib-rs/src/libext.rs:729:39 729 let c_dist = DistCFFI::::new(c_func); -------------------- ^^^^^^ expected u32, found u64
arguments to this function are incorrect
= note: expected fn pointer `extern "C" fn(_, _, u32) -> _`
           found fn pointer `extern "C" fn(_, _, u64) -> _`

note: associated function defined here --> /Users/jianshuzhao/Github/hnswlib-rs/src/dist.rs:990:12 | 990 | pub fn new(f:DistCFnPtr) -> Self { | ^^^ ---------------

error[E0308]: mismatched types --> /Users/jianshuzhao/Github/hnswlib-rs/src/libext.rs:786:38 786 let c_dist = DistCFFI::::new(c_func); ------------------- ^^^^^^ expected u32, found u64
arguments to this function are incorrect
= note: expected fn pointer `extern "C" fn(_, _, u32) -> _`
           found fn pointer `extern "C" fn(_, _, u64) -> _`

note: associated function defined here --> /Users/jianshuzhao/Github/hnswlib-rs/src/dist.rs:990:12 | 990 | pub fn new(f:DistCFnPtr) -> Self { | ^^^ ---------------

For more information about this error, try rustc --explain E0308. error: could not compile hnsw_rs (lib) due to 5 previous errors warning: build failed, waiting for other jobs to finish...

I think this commit solved the problem, at least for cross compiling. I can now provide windows exe binary files for rust programs!!

Thanks,

Jianshu

jean-pierreBoth commented 1 year ago

merged