diff --git a/Makefile b/Makefile index 34e284798..29bfe497e 100644 --- a/Makefile +++ b/Makefile @@ -459,6 +459,7 @@ bin_modules-$(CONFIG_HOTPKEY) += hotp-verification bin_modules-$(CONFIG_MSRTOOLS) += msrtools bin_modules-$(CONFIG_NKSTORECLI) += nkstorecli bin_modules-$(CONFIG_UTIL_LINUX) += util-linux +bin_modules-$(CONFIG_PYTHON) += python $(foreach m, $(bin_modules-y), \ $(call map,initrd_bin_add,$(call bins,$m)) \ diff --git a/boards/x230-hotp-maximized/x230-hotp-maximized.config b/boards/x230-hotp-maximized/x230-hotp-maximized.config index a7226da29..21c92be65 100644 --- a/boards/x230-hotp-maximized/x230-hotp-maximized.config +++ b/boards/x230-hotp-maximized/x230-hotp-maximized.config @@ -51,6 +51,7 @@ CONFIG_FBWHIPTAIL=y #Additional tools: #SSH server (requires ethernet drivers, eg: CONFIG_LINUX_E1000E) CONFIG_DROPBEAR=y +CONFIG_PYTHON=y export CONFIG_BOOTSCRIPT=/bin/gui-init export CONFIG_BOOT_REQ_HASH=n diff --git a/modules/python b/modules/python new file mode 100644 index 000000000..ba175fac9 --- /dev/null +++ b/modules/python @@ -0,0 +1,48 @@ +modules-$(CONFIG_PYTHON) += python + +python_depends := $(musl_dep) + +python_version := 3.9.2 +python_dir := python-$(python_version) +python_tar := Python-$(python_version).tar.xz +python_url := https://www.python.org/ftp/python/$(python_version)/$(python_tar) +python_hash := 3c2034c54f811448f516668dce09d24008a0716c3a794dd8639b5388cbde247d + +# Use an empty prefix so that the executables will not include the +# build path. +python_configure := \ + PKG_CONFIG="/bin/false" \ + READELF="$(CROSS)readelf" \ + ac_cv_file__dev_ptmx=no \ + ac_cv_file__dev_ptc=no \ + have_openssl=no \ + CFLAGS="-Os" \ + CC="$(CROSS)gcc \ + -D__MUSL__ \ + -isystem $(INSTALL)/include \ + -L$(INSTALL)/lib" \ + $(CROSS_TOOLS_NOCC) \ + ./configure \ + --enable-optimizations \ + --with-cxx-main=$(CROSS)gcc \ + --with-libc="$(musl-cross_libraries)" \ + --host $(MUSL_ARCH)-linux-musl \ + --build $(MUSL_ARCH) \ + --disable-ipv6 \ + --prefix="" \ + --exec-prefix="" \ + +# but after building, replace prefix so that they will be installed +# in the correct directory. +python_target := \ + $(MAKE_JOBS) \ + && $(MAKE) \ + CC="$(heads_cc)" \ + -C $(build)/$(python_dir) \ + prefix="$(INSTALL)" \ + DESTDIR="$(INSTALL)" \ + install + +python_output := \ + python \ + diff --git a/patches/python-3.9.2/001-use-env-cc-first.patch b/patches/python-3.9.2/001-use-env-cc-first.patch new file mode 100644 index 000000000..862bd3500 --- /dev/null +++ b/patches/python-3.9.2/001-use-env-cc-first.patch @@ -0,0 +1,92 @@ +From cd6d2577fadc4cc0275017f27f46b0a628216353 Mon Sep 17 00:00:00 2001 +From: Christian Heimes +Date: Thu, 25 Nov 2021 21:53:14 +0200 +Subject: [PATCH] [3.9] bpo-45881: Use CC from env first for cross building + (GH-29752) (GH-29754) + +Co-authored-by: Christian Heimes . +Co-authored-by: Christian Heimes +--- + .../2021-11-24-17-14-06.bpo-45881.GTXXLk.rst | 2 ++ + setup.py | 16 ++++++++-------- + 2 files changed, 10 insertions(+), 8 deletions(-) + create mode 100644 Misc/NEWS.d/next/Build/2021-11-24-17-14-06.bpo-45881.GTXXLk.rst + +diff --git a/Misc/NEWS.d/next/Build/2021-11-24-17-14-06.bpo-45881.GTXXLk.rst b/Misc/NEWS.d/next/Build/2021-11-24-17-14-06.bpo-45881.GTXXLk.rst +new file mode 100644 +index 000000000000..b697658cf3aa +--- /dev/null ++++ b/Misc/NEWS.d/next/Build/2021-11-24-17-14-06.bpo-45881.GTXXLk.rst +@@ -0,0 +1,2 @@ ++``setup.py`` now uses ``CC`` from environment first to discover multiarch ++and cross compile paths. +diff --git a/setup.py b/setup.py +index 9a5887b59ffc..c6023e1ab635 100644 +--- a/setup.py ++++ b/setup.py +@@ -65,6 +65,9 @@ def get_platform(): + MACOS = (HOST_PLATFORM == 'darwin') + AIX = (HOST_PLATFORM.startswith('aix')) + VXWORKS = ('vxworks' in HOST_PLATFORM) ++CC = os.environ.get("CC") ++if not CC: ++ CC = sysconfig.get_config_var("CC") + + + SUMMARY = """ +@@ -443,6 +446,9 @@ def set_compiler_executables(self): + + def build_extensions(self): + self.set_srcdir() ++ self.set_compiler_executables() ++ self.configure_compiler() ++ self.init_inc_lib_dirs() + + # Detect which modules should be compiled + self.detect_modules() +@@ -451,7 +457,6 @@ def build_extensions(self): + + self.update_sources_depends() + mods_built, mods_disabled = self.remove_configured_extensions() +- self.set_compiler_executables() + + build_ext.build_extensions(self) + +@@ -631,12 +636,11 @@ def check_extension_import(self, ext): + def add_multiarch_paths(self): + # Debian/Ubuntu multiarch support. + # https://wiki.ubuntu.com/MultiarchSpec +- cc = sysconfig.get_config_var('CC') + tmpfile = os.path.join(self.build_temp, 'multiarch') + if not os.path.exists(self.build_temp): + os.makedirs(self.build_temp) + ret = run_command( +- '%s -print-multiarch > %s 2> /dev/null' % (cc, tmpfile)) ++ '%s -print-multiarch > %s 2> /dev/null' % (CC, tmpfile)) + multiarch_path_component = '' + try: + if ret == 0: +@@ -675,11 +679,10 @@ def add_multiarch_paths(self): + os.unlink(tmpfile) + + def add_cross_compiling_paths(self): +- cc = sysconfig.get_config_var('CC') + tmpfile = os.path.join(self.build_temp, 'ccpaths') + if not os.path.exists(self.build_temp): + os.makedirs(self.build_temp) +- ret = run_command('%s -E -v - %s 1>/dev/null' % (cc, tmpfile)) ++ ret = run_command('%s -E -v - %s 1>/dev/null' % (CC, tmpfile)) + is_gcc = False + is_clang = False + in_incdirs = False +@@ -1783,9 +1786,6 @@ def detect_uuid(self): + self.missing.append('_uuid') + + def detect_modules(self): +- self.configure_compiler() +- self.init_inc_lib_dirs() +- + self.detect_simple_extensions() + if TEST_EXTENSIONS: + self.detect_test_extensions() + diff --git a/patches/python-3.9.2/024-musl-find_library.patch b/patches/python-3.9.2/024-musl-find_library.patch new file mode 100644 index 000000000..f986a7a94 --- /dev/null +++ b/patches/python-3.9.2/024-musl-find_library.patch @@ -0,0 +1,74 @@ +https://bugs.python.org/issue21622 + +Based on the patch from Alpine Linux +https://git.alpinelinux.org/aports/tree/main/python2/musl-find_library.patch + +--- a/Lib/ctypes/util.py ++++ b/Lib/ctypes/util.py +@@ -92,6 +92,8 @@ elif sys.platform.startswith("aix"): + elif os.name == "posix": + # Andreas Degert's find functions, using gcc, /sbin/ldconfig, objdump + import re, tempfile ++ from glob import glob ++ musl_ldso = glob('/lib/ld-musl-*.so.1') + + def _is_elf(filename): + "Return True if the given file is an ELF file" +@@ -265,6 +267,57 @@ elif os.name == "posix": + def find_library(name, is64 = False): + return _get_soname(_findLib_crle(name, is64) or _findLib_gcc(name)) + ++ elif musl_ldso and os.path.isfile(musl_ldso[0]): ++ ++ def _is_elf(filepath): ++ try: ++ with open(filepath, 'rb') as fh: ++ return fh.read(4) == b'\x7fELF' ++ except: ++ return False ++ ++ def find_library(name): ++ # absolute name? ++ if os.path.isabs(name): ++ if _is_elf(name): ++ return name ++ else: ++ return None ++ ++ # special case for unified standard libs ++ stdlibs = ['libcrypt.so', 'libdl.so', 'libm.so', 'libpthread.so', 'libresolv.so', 'librt.so', 'libutil.so', 'libxnet.so'] ++ if name in stdlibs: ++ name = 'libc.so' ++ elif ('lib' + name + '.so') in stdlibs: ++ name = 'c' ++ ++ paths = [] ++ # read path list from /etc/ld-musl-$(ARCH).path ++ path_list = musl_ldso[0].replace('/lib/', '/etc/').replace('.so.1', '.path') ++ try: ++ with open(path_list, 'r') as fh: ++ paths = [path for line in fh for path in line.rstrip('\n').split(':') if path] ++ except: ++ paths = [] ++ # default path list if /etc/ld-musl-$(ARCH).path is empty or does not exist ++ if not paths: ++ paths = ['/lib', '/usr/local/lib', '/usr/lib'] ++ ++ # prepend paths from LD_LIBRARY_PATH ++ if 'LD_LIBRARY_PATH' in os.environ: ++ paths = os.environ['LD_LIBRARY_PATH'].split(':') + paths ++ ++ for d in paths: ++ f = os.path.join(d, name) ++ if _is_elf(f): ++ return os.path.basename(f) ++ ++ prefix = os.path.join(d, 'lib'+name) ++ for suffix in ['.so', '.so.*']: ++ for f in glob('{0}{1}'.format(prefix, suffix)): ++ if _is_elf(f): ++ return os.path.basename(f) ++ + else: + + def _findSoname_ldconfig(name): diff --git a/patches/python-3.9.2/030-bpo-43112-detect-musl-as-a-separate-SOABI-GH-24502.patch b/patches/python-3.9.2/030-bpo-43112-detect-musl-as-a-separate-SOABI-GH-24502.patch new file mode 100644 index 000000000..f22075e26 --- /dev/null +++ b/patches/python-3.9.2/030-bpo-43112-detect-musl-as-a-separate-SOABI-GH-24502.patch @@ -0,0 +1,75 @@ +From 3f79de7b8411c76a1fcd1ca850ea62500be7a881 Mon Sep 17 00:00:00 2001 +From: Natanael Copa +Date: Sat, 29 Jan 2022 00:02:54 +0100 +Subject: [PATCH 1/2] bpo-43112: detect musl as a separate SOABI (GH-24502) +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +musl libc and gnu libc are not ABI compatible so we need set different +SOABI for musl and not simply assume that all linux is linux-gnu. + +Replace linux-gnu with the detected os for the build from config.guess +for linux-musl*. + +(cherry picked from commit 1f036ede59e2c4befc07714cf76603c591d5c972) +Signed-off-by: Šimon Bořek +--- + Lib/test/test_sysconfig.py | 8 ++++---- + .../next/Build/2021-02-10-17-54-04.bpo-43112.H5Lat6.rst | 1 + + configure | 5 +++++ + configure.ac | 5 +++++ + 4 files changed, 15 insertions(+), 4 deletions(-) + create mode 100644 Misc/NEWS.d/next/Build/2021-02-10-17-54-04.bpo-43112.H5Lat6.rst + +--- a/Lib/test/test_sysconfig.py ++++ b/Lib/test/test_sysconfig.py +@@ -425,11 +425,11 @@ class TestSysConfig(unittest.TestCase): + self.assertTrue('linux' in suffix, suffix) + if re.match('(i[3-6]86|x86_64)$', machine): + if ctypes.sizeof(ctypes.c_char_p()) == 4: +- self.assertTrue(suffix.endswith('i386-linux-gnu.so') or +- suffix.endswith('x86_64-linux-gnux32.so'), +- suffix) ++ expected_suffixes = 'i386-linux-gnu.so', 'x86_64-linux-gnux32.so', 'i386-linux-musl.so' + else: # 8 byte pointer size +- self.assertTrue(suffix.endswith('x86_64-linux-gnu.so'), suffix) ++ expected_suffixes = 'x86_64-linux-gnu.so', 'x86_64-linux-musl.so' ++ self.assertTrue(suffix.endswith(expected_suffixes), ++ f'unexpected suffix {suffix!r}') + + @unittest.skipUnless(sys.platform == 'darwin', 'OS X-specific test') + def test_osx_ext_suffix(self): +--- /dev/null ++++ b/Misc/NEWS.d/next/Build/2021-02-10-17-54-04.bpo-43112.H5Lat6.rst +@@ -0,0 +1 @@ ++Detect musl libc as a separate SOABI (tagged as ``linux-musl``). +\ No newline at end of file +--- a/configure ++++ b/configure +@@ -5376,6 +5376,11 @@ EOF + + if $CPP $CPPFLAGS conftest.c >conftest.out 2>/dev/null; then + PLATFORM_TRIPLET=`grep -v '^#' conftest.out | grep -v '^ *$' | tr -d ' '` ++ case "$build_os" in ++ linux-musl*) ++ PLATFORM_TRIPLET=`echo "$PLATFORM_TRIPLET" | sed 's/linux-gnu/linux-musl/'` ++ ;; ++ esac + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PLATFORM_TRIPLET" >&5 + $as_echo "$PLATFORM_TRIPLET" >&6; } + else +--- a/configure.ac ++++ b/configure.ac +@@ -866,6 +866,11 @@ EOF + + if $CPP $CPPFLAGS conftest.c >conftest.out 2>/dev/null; then + PLATFORM_TRIPLET=`grep -v '^#' conftest.out | grep -v '^ *$' | tr -d ' '` ++ case "$build_os" in ++ linux-musl*) ++ PLATFORM_TRIPLET=`echo "$PLATFORM_TRIPLET" | sed 's/linux-gnu/linux-musl/'` ++ ;; ++ esac + AC_MSG_RESULT([$PLATFORM_TRIPLET]) + else + AC_MSG_RESULT([none])