Skip to content

Commit

Permalink
bindings/python/run.me: update the build procedure.
Browse files Browse the repository at this point in the history
- build fat shared object on MacOS;
- pull more information from sysconfig, make it work with MinGW;
  • Loading branch information
dot-asm committed Sep 13, 2024
1 parent d82c533 commit cf75400
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions bindings/python/run.me
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,42 @@ 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()
subprocess.check_call(["swig", "-c++", "-python", "-O",
"-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)
Expand Down

0 comments on commit cf75400

Please sign in to comment.