#!/usr/bin/env python3

from types import SimpleNamespace

from lilaclib import *

# Somehow this can consume >100G disk space
build_args = ['-r', os.path.expanduser('~/chroots')]

g = SimpleNamespace()

def pre_build():
  g.files = download_official_pkgbuild('rocm-llvm')

  for line in edit_file('PKGBUILD'):
    line = line.replace('AMDGPU;NVPTX;X86', 'AMDGPU;NVPTX;AArch64')
    if line.startswith('arch='):
      line = 'arch=(aarch64)'
    if line.startswith('build()'):
      print(line)
      print("    CXXFLAGS+=' -Wno-error -Wno-narrowing'")
      print("    CFLAGS+=' -Wno-error -Wno-narrowing'")
      continue
    print(line)
  run_cmd(['updpkgsums'])

def post_build():
  git_add_files([f for f in g.files if not f.startswith(".")])
  git_commit()
