-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
ports/libmicropython: Implement a static library "port". #5964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I should add: this is quite similar to the approach used internally in the Zephyr port, so hopefully this can also be used to simplify that port too. |
THIS IS AWESOME! Well done @jimmo !!! |
Nice! Are you going to use this for esp32-s2? |
af3d0ca
to
86f4afb
Compare
I am currently working on a MicroPython port to the SwissMicros DMCP platform (used on the DM42 calculator, as well as the upcoming DM41X and WP43S / WP43C). It's still at an early stage, but this PR really helped me a lot to get things started. Thank you! |
I have a question: Looking at the embedding example, can I override settings from mpconfigport.h in my mpconfigembed.h? It seems mpconfigport.h is parsed after mpconfigembed.h, so I cannot just #undef a setting before replacing it with my own #define. I would like to be able to do an out-of-tree build of libmicropython without having to touch anything inside the micropython directory, if possible. Edit: It should probably suffice to move the
from the beginning to the end of mpconfigport.h Edit 2: Sorry, I should have read mpconfigport.h more closely. I just found:
|
I had a play with this and it works well, but it has some limitations when it comes to extending and configuring the libmicropython.a (at least, I couldn't work out how to do what I wanted without modifying files in One thing I wanted to do was to include Also, IMO it adds an unnecessary layer of complexity having all 3 of // Type definitions for the specific machine
typedef intptr_t mp_int_t; // must be pointer size
typedef uintptr_t mp_uint_t; // must be pointer size
// Cannot include <sys/types.h>, as it may lead to symbol name clashes
#if _FILE_OFFSET_BITS == 64 && !defined(__LP64__)
typedef long long mp_off_t;
#else
typedef long mp_off_t;
#endif
// We need to provide a declaration/definition of alloca()
#ifdef __FreeBSD__
#include <stdlib.h>
#else
#include <alloca.h>
#endif which could actually be added to Then by the same token The idea with the above simplification of So then in the end In summary my suggestions would be:
|
This provides a configurable build that can be used in projects that aren't using MicroPython's build system. Also provides hooks for customisation and configuration. Update `examples/embedding` to use this.
86f4afb
to
731df92
Compare
@jimmo Is there any progress on this? |
I took a glance at this PR. The build seems to be failing due to a missing definition for Even after that fix, I get a linker failure when trying to build examples/embedding: |
@jimmo I really like this PR, any chances that it'll go mainline ^^ ? I've rebased on master and solved these issues locally and got it to work with the |
@michelhe would you mind making your changes available? Perhaps we can help to get this PR finished. |
@jimmo @jminor I have some more changes in mind that would improve this like having additional |
To anyone ending up here, there is another PR that seems less complex (though less complete?) and for now fixes the To anyone directly involved, maybe it's worth discussing pros and cons for both in view of merging either? |
Yes! Thanks @Simon-L that PR you referenced is working for me. Thank you so much for finding that. It looks like it may have been merged into the main codebase. My use case seems to be working now. This is really helpful. |
Hey, I have a problem compiling this example cyber@cyber:~/projects/jimmo-micropython/examples/embedding$ make
make[1]: Entering directory '/home/cyber/projects/jimmo-micropython/ports/libmicropython'
Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.
mkdir -p /home/cyber/projects/jimmo-micropython/examples/embedding/build-libmicropython/genhdr
GEN /home/cyber/projects/jimmo-micropython/examples/embedding/build-libmicropython/genhdr/mpversion.h
GEN /home/cyber/projects/jimmo-micropython/examples/embedding/build-libmicropython/genhdr/moduledefs.h
GEN /home/cyber/projects/jimmo-micropython/examples/embedding/build-libmicropython/genhdr/qstr.i.last
GEN /home/cyber/projects/jimmo-micropython/examples/embedding/build-libmicropython/genhdr/qstr.split
GEN /home/cyber/projects/jimmo-micropython/examples/embedding/build-libmicropython/genhdr/qstrdefs.collected.h
QSTR updated
GEN /home/cyber/projects/jimmo-micropython/examples/embedding/build-libmicropython/genhdr/qstrdefs.generated.h
mkdir -p /home/cyber/projects/jimmo-micropython/examples/embedding/build-libmicropython/extmod/
mkdir -p /home/cyber/projects/jimmo-micropython/examples/embedding/build-libmicropython/lib/embed/
mkdir -p /home/cyber/projects/jimmo-micropython/examples/embedding/build-libmicropython/lib/utils/
mkdir -p /home/cyber/projects/jimmo-micropython/examples/embedding/build-libmicropython/py/
CC ../../py/mpstate.c
CC ../../py/nlr.c
CC ../../py/nlrx86.c
CC ../../py/nlrx64.c
CC ../../py/nlrthumb.c
CC ../../py/nlrpowerpc.c
CC ../../py/nlrxtensa.c
CC ../../py/nlrsetjmp.c
CC ../../py/malloc.c
CC ../../py/gc.c
CC ../../py/pystack.c
CC ../../py/qstr.c
CC ../../py/vstr.c
CC ../../py/mpprint.c
CC ../../py/unicode.c
CC ../../py/mpz.c
CC ../../py/reader.c
CC ../../py/lexer.c
CC ../../py/parse.c
CC ../../py/scope.c
CC ../../py/compile.c
CC ../../py/emitcommon.c
CC ../../py/emitbc.c
CC ../../py/asmbase.c
CC ../../py/asmx64.c
CC ../../py/emitnx64.c
CC ../../py/asmx86.c
CC ../../py/emitnx86.c
CC ../../py/asmthumb.c
CC ../../py/emitnthumb.c
CC ../../py/emitinlinethumb.c
CC ../../py/asmarm.c
CC ../../py/emitnarm.c
CC ../../py/asmxtensa.c
CC ../../py/emitnxtensa.c
CC ../../py/emitinlinextensa.c
CC ../../py/emitnxtensawin.c
CC ../../py/formatfloat.c
CC ../../py/parsenumbase.c
CC ../../py/parsenum.c
CC ../../py/emitglue.c
CC ../../py/persistentcode.c
CC ../../py/runtime.c
CC ../../py/runtime_utils.c
CC ../../py/scheduler.c
CC ../../py/nativeglue.c
CC ../../py/pairheap.c
CC ../../py/ringbuf.c
CC ../../py/stackctrl.c
CC ../../py/argcheck.c
CC ../../py/warning.c
CC ../../py/profile.c
CC ../../py/map.c
CC ../../py/obj.c
CC ../../py/objarray.c
CC ../../py/objattrtuple.c
CC ../../py/objbool.c
CC ../../py/objboundmeth.c
CC ../../py/objcell.c
CC ../../py/objclosure.c
CC ../../py/objcomplex.c
CC ../../py/objdeque.c
CC ../../py/objdict.c
CC ../../py/objenumerate.c
CC ../../py/objexcept.c
CC ../../py/objfilter.c
CC ../../py/objfloat.c
CC ../../py/objfun.c
CC ../../py/objgenerator.c
CC ../../py/objgetitemiter.c
CC ../../py/objint.c
CC ../../py/objint_longlong.c
CC ../../py/objint_mpz.c
CC ../../py/objlist.c
CC ../../py/objmap.c
CC ../../py/objmodule.c
CC ../../py/objobject.c
CC ../../py/objpolyiter.c
CC ../../py/objproperty.c
CC ../../py/objnone.c
CC ../../py/objnamedtuple.c
CC ../../py/objrange.c
CC ../../py/objreversed.c
CC ../../py/objset.c
CC ../../py/objsingleton.c
CC ../../py/objslice.c
CC ../../py/objstr.c
CC ../../py/objstrunicode.c
CC ../../py/objstringio.c
CC ../../py/objtuple.c
CC ../../py/objtype.c
CC ../../py/objzip.c
CC ../../py/opmethods.c
CC ../../py/sequence.c
CC ../../py/stream.c
CC ../../py/binary.c
CC ../../py/builtinimport.c
CC ../../py/builtinevex.c
CC ../../py/builtinhelp.c
CC ../../py/modarray.c
CC ../../py/modbuiltins.c
CC ../../py/modcollections.c
CC ../../py/modgc.c
CC ../../py/modio.c
CC ../../py/modmath.c
CC ../../py/modcmath.c
CC ../../py/modmicropython.c
CC ../../py/modstruct.c
CC ../../py/modsys.c
CC ../../py/moduerrno.c
CC ../../py/modthread.c
CC ../../py/vm.c
CC ../../py/bc.c
CC ../../py/showbc.c
CC ../../py/repl.c
CC ../../py/smallint.c
CC ../../py/frozenmod.c
CC ../../extmod/moduasyncio.c
CC ../../extmod/moductypes.c
CC ../../extmod/modujson.c
CC ../../extmod/modure.c
CC ../../extmod/moduzlib.c
CC ../../extmod/moduheapq.c
CC ../../extmod/modutimeq.c
CC ../../extmod/moduhashlib.c
CC ../../extmod/moducryptolib.c
CC ../../extmod/modubinascii.c
CC ../../extmod/virtpin.c
CC ../../extmod/machine_mem.c
CC ../../extmod/machine_pinbase.c
CC ../../extmod/machine_signal.c
CC ../../extmod/machine_pulse.c
CC ../../extmod/machine_i2c.c
CC ../../extmod/machine_spi.c
CC ../../extmod/modbluetooth.c
CC ../../extmod/modussl_axtls.c
CC ../../extmod/modussl_mbedtls.c
CC ../../extmod/modurandom.c
CC ../../extmod/moduselect.c
CC ../../extmod/moduwebsocket.c
CC ../../extmod/modwebrepl.c
CC ../../extmod/modframebuf.c
CC ../../extmod/vfs.c
CC ../../extmod/vfs_blockdev.c
CC ../../extmod/vfs_reader.c
CC ../../extmod/vfs_posix.c
CC ../../extmod/vfs_posix_file.c
In file included from ../../extmod/vfs_posix_file.c:27:
../../py/mphal.h:38:1: error: unknown type name ‘uintptr_t’
38 | uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags);
| ^~~~~~~~~
../../py/mphal.h:38:29: error: unknown type name ‘uintptr_t’
38 | uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags);
| ^~~~~~~~~
make[1]: *** [../../py/mkrules.mk:63: /home/cyber/projects/jimmo-micropython/examples/embedding/build-libmicropython/extmod/vfs_posix_file.o] Error 1
make[1]: Leaving directory '/home/cyber/projects/jimmo-micropython/ports/libmicropython'
make: *** [Makefile:37: /home/cyber/projects/jimmo-micropython/examples/embedding/build-libmicropython/libmicropython.a] Error 2 |
@cyberuser-black - Were you able to resolve this? |
added GPIO40 pin to esp32s3 devkit boards (Closes micropython#5964)
Closed in favour of #9529 We might consider adding a way to generate a .a file from the |
This is to facilitate embedding MicroPython in third-party build systems or larger projects.
Two main changes:
The examples/embedding demo has been a bit of a stumbling block and comes up occasionally on the forums (it also currently doesn't compile). I don't feel that what's currently there is particularly useful to people as a "here's how to embed micropython" demo as there's far too much stuff going on and it's not clear which part is the demo and which part is libmicropython. And the dependence on the Unix port means that it's not at all useful to people wanting to embed anywhere else (i.e. other RTOS).
My goal here is that someone could embed MicroPython without really knowing much at all about how Make works (or the MicroPython build system).
I hope that this will also be useful for ports as well as embedding. I think we could almost use this as-is for a few of our ports (especially the simpler ones like samd and mimxrt). And it could also be used to vastly simplify the ESP32 port.
There's a few loose ends here (mostly marked as TODOs) but I'd like to leave them for future PRs, but these are all things that weren't addressed at all in the previous example.
Also adds building examples/embedding to travis.