Can't build user C modules with new versions of Micropython?

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
chibill
Posts: 47
Joined: Thu Oct 31, 2019 10:44 pm

Can't build user C modules with new versions of Micropython?

Post by chibill » Tue Mar 30, 2021 7:07 pm

I am trying to write some C modules (actually c++ but want to make sure i can compile them at all first) but I can't seem to enable them.

I am running

Code: Select all

make USER_C_MODULES=../../examples/usercmodule/ CFLAGS_EXTRA=-DMODULE_CEXAMPLE_ENABLED=1
to compile it but I can't see anywhere that it actually attempted to do anything with the module at all.

Using the latest master branch as of commit 5976ea02a50ea76d72ada40db4cda186147fb412 and IDF 4.2, I am building the ESP32 port following the readme inside that ports folder as normal, where I compile by running make after setting up the tools.

But when looking at the terminal output it seems like its using make to like run cmake then run that new make file or something, sort of wacky. If this changed so drastically can the documentation be updated to show how to properly build micropython for ESP32 and also build and use C modules?

I say how to properly build micropython for ESP32 because I know for sure if this was just using cmake you wouldn't be using a make file to run cmake to then run a make again.

chibill
Posts: 47
Joined: Thu Oct 31, 2019 10:44 pm

Re: Can't build user C modules with new versions of Micropython?

Post by chibill » Tue Mar 30, 2021 7:16 pm

Also if its not possible to do now with what ever crazy new system the make build command is running would I be better off modifying the port's files directly instead of as a usermodule? (Like move my files into the ports folder then modify its build scripts to include my code.)

marcidy
Posts: 133
Joined: Sat Dec 12, 2020 11:07 pm

Re: Can't build user C modules with new versions of Micropython?

Post by marcidy » Wed Mar 31, 2021 3:04 am

Did you read the sticky thread about this?

I appreciate build systems can be frustrating, but calling the idf a weird command is a bit much, it's the official esp-idf build system entry point. We're better off being able to use it than not, and that work is very much appreciated.

chibill
Posts: 47
Joined: Thu Oct 31, 2019 10:44 pm

Re: Can't build user C modules with new versions of Micropython?

Post by chibill » Thu Apr 01, 2021 3:37 pm

I haven't even touched the idf command. Just using make like the readme says.

chibill
Posts: 47
Joined: Thu Oct 31, 2019 10:44 pm

Re: Can't build user C modules with new versions of Micropython?

Post by chibill » Fri Apr 02, 2021 2:03 am

Also even with the latest pushes as of April 1st I am still unable to build user c modules, can't even build the examples, instead I get a cmake error about being unable to load the cmake files from the examples folders.

marcidy
Posts: 133
Joined: Sat Dec 12, 2020 11:07 pm

Re: Can't build user C modules with new versions of Micropython?

Post by marcidy » Sat Apr 03, 2021 4:23 am

try using the full path to the cmake file, as noted in the PR.

Code: Select all

micropython/ports/esp32$ make USER_C_MODULES=/full/path/to/micropython/examples/usercmodule/micropthon.cmake
I just did it, and the cexample worked fine for me. make sure you make clean / idf.py fullclean and remove the build directories to be sure you have a clean starting directory.

Code: Select all

>>> import cexample
>>> cexample.
__class__       __name__        add_ints
>>> cexample.add_ints(1, 3)
4
>>> 

chibill
Posts: 47
Joined: Thu Oct 31, 2019 10:44 pm

Re: Can't build user C modules with new versions of Micropython?

Post by chibill » Mon Apr 05, 2021 4:39 pm

Found out the issue, turns out what every build system change happened also changed the starting path for relative paths in that C modules list to no longer start where the command is ran but in one folder higher, unlike how it was before.


Now time to do battle with trying to get CPP templates playing nicely with a user module again, because even having a CPP function breaking up the call to functions and stuff that use templating still causes linking issues.

Post Reply