PhillNet_Recall / scripts /build_native.py
ayjays132's picture
Upload 121 files
3b3b2bd verified
Raw History Blame Contribute Delete
735 Bytes
"""Explicit local compilation; downloaded repositories never execute code on loading."""
from pathlib import Path
import os,subprocess,sys,shutil
root=Path(__file__).resolve().parents[1]
compiler=os.environ.get('CC') or shutil.which('cc') or shutil.which('gcc')
if not compiler:raise SystemExit('No C compiler found. The Python reference remains usable.')
out=root/'phillnet_recall/native';out.mkdir(exist_ok=True)
name='ugr.dll' if os.name=='nt' else 'libugr.dylib' if sys.platform=='darwin' else 'libugr.so'
flags=['-std=c99','-O3','-ffp-contract=off','-fno-fast-math','-shared']
if os.name!='nt':flags+=['-fPIC']
cmd=[compiler,*flags,str(root/'native/ugr.c'),'-o',str(out/name),'-lm']
subprocess.run(cmd,check=True)
print(out/name)