2 ms·
You make it sound like ffi is a nasty 3 letter word ;). It look me 3 lines of code to import the dll, assign the signature and call the function, I'd hardly ca
by vvanders 9y ago
You make it sound like ffi is a nasty 3 letter word ;).
It look me 3 lines of code to import the dll, assign the signature and call the function, I'd hardly call that complex.
- mlevental 9y agothis is probably a dumb question but did you just compile the rust binary and then expose the functions? how? I don't remember but does rust face header files?
- vvanders 9y agoYup, just declare the function like so: #[no_mangle] pub unsafe extern "C" fn transform_pcm( data: *mut c_short, len: c_uint, ramp_time: c_uint, tone_delta_frame: c_float) { then call from python: gen_pcm_dll = ctypes.cdll.LoadLibrary("gen_pcm_rust/target/release/gen_pcm.dll") gen_pcm_dll.transform_pcm.argtypes = [ctypes.c_void_p, ctypes.c_uint, ctypes.c_uint, ctypes.c_float] gen_pcm_dll.transform_pcm(ptr, len(pcm), ramp_time, tone_delta_frame) Rust doesn't generate headers(although there are helper libs if you want) and you don't need them to FFI.
- the_mitsuhiko 9y agoHere is how we do it: https://blog.sentry.io/2017/11/14/evolving-our-rust-with-milksnake https://blog.sentry.io/2017/11/14/evolving-our-rust-with-mil...