FFI bindings generator from library header files

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

FFI bindings generator from library header files

Post by pfalcon » Thu Jul 03, 2014 11:09 pm

https://github.com/pfalcon/micropython-ffigen

This opens possibility for easy integration with any third-party library, without writing and compiling any C code. This mostly applies to "unix" port (but there's no reason why this can't apply to baremetal ports, except for their lack of resources to host such "third-party libraries").
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: FFI bindings generator from library header files

Post by pfalcon » Sat Mar 14, 2015 10:12 pm

The tool has been updated for latest version of MicroPython.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

SpotlightKid
Posts: 463
Joined: Wed Apr 08, 2015 5:19 am

Re: FFI bindings generator from library header files

Post by SpotlightKid » Fri Nov 20, 2015 12:47 pm

How do you use it? It seems to try to load some JSON file. Where is that supposed to come from? From c2ffi?

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: FFI bindings generator from library header files

Post by pfalcon » Fri Nov 20, 2015 1:33 pm

Yup. Improvements to documentation welcome.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

SpotlightKid
Posts: 463
Joined: Wed Apr 08, 2015 5:19 am

Re: FFI bindings generator from library header files

Post by SpotlightKid » Fri Nov 20, 2015 2:59 pm

I wanted to evaluate this tool, but I'm having trouble getting c2ffi compiled, since there is no package for it in Arch (or AUR). Arch only has llvm 3.5 or 3.7 and c2ffi only claims support for llvm 3.6 and the llvm-3.5 branch mentioned does not exist.

With llvm 3.5 installed, c2ffi's configure output gives this error:

Code: Select all

checking for llvm >= 3.5... yes
checking clang/Frontend/CompilerInstance.h usability... no
checking clang/Frontend/CompilerInstance.h presence... yes
configure: WARNING: clang/Frontend/CompilerInstance.h: present but cannot be compiled
configure: WARNING: clang/Frontend/CompilerInstance.h:     check for missing prerequisite headers?
configure: WARNING: clang/Frontend/CompilerInstance.h: see the Autoconf documentation
configure: WARNING: clang/Frontend/CompilerInstance.h:     section "Present But Cannot Be Compiled"
configure: WARNING: clang/Frontend/CompilerInstance.h: proceeding with the compiler's result
checking for clang/Frontend/CompilerInstance.h... no
configure: error: clang development libs not found
When I install clanng-3.5 instead, configure immediately bails out with

Code: Select all

configure: error: C compiler cannot create executables
and looking at 'config.log' the cause of this is "clang: error: unknown argument: '-fstack-check'". So neither clang-3.7 nor clang-3.5 work :(

With llvm 3.7 I get the error reported here: https://github.com/rpav/c2ffi/issues/22.

So c2ffi does not work with clang-3.7 yet. Any other options left to me now except waiting for it to get fixed?

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: FFI bindings generator from library header files

Post by pfalcon » Tue Dec 15, 2015 1:55 pm

SpotlightKid, LLVM/Clang is notorious for breaking compatibility with each new release. Most serious Linux distros figured a way to address that: e.g. Debian/Ubuntu provide llvm-3.3, llvm-3.4, llvm-3.5, ... etc. package which can be installed in parallel, and newer version doesn't replace older.

So yes, the most obvious way is to build c2ffi with exact version documented. Even better way is to port it to newer version and contribute changes to c2ffi project (I did that when I hacked on it, it was llvm 3.5 at that time IIRC).

In either case, issues with c2ffi should be reported to its bug tracker on github.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

SpotlightKid
Posts: 463
Joined: Wed Apr 08, 2015 5:19 am

Re: FFI bindings generator from library header files

Post by SpotlightKid » Tue Dec 15, 2015 2:56 pm

So it seems that I would have to compile clang 3.6 manually. I think I'll just wait...

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: FFI bindings generator from library header files

Post by pfalcon » Tue Dec 15, 2015 4:17 pm

Btw, http://forum.micropython.org/viewtopic. ... 221&p=7571 ended up approaching Clang for a slightly different problem (but they both are quite similar of course).
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

Post Reply