Dynamic C/C++ extensions to micropython

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
wpd
Posts: 1
Joined: Fri Jan 26, 2018 6:20 pm

Dynamic C/C++ extensions to micropython

Post by wpd » Fri Jan 26, 2018 6:25 pm

Is it possible to write C/C++ extensions to micropython that can be loaded dynamically at runtime (specifically by the Linux port)? I have found documentation that shows me how to write extensions and compile them directly into the interpreter, but I would like to distribute my (cross compiled) extension package separately from the micropython interpreter baked onto my embedded Linux target. Does upip support this?

Thank you.

--wpd

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Dynamic C/C++ extensions to micropython

Post by dhylands » Fri Jan 26, 2018 6:38 pm

For linux the answer is yes. You can use FFI. There are examples of calling the C runtime library through FFI in micropython-lib.

I'd recommend that you download a copy of micropython-lib and search through for the string ffi

Having said that, the stuff in the C code will need to be independent of micropython (i.e. it won't be able to make any calls into micropython).

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

Re: Dynamic C/C++ extensions to micropython

Post by pfalcon » Fri Jan 26, 2018 6:39 pm

https://github.com/micropython/micropython/pull/1627
Does upip support this?
As such dynamic modules don't exist except as a proof of concept, upip obviously doesn't support them.
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/

stijn
Posts: 735
Joined: Thu Apr 24, 2014 9:13 am

Re: Dynamic C/C++ extensions to micropython

Post by stijn » Fri Jan 26, 2018 9:35 pm

https://github.com/stinos/micropython/c ... indows-pyd possibly in combination with https://github.com/stinos/micropython-wrap might do what you want on linux, i.e. compile and link a 'foo.so' then load it dynamically (using dlopen and the likes) upon 'import foo'. Has some disadvantages: completely different implementation from the one pfalcon mentions, not in the offical fork, apart from the Travis build it has not been used extensively on unix (but I do make very heavy use of it on windows without problems), last time I tried I couldn't get FATFS to link properly with -rdynamic.

Turbinenreiter
Posts: 288
Joined: Sun May 04, 2014 8:54 am

Re: Dynamic C/C++ extensions to micropython

Post by Turbinenreiter » Mon Jan 29, 2018 7:49 am

pfalcon wrote:
Fri Jan 26, 2018 6:39 pm
https://github.com/micropython/micropython/pull/1627
Does upip support this?
As such dynamic modules don't exist except as a proof of concept, upip obviously doesn't support them.
Ist there a roadmap or general idea what has to happen to finish this up?

Post Reply