Page 1 of 1
Dynamic C/C++ extensions to micropython
Posted: Fri Jan 26, 2018 6:25 pm
by wpd
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
Re: Dynamic C/C++ extensions to micropython
Posted: Fri Jan 26, 2018 6:38 pm
by dhylands
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).
Re: Dynamic C/C++ extensions to micropython
Posted: Fri Jan 26, 2018 6:39 pm
by pfalcon
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.
Re: Dynamic C/C++ extensions to micropython
Posted: Fri Jan 26, 2018 9:35 pm
by stijn
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.
Re: Dynamic C/C++ extensions to micropython
Posted: Mon Jan 29, 2018 7:49 am
by Turbinenreiter
Ist there a roadmap or general idea what has to happen to finish this up?