#!/usr/bin/env python3 """Native Strata build. No Docker, driver changes, root requirement or service restart.""" import argparse,json,os,re,shutil,subprocess,sys from pathlib import Path ROOT=Path(__file__).resolve().parent.parent RECIPE=json.loads((ROOT/'strata_sources.json').read_text()) def run(args,cwd=None,env=None):subprocess.run([str(x) for x in args],cwd=cwd,env=env,check=True) def install(destination,nvcc=None,architectures='86;120'): destination=Path(destination).resolve() nvcc=nvcc or os.environ.get('STRATA_NVCC') or shutil.which('nvcc') if not nvcc or not re.search(r'release 13\.0\b',subprocess.check_output([nvcc,'--version'],text=True)): from strata_toolkit import toolkit nvcc=str(toolkit(destination/'cuda')) version=subprocess.check_output([nvcc,'--version'],text=True) if not re.search(r'release 13\.0\b',version):raise ValueError('Strata-Rezept benötigt CUDA Toolkit 13.0; vorhandene andere Toolkits bleiben unverändert.') for tool in ('git','g++','make'): if not shutil.which(tool):raise ValueError('Native Build-Abhängigkeit fehlt: '+tool) if not re.fullmatch(r'\d+(;\d+)*',architectures):raise ValueError('Ungültige CUDA-Architekturen.') destination.mkdir(parents=True,exist_ok=True) source=destination/'source' if not source.exists(): run(['git','init',source]);run(['git','-C',source,'fetch','--depth','1','https://github.com/Niko1221/Strata.git',RECIPE['code']]);run(['git','-C',source,'checkout','--detach','FETCH_HEAD']) if subprocess.check_output(['git','-C',source,'rev-parse','HEAD'],text=True).strip()!=RECIPE['code']:raise ValueError('Strata-Quellversion stimmt nicht mit Rezept überein.') python=source/'.venv/bin/python' if not python.is_file():run([sys.executable,'-m','venv',source/'.venv']) run([python,'-m','pip','install','--no-cache-dir','-r',source/'requirements.txt']) env=dict(os.environ,PATH=str(python.parent)+os.pathsep+str(Path(nvcc).parent)+os.pathsep+os.environ.get('PATH',''),CUDAToolkit_ROOT=str(Path(nvcc).parent.parent),LD_LIBRARY_PATH=str(Path(nvcc).parent.parent/'lib')+os.pathsep+str(Path(nvcc).parent.parent/'lib64')+os.pathsep+os.environ.get('LD_LIBRARY_PATH',''),STRATA_NVCC=str(nvcc),CMAKE_BUILD_PARALLEL_LEVEL='2') run([python,'-c','import setup;setup.get_llama_cpp()'],source,env) cmake=python.parent/'cmake' run([cmake,'-S',source,'-B',source/'build','-G','Ninja','-DCMAKE_BUILD_TYPE=Release','-DSTRATA_ENABLE_CUDA=ON','-DSTRATA_BUILD_TESTS=OFF','-DSTRATA_GGML_DIR='+str(source/'third_party/llama.cpp'),'-DCMAKE_CUDA_ARCHITECTURES='+architectures,'-DCMAKE_CUDA_COMPILER='+str(nvcc)],env=env) run([cmake,'--build',source/'build','--target','strata','-j','2'],env=env) (source/'engine').mkdir(exist_ok=True);shutil.copy2(source/'build/strata',source/'engine/strata') (source/'engine/BUILD.json').write_text(json.dumps(dict(source='local',version=RECIPE['version'],cuda_architectures=architectures,vision=False))) (destination/'ready.json').write_text(json.dumps(dict(commit=RECIPE['code'],cuda='13.0',architectures=architectures,origin='native-build'))) if __name__=='__main__': p=argparse.ArgumentParser();p.add_argument('--destination',required=True);p.add_argument('--nvcc');p.add_argument('--architectures',default='86;120');a=p.parse_args();install(a.destination,a.nvcc,a.architectures)