Open tlaurion opened 4 years ago
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
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.
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)
>>>
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.
@osresearch : Anything practical to provide here to help fix things upstream?
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.
@osresearch : ping?
Some progress upstream https://bugs.python.org/issue45881
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
Not bad, 800k stripped cost, compressed under intrd with xz
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
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.
https://github.com/python/cpython/pull/24502 https://github.com/python/cpython/issues/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 https://github.com/osresearch/heads/pull/1216#issuecomment-1254244551
Seems like the following might fix the problem and OpenWrt is a good source for those kind of issues
Opened issue https://github.com/python/cpython/issues/97842
https://github.com/python/cpython/pull/107221 seem to fix triplet and libc fixation fixing https://github.com/python/cpython/issues/97842
Might be time to retry!
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