55from re import match
66
77import sh
8+ import subprocess
89import shutil
910import fnmatch
1011import zipfile
@@ -1408,6 +1409,7 @@ class MesonRecipe(PyProjectRecipe):
14081409 '''Recipe for projects which uses meson as build system'''
14091410
14101411 meson_version = "1.4.0"
1412+ pybind_version = "3.3.0"
14111413
14121414 skip_python = False
14131415 '''If true, skips all Python build and installation steps.
@@ -1416,6 +1418,18 @@ class MesonRecipe(PyProjectRecipe):
14161418 def sanitize_flags (self , * flag_strings ):
14171419 return " " .join (flag_strings ).strip ().split (" " )
14181420
1421+ def get_wrapper_dir (self , arch ):
1422+ return join (self .get_build_dir (arch .arch ), "p4a_wrappers" )
1423+
1424+ def write_wrapper (self , arch , name , content ):
1425+ wrapper_dir = self .get_wrapper_dir (arch )
1426+ ensure_dir (wrapper_dir )
1427+ wrapper_path = join (wrapper_dir , name )
1428+ with open (wrapper_path , "w" ) as f :
1429+ f .write (content )
1430+ chmod (wrapper_path , 0o755 )
1431+ return wrapper_path
1432+
14191433 def get_python_wrapper (self , arch ):
14201434 """
14211435 Meson Python introspection runs on the host interpreter, but the
@@ -1451,19 +1465,50 @@ def get_python_wrapper(self, arch):
14511465 with open (python_file , "r" ) as f :
14521466 file_data += "\n " + f .read ()
14531467
1454- wrapper_dir = join (self .get_build_dir (arch .arch ), "p4a_python_wrapper" )
1455- ensure_dir (wrapper_dir )
1456- wrapper_path = join (wrapper_dir , "python" )
1457- with open (wrapper_path , "w" ) as f :
1458- f .write (file_data )
1459- chmod (wrapper_path , 0o755 )
1468+ return self .write_wrapper (arch , "python" , file_data )
14601469
1461- return wrapper_path
1470+ def get_config_wrappers (self , arch , w_type : str ):
1471+ wrapper_name = ""
1472+ version = ""
1473+ include_path = ""
1474+
1475+ if w_type == "pybind11" :
1476+ wrapper_name = "pybind11-config"
1477+ include_path = join (self ._host_recipe .site_dir , "pybind11/include" )
1478+
1479+ version = None
1480+ try :
1481+ command = [self ._host_recipe .real_hostpython_location , "-c" , "import pybind11; print(pybind11.__version__)" ]
1482+ version = subprocess .check_output (command ).decode ('utf-8' ).strip ()
1483+ except Exception :
1484+ warning ("Unable to get pybind11 version" )
1485+ if version is None :
1486+ version = self .pybind_version
1487+
1488+ elif w_type == "numpy" :
1489+ wrapper_name = "numpy-config"
1490+ recipe = Recipe .get_recipe ("numpy" , self .ctx )
1491+ include_path = recipe .get_include (arch )
1492+ version = recipe .version
1493+ else :
1494+ raise ValueError (f"Unknown wrapper type: { w_type } " )
1495+
1496+ content = (
1497+ f"#!/bin/sh\n "
1498+ f"if [ \" $1\" = \" --version\" ]; then\n "
1499+ f" echo '{ version } '\n "
1500+ f"else\n "
1501+ f" echo '-I{ include_path } '\n "
1502+ f"fi\n "
1503+ )
1504+ return self .write_wrapper (arch , wrapper_name , content )
14621505
14631506 def get_recipe_meson_options (self , arch ):
14641507 env = self .get_recipe_env (arch , with_flags_in_cc = True )
14651508 return {
14661509 "binaries" : {
1510+ "pybind11-config" : self .get_config_wrappers (arch , "pybind11" ),
1511+ "numpy-config" : self .get_config_wrappers (arch , "numpy" ),
14671512 "python" : self .get_python_wrapper (arch ),
14681513 "c" : arch .get_clang_exe (with_target = True ),
14691514 "cpp" : arch .get_clang_exe (with_target = True , plus_plus = True ),
0 commit comments