From cf754001ddd10c30c366a2d6337e2a1a82bd6acf Mon Sep 17 00:00:00 2001 From: Andy Polyakov Date: Fri, 13 Sep 2024 13:00:12 +0200 Subject: [PATCH] bindings/python/run.me: update the build procedure. - build fat shared object on MacOS; - pull more information from sysconfig, make it work with MinGW; --- bindings/python/run.me | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/bindings/python/run.me b/bindings/python/run.me index 55a72761..29d1bc60 100755 --- a/bindings/python/run.me +++ b/bindings/python/run.me @@ -18,14 +18,20 @@ def newer(*files): if not os.path.exists(rh): return True for lh in files[:-1]: - if os.stat(lh).st_ctime > os.stat(rh).st_ctime: + if os.stat(lh).st_mtime > os.stat(rh).st_mtime: return True return False if newer("../blst.h", "../libblst.a"): print("building libblst.a...") or sys.stdout.flush() - subprocess.check_call(["../build.sh", "-fvisibility=hidden"] + sys.argv[1:], cwd="..") + cmd = ["../build.sh", "-fvisibility=hidden"] + sys.argv[1:] + if sysconfig.get_config_var('MACHDEP') == 'darwin': + cmd.extend(["-arch", "arm64", "-arch", "x86_64"]) + try: + subprocess.check_call(cmd, cwd="..") + except: + subprocess.check_call(["sh"] + cmd, cwd="..") if newer("../blst.swg", "../blst.h", "../blst.hpp", "blst_wrap.cpp"): print("swig-ing...") or sys.stdout.flush() @@ -33,15 +39,21 @@ if newer("../blst.swg", "../blst.h", "../blst.hpp", "blst_wrap.cpp"): "-o", "blst_wrap.cpp", "-outdir", ".", "../blst.swg"]) -if newer("blst_wrap.cpp", "../libblst.a", "_blst.so"): - print("compiling _blst.so...") or sys.stdout.flush() +blst_so = "_blst"+sysconfig.get_config_var('EXT_SUFFIX') + +if newer("blst_wrap.cpp", "../libblst.a", blst_so): + print("compiling %s..." % blst_so) or sys.stdout.flush() if sysconfig.get_config_var('MACHDEP') == 'darwin': - cmd = ["c++", "-bundle", "-undefined", "dynamic_lookup"] + cmd = ["c++", "-bundle", "-undefined", "dynamic_lookup", + "-arch", "arm64", "-arch", "x86_64"] else: cmd = ["c++", "-shared", "-Wl,-Bsymbolic"] - cmd.extend(["-o", "_blst.so", "-fPIC", "-fvisibility=hidden", + cmd.extend(["-o", blst_so, "-fPIC", "-fvisibility=hidden", "-I"+sysconfig.get_config_var('INCLUDEPY'), "-I..", "-O", "-Wall", "blst_wrap.cpp", "../libblst.a"]) + if sysconfig.get_config_var('LIBPYTHON'): + cmd.extend(["-L"+sysconfig.get_config_var('LIBDIR'), + sysconfig.get_config_var('LIBPYTHON')]) try: pre = subprocess.check_output(["c++", "-dM", "-E", "-x", "c++", "/dev/null"], stderr=subprocess.STDOUT)