Skip to content
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

CPython integration help needed #689

Open
tlaurion opened this issue Mar 5, 2020 · 15 comments
Open

CPython integration help needed #689

tlaurion opened this issue Mar 5, 2020 · 15 comments
Assignees

Comments

@tlaurion
Copy link
Collaborator

tlaurion commented Mar 5, 2020

Micropython would not fit the bill of wyng dependencies in the long run.

CPython could work with additional space freed with modified IFD and Neutered ME, but I would need to understand how to properly cross-compile it.

Outcome would be chipsec inclusion, wyng-backups inclusion permitting to have factory disk restore/integrity validation inside of Heads.

Linked #233

@osresearch
Copy link
Collaborator

I'm using micropython in other projects with good success, but those embedded systems don't have deep dependency trees.

I'll poke at cpython to see if there is an easy way to apply the fix from 360651

@osresearch
Copy link
Collaborator

I first build a native version for the build machine and then build a cross compiled version using the native as the $PYTHON_FOR_BUILD that appears to work in a chroot environment:

CC=$HEADS/crossgcc/bin/x86_64-linux-musl-gcc \
PYTHON_FOR_BUILD=`pwd`/../build/python \
ac_cv_file__dev_ptmx=no \
ac_cv_file__dev_ptc=no \
have_openssl=no \
../configure \
  --build x86_64-linux-musl \
  --host x86_64-linux-gnu \
  --disable-ipv6 \
  --prefix=/tmp/root/usr/local \

make "passes", although many of the extensions fail. It also appears that quite a bit of the code ends up ignoring $(CC) and building with gcc instead (all of the cpython/Modules directory?).

Another problem is that python wants openssl, which is a massive dependency.

@osresearch
Copy link
Collaborator

Yeah, the wrong compiler is definitely going to make this a mess:

~ # python
Python 3.9.0a4+ (heads/master-dirty:efc28bb, Mar  5 2020, 19:38:39) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/ctypes/__init__.py", line 7, in <module>
    from _ctypes import Union, Structure, Array
ImportError: Error loading shared library libffi.so.6: No such file or directory (needed by /usr/local/lib/python3.9/lib-dynload/_ctypes.cpython-39-x86_64-linux-gnu.so)
>>> 

@osresearch
Copy link
Collaborator

Oops, I swapped the --host and --build values. Rebuilding with this for the configuration:

CC=~/heads/install/bin/musl-gcc \
 CXX=~/heads/install/bin/musl-gcc \
READELF=~/heads/crossgcc/x86_64-linux-musl/x86_64-linux-musl/bin/readelf \
PYTHON_FOR_BUILD=`pwd`/../build/python \
ac_cv_file__dev_ptmx=no \
ac_cv_file__dev_ptc=no \
have_openssl=no \
../configure \
  --host x86_64-linux-musl \
  --build x86_64-linux-gnu \
  --disable-ipv6  \
  --prefix=/tmp/root/usr/local \

Takes forever due to warnings in Modules/unicodename_db.h, but does appear to use the correct gcc this time. However, import ctypes produces the same error, so something is still borked.

@tlaurion
Copy link
Collaborator Author

tlaurion commented Mar 9, 2020

@osresearch : Anything practical to provide here to help fix things upstream?

@osresearch
Copy link
Collaborator

I was idly wondering about building a fakeroot environment so that the build environment is "native" and doesn't have the cross compilation issues. This would mean building a bootstrap compiler to build the musl native compiler, although since we have busybox already built for musl we have most of the rest of the environment that we would need.

@tlaurion
Copy link
Collaborator Author

tlaurion commented May 4, 2020

@osresearch : ping?

@tlaurion
Copy link
Collaborator Author

Some progress upstream https://bugs.python.org/issue45881

@tlaurion
Copy link
Collaborator Author

Was able to compile. 13mb static binary unpacked and unstripped, built only when host provides the same python version, so PoC under 3.9.2

@tlaurion
Copy link
Collaborator Author

Not bad, 800k stripped cost, compressed under intrd with xz

@tlaurion
Copy link
Collaborator Author

Not bad, 800k stripped cost, compressed under intrd with xz

Well, this is just the interpreter alone. Still not bad, but still not ready, everything else is missing and a lot of errors are still happening for Modules/unicodename_db.h and some modules fail to be compiled.

Buildroot seems to be used in other cross-compiling environments https://github.com/minghuadev/minecraft-tests/blob/master/other-p2js/arm-cross-python-386/readme-buildroot-howto

@tlaurion
Copy link
Collaborator Author

tlaurion commented Sep 26, 2022

Still some issues upstream with musl-cross-make and python's assumptions, building target against host's buildstack, not defined one per environment variables, autotool config being faulty and hacks needed, pending upstream.

python/cpython#24502
python/cpython#95855

As of today with 3.9.2, python tries to link against host's libc and does not respect libc path given at configure step, resulting in build failing. Details in WiP inclusion PR at #1216 (comment)

@tlaurion
Copy link
Collaborator Author

tlaurion commented Oct 5, 2022

Opened issue python/cpython#97842

@tlaurion
Copy link
Collaborator Author

tlaurion commented Aug 25, 2023

python/cpython#107221 seem to fix triplet and libc fixation fixing python/cpython#97842

Might be time to retry!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants