Skip to content

interpreters/python: Add libffi package integration to enable Python's ctypes module #3495

Merged
xiaoxiang781216 merged 2 commits into
apache:masterfrom
tmedicci:feature/python_pip
May 22, 2026
Merged

interpreters/python: Add libffi package integration to enable Python's ctypes module #3495
xiaoxiang781216 merged 2 commits into
apache:masterfrom
tmedicci:feature/python_pip

Conversation

@tmedicci
Copy link
Copy Markdown
Contributor

Summary

  • interpreters/python: Add ctypes prototype patches for NuttX:

    • integrate NuttX-specific ctypes and posixmodule updates.
  • system/libffi: Add libffi package integration:

    • Add Kconfig, build rules, and ignore entries required to build and package libffi as a standalone system component.

Impact

Impact on user: Allow users to import the ctypes module for Python on NuttX.

Impact on build: No.

Impact on hardware: No.

Impact on documentation: No.

Impact on security: No.

Impact on compatibility: No.

Testing

rv-virt:cpython can be used to test it.

Building

make -j distclean
./tools/configure.sh -S rv-virt:python
kconfig-tweak -e FS_TMPFS
kconfig-tweak --set-val FS_HEAPSIZE 2097152
kconfig-tweak --set-val RAM_SIZE 67108864
kconfig-tweak -e LIBC_DLFCN
kconfig-tweak -e LIB_LIBFFI
kconfig-tweak -e INTERPRETERS_CPYTHON_ENABLE_PIP
make olddefconfig
make -j$(nproc)

Running

After build, run it on the generic RISC-V QEMU:

qemu-system-riscv32 -semihosting -M virt,aclint=on -cpu rv32 -smp 8 -m 128 \
   -global virtio-mmio.force-legacy=false \
   -device virtio-serial-device,bus=virtio-mmio-bus.0 \
   -chardev socket,telnet=on,host=127.0.0.1,port=3450,server=on,wait=off,id=foo \
   -device virtconsole,chardev=foo \
   -device virtio-rng-device,bus=virtio-mmio-bus.1 \
   -netdev user,id=u1,hostfwd=tcp:127.0.0.1:10023-10.0.2.15:23,hostfwd=tcp:127.0.0.1:15001-10.0.2.15:5001 \
   -device virtio-net-device,netdev=u1,bus=virtio-mmio-bus.2 \
   -drive file=./mydisk-1gb.img,if=none,format=raw,id=hd \
   -device virtio-blk-device,bus=virtio-mmio-bus.3,drive=hd \
   -bios none -kernel ./nuttx -nographic

And, then, try to import ctypes on Python and check its output result to calculate the size of a C type.

Results

 nsh> python
[    2.710000] check_and_mount_romfs: Mounting ROMFS filesystem at target=/usr/local/lib with source=/dev/ram1
Python 3.13.0 (main, May 21 2026, 16:35:39) [GCC 14.2.0] on nuttx
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
>>> x = ctypes.sizeof(ctypes.c_longlong)
>>> x
8
>>> 

tmedicci added 2 commits May 21, 2026 15:38
Add Kconfig, build rules, and ignore entries required to build and
package libffi as a standalone system component.

Signed-off-by: Tiago Medicci <tiago.medicci@espressif.com>
Integrate NuttX-specific ctypes and posixmodule updates.

Signed-off-by: Tiago Medicci <tiago.medicci@espressif.com>
@xiaoxiang781216 xiaoxiang781216 merged commit 58b780c into apache:master May 22, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants