whentze / louis-sys

Rust bindings to liblouis (low-level crate)
GNU Lesser General Public License v3.0
1 stars 0 forks source link

Status of liblouis Rust bindings #1

Open egli opened 6 years ago

egli commented 6 years ago

Hi Whentze

I'm one of the maintainers of liblouis. For quite some time I've been pondering the idea to replace parts of the crufty liblouis C code with Rust. As a proof-of-concept I wanted to rewrite some of the tools in Rust. That's when I discovered your louis-sys Rust liblouis bindings.

What is the status of these bindings? They look fairly complete, are they?. Are you using them somewhere? You say they are low-level. Will you also create high-level bindings?

On a more meta level: Is it even a good idea to add Rust to the mix? At the moment liblouis is so bare bones when it comes to dependencies that it basically runs on anything (from embed to desktop) and that is a good thing that I don't want to change.

Thanks Christian

whentze commented 6 years ago

Hi!

This crate consists of automatically generated bindings that I made using "bindgen". They are low-level in the sense that:

  1. The entire API basically mirrors the C API 1:1.
  2. All functions are marked "unsafe". They are complete in the sense that they can do exactly everything that you can do from C using liblouis.h. I am not using them yet, as I plan to write the high-level bindings first. High-level bindings would mean, among other things:
    • A (mostly) safe API
    • Using native Rust types instead of C FFI types, for example having functions that return Result<T,E> instead of reporting errors via error codes or out-of-band via logging.
    • Nicely handling encoding to and from UTF-8 for the user. Rust uses UTF8 pretty much universally, so it's a requirement for an ergonomic API. However, most liblouis builds use, as far as I can tell, UTF-16 or UTF-32. Making nice high-level bindings involves much more work than these low-level ones, which are basically free. So far I pretty much just pointed bindgen at it and then wrote some very basic tests to confirm the bindings work.

Regarding the meta-question: I think adding Rust code to liblouis is definitely worth a consideration. However, this depends on what kind of platforms you're targeting. rustc supports many target platforms, but not as many as GCC. There is good upstream support for every major OS, i.e. Windows, MacOS, Linux, iOS and Android. More niche Unixen such as the BSDs, Solaris, Haiku etc. are supported as well but do not receive as much attention. Rust also builds for a couple of embedded targets, but this is mostly limited to various flavors of ARM and TI MSP430 microcontrollers. If you want to build for AVR, you need an out-of-tree compiler while other ISAs such as XTensa or Blackfin are not supported at all so far. If you want to support those platforms, I think you should hold off until Rust adds support for them.

egli commented 6 years ago

Hi

This all sounds very exciting! I would love to see high-level bindings. Do have any idea when you'd work on those?

this depends on what kind of platforms you're targeting

I myself use liblouis on a server, but I believe there are people that use it in embossers or in handheld devices such as braille displays or Android tablets. I do not know for sure on what devices it is used on but I suspect it would be more beefy that a microcontroller. I cannot imagine anyone would want to use liblouis on a device that doesn't have a file system.

In an ideal world we would port all of liblouis over to Rust. Then we'd have a decent standard lib to work with, no more cross platform hassles and no more CVEs to deal with. But in reality this is probably more work than I have time for.

I was going to experiment with porting one of the tools (lou_maketable) which is ATM a mix of C, Makefile and Python over to Rust to get a feel for the language and the feasibility of this idea. But for that I need bindings :-)