11import argparse
22from packaging .version import Version
3+ import shutil
4+ import subprocess
35
46from module .debug import shell_here
57from module .path import ProjectPaths
@@ -247,6 +249,49 @@ def _gettext(ver: BranchProfile, paths: ProjectPaths, config: argparse.Namespace
247249 make_default ('gettext' , build_dir , config .jobs )
248250 make_destdir_install ('gettext' , build_dir , paths .x_prefix / 'x86_64-w64-mingw32' )
249251
252+ def _python (ver : BranchProfile , paths : ProjectPaths , config : argparse .Namespace ):
253+ res = subprocess .run ([
254+ 'xmake' , 'config' , '--root' ,
255+ '-p' , 'mingw' ,
256+ '-a' , 'x86_64' ,
257+ f'--mingw={ paths .x_prefix } ' ,
258+ f'--cross=x86_64-w64-mingw32-' ,
259+ ], cwd = paths .python )
260+ if res .returncode != 0 :
261+ raise Exception ('xmake config failed' )
262+ res = subprocess .run ([
263+ 'xmake' , 'build' , '--root' ,
264+ '-j' , str (config .jobs ),
265+ ], cwd = paths .python )
266+ if res .returncode != 0 :
267+ raise Exception ('xmake build failed' )
268+ res = subprocess .run ([
269+ 'xmake' , 'install' , '--root' ,
270+ '-o' , paths .x_prefix / 'x86_64-w64-mingw32' ,
271+ ], cwd = paths .python )
272+ if res .returncode != 0 :
273+ raise Exception ('xmake install failed' )
274+
275+ def _python_packages (ver : BranchProfile , paths : ProjectPaths , config : argparse .Namespace ):
276+ x_prefix_mingw = paths .x_prefix / 'x86_64-w64-mingw32'
277+ python_lib = x_prefix_mingw / 'Lib'
278+ python_lib_zip = x_prefix_mingw / 'lib' / 'python.zip'
279+ shutil .copytree (paths .x_prefix / 'share' / f'gcc-{ config .branch } ' / 'python' , python_lib , dirs_exist_ok = True )
280+ subprocess .run ([
281+ 'python3' , '-m' , 'compileall' ,
282+ '-b' ,
283+ '-o' , '2' ,
284+ '.' ,
285+ ], check = True , cwd = python_lib )
286+ if python_lib_zip .exists ():
287+ python_lib_zip .unlink ()
288+ subprocess .run ([
289+ '7z' , 'a' , '-tzip' ,
290+ '-mx0' , # no compression, reduce final size
291+ python_lib_zip ,
292+ '*' , '-xr!__pycache__' , '-xr!*.py' ,
293+ ], check = True , cwd = python_lib )
294+
250295def build_AAB_library (ver : BranchProfile , paths : ProjectPaths , config : argparse .Namespace ):
251296 _gmp (ver , paths , config )
252297
@@ -256,3 +301,7 @@ def build_AAB_library(ver: BranchProfile, paths: ProjectPaths, config: argparse.
256301
257302 if ver .gettext :
258303 _gettext (ver , paths , config )
304+
305+ if ver .python :
306+ _python (ver , paths , config )
307+ _python_packages (ver , paths , config )
0 commit comments