30 lines
2.0 KiB
Python
30 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Build-only six-component pinned toolkit, no BLAS/model/GPU/runtime installation."""
|
|
import importlib.util,json,os,pathlib,sys,tempfile,hashlib
|
|
root=pathlib.Path(__file__).resolve().parents[1]
|
|
spec=importlib.util.spec_from_file_location('cuda_bootstrap',root/'scripts/bootstrap-cuda-toolkit.py')
|
|
b=importlib.util.module_from_spec(spec);spec.loader.exec_module(b)
|
|
assert len(sys.argv)==2
|
|
out=pathlib.Path(sys.argv[1]).absolute();assert not out.exists();out.parent.mkdir(parents=True,exist_ok=True)
|
|
lock=json.loads((root/'deploy/cuda-toolkit.lock.json').read_text());os.umask(0o077)
|
|
with tempfile.TemporaryDirectory(prefix='.q5-toolkit-',dir=out.parent) as td:
|
|
stage=pathlib.Path(td);prefix=stage/'toolkit';prefix.mkdir()
|
|
manifest=stage/'manifest.json';b.download(lock['manifest_url'],manifest,lock['manifest_sha256'],1024**2)
|
|
b.validate_lock(lock,json.loads(manifest.read_text()))
|
|
components=[x for x in lock['components'] if x['component']!='libcublas'];assert len(components)==6
|
|
for item in components:
|
|
archive=stage/(item['component']+'.tar.xz');size=int(item['size'])
|
|
b.download(b.BASE+item['relative_path'],archive,item['sha256'],size,size)
|
|
tree=b.extract(archive,stage,pathlib.Path(item['relative_path']).name.removesuffix('.tar.xz'))
|
|
for child in tree.iterdir():
|
|
if child.is_dir() and not child.is_symlink():b.merge(child,prefix/child.name)
|
|
else:
|
|
license_dir=prefix/'licenses'/item['component'];license_dir.mkdir(parents=True,exist_ok=True);b.merge(child,license_dir/child.name)
|
|
print(json.dumps(item),flush=True)
|
|
(prefix/'lib64').symlink_to('lib',target_is_directory=True)
|
|
for p in prefix.rglob('*'):
|
|
if p.is_symlink():assert p.resolve().is_relative_to(prefix) and p.exists()
|
|
(prefix/'TOOLKIT-PROVENANCE.json').write_text(json.dumps({'lock':lock,'selected_components':[x['component'] for x in components],'scope':'independent Q5 oracle/offline PTX only; no BLAS'},indent=2)+'\n')
|
|
prefix.rename(out)
|
|
print('Prepared '+str(out))
|