cazyundee commited on
Commit
2ab0e84
·
verified ·
1 Parent(s): 37096e6

Fix: build llama.cpp with static linking, find binary after build

Browse files
Files changed (1) hide show
  1. app.py +14 -5
app.py CHANGED
@@ -424,8 +424,7 @@ def _ensure_llama_cpp():
424
  import subprocess
425
 
426
  os.makedirs(_BENCHMARK_CACHE, exist_ok=True)
427
- build_dir = os.path.join(_BENCHMARK_CACHE, "llama_build")
428
- bin_dir = os.path.join(build_dir, "build", "bin")
429
  llama_cli = os.path.join(bin_dir, "llama-cli")
430
 
431
  if os.path.isfile(llama_cli):
@@ -445,18 +444,28 @@ def _ensure_llama_cpp():
445
  )
446
  _log("Benchmark: building llama.cpp (this takes 2-5 minutes)...")
447
  n_threads = _parse_cpu_count() or 8
 
448
  os.makedirs(build_dir, exist_ok=True)
 
449
  subprocess.check_call(
450
  ["cmake", "-S", src_dir, "-B", build_dir,
451
- "-DLLAMA_NATIVE=ON", "-DBUILD_SHARED_LIBS=ON"],
452
  stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
453
  )
454
  subprocess.check_call(
455
  ["cmake", "--build", build_dir, "-j", str(n_threads), "--target", "llama-cli"],
456
  stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
457
  )
458
- _log(f"Benchmark: llama.cpp built at {llama_cli}")
459
- _log(f"Benchmark: files: {os.listdir(bin_dir)}")
 
 
 
 
 
 
 
 
460
 
461
  _LLAMA_CPP_BIN = llama_cli
462
  return llama_cli
 
424
  import subprocess
425
 
426
  os.makedirs(_BENCHMARK_CACHE, exist_ok=True)
427
+ bin_dir = os.path.join(_BENCHMARK_CACHE, "llama_bin")
 
428
  llama_cli = os.path.join(bin_dir, "llama-cli")
429
 
430
  if os.path.isfile(llama_cli):
 
444
  )
445
  _log("Benchmark: building llama.cpp (this takes 2-5 minutes)...")
446
  n_threads = _parse_cpu_count() or 8
447
+ build_dir = os.path.join(_BENCHMARK_CACHE, "llama_build")
448
  os.makedirs(build_dir, exist_ok=True)
449
+ os.makedirs(bin_dir, exist_ok=True)
450
  subprocess.check_call(
451
  ["cmake", "-S", src_dir, "-B", build_dir,
452
+ "-DLLAMA_NATIVE=ON", "-DBUILD_SHARED_LIBS=OFF"],
453
  stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
454
  )
455
  subprocess.check_call(
456
  ["cmake", "--build", build_dir, "-j", str(n_threads), "--target", "llama-cli"],
457
  stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
458
  )
459
+ # Find the built binary
460
+ import glob as _glob
461
+ candidates = _glob.glob(os.path.join(build_dir, "**", "llama-cli"), recursive=True)
462
+ if candidates:
463
+ import shutil as _shutil2
464
+ _shutil2.copy2(candidates[0], llama_cli)
465
+ os.chmod(llama_cli, 0o755)
466
+ _log(f"Benchmark: llama.cpp built at {llama_cli}")
467
+ else:
468
+ raise RuntimeError(f"llama-cli not found after build in {build_dir}")
469
 
470
  _LLAMA_CPP_BIN = llama_cli
471
  return llama_cli