[libcamera-devel] Rustlang bindings
Kieran Bingham
kieran.bingham at ideasonboard.com
Mon Nov 21 16:58:30 CET 2022
Hi Jurgis,
Quoting Jurgis Balciunas via libcamera-devel (2022-11-21 15:27:14)
> Hello everyone,
Welcome to libcamera. And thanks for diving in!
> I'm not used to mailing lists and patchwork process so pardon me if I'm
> writing this at the wrong place.
Entirely correct, don't worry.
> 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
\o/
> 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
C-bindings will be useful else where indeed. Either for other language
bindings, (Anyone going to work on Go next ?) or just to expose a direct
C api.
> be maintaining documentation as the C API does not map 1:1 with C++,
> especially anything related to STL containers.
Yes, we'll have to figure out how to document the C API potentially
alongside the C++ API.
Ideally, we'd continue our doxygen integration there.
> 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.
Well the next questions will be - what should our next steps be to
getting your work integrated.
Ideally, we would like contributors to have read:
- https://libcamera.org/contributing.html
- https://libcamera.org/coding-style.html#coding-style-guidelines
and have the checkstyle hooks added to their repository:
cp utils/hooks/post-commit .git/hooks/post-commit
And have clean commits that we can review on list. I anticipate getting
the full c-bindings merged may be a fair bit of work - so do let us know
if there's anything that we can do to help or support you.
I would anticpate that the rust bindings would live in the libcamera
repostiory as well as the c-bindings. Is that how other rust projects
work?
Are you happy for this work to live in the libcamera upstream
repositories? If it's upstream we can expect to maintain it and validate
it against any ABI/API changes. I might need some help setting up extra
automation and testing to make sure the rust bindings are functional...
(I've got extremely little rust experience).
--
Kieran
>
> Regards,
> Jurgis
More information about the libcamera-devel
mailing list