[libcamera-devel] Rustlang bindings
Jurgis Balciunas
chemicstry at gmail.com
Mon Nov 21 16:27:14 CET 2022
Hello everyone,
I'm not used to mailing lists and patchwork process so pardon me if I'm
writing this at the wrong place.
I've been working on Rust bindings for the libcamera and wanted to let
everyone know in case someone would be interested. So far I've gotten as
far as capturing JPEG image from webcam entirely in safe Rust and I think
this already covers ~70% of libcamera API. The wrapper library is currently
published at https://github.com/lit-robotics/libcamera-rs. It consists of 2
main parts: libcamera-sys, which contains raw unsafe bindings to libcamera
and libcamera-rs, which implements a higher-level memory-safe API on top of
libcamera-sys.
The most difficult part was C++ not being FFI friendly and most of the
automatic binding generation tools break with complex C++ codebases,
especially when templates are used. So instead I've written a thin C
wrapper around libcamera (under libcamera-sys/c_api
<https://github.com/lit-robotics/libcamera-rs/tree/main/libcamera-sys/c_api>),
which was used to autogenerate libcamera-sys. We had a discussion in
https://github.com/kbingham/libcamera/issues/58 that this C wrapper could
be useful not only for Rust bindings, but I'm personally not sure about any
uses outside FFI? If it were a part of libcamera, the difficult part would
be maintaining documentation as the C API does not map 1:1 with C++,
especially anything related to STL containers.
Anyway, there is quite a lot to these bindings (~5k LoC excluding the
auto-generated stuff) and too many design decisions to explain in this
introductory email. I'm happy to answer any questions instead.
Regards,
Jurgis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.libcamera.org/pipermail/libcamera-devel/attachments/20221121/0c962722/attachment.htm>
More information about the libcamera-devel
mailing list