"""Build a pinned isolated native worker; development VM builds use --backend cpu.""" import argparse import os from pathlib import Path import shutil import subprocess import sys ROOT = Path(__file__).resolve().parents[2] TAG = "b11461" COMMIT = "4d756bc72bf00a4aacf410ae15a2d315f3db400d" def run(arguments, cwd=None): subprocess.run([str(value) for value in arguments], cwd=cwd, check=True) def main(): parser = argparse.ArgumentParser(description="Build Searchi's pinned Google embedding worker") parser.add_argument("--backend", choices=["cpu", "auto", "metal", "vulkan", "cuda"], default="auto") parser.add_argument("--jobs", type=int, default=2) args = parser.parse_args() if not 1 <= args.jobs <= 16: parser.error("jobs must be 1–16") vulkan_loader = None if os.name == "nt" and args.backend in {"auto", "vulkan"}: from provision_vulkan import provision sdk, vulkan_loader = provision() os.environ["VULKAN_SDK"] = str(sdk) source = ROOT / ".searchi/references/llama.cpp" build = ROOT / ".searchi/runtime" / args.backend if not source.exists(): source.parent.mkdir(parents=True, exist_ok=True) run(["git", "clone", "--depth", "1", "--branch", TAG, "https://github.com/ggml-org/llama.cpp.git", source]) actual = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=source, text=True).strip() if actual != COMMIT: raise RuntimeError("Runtime reference checkout differs from pinned commit; refusing to reset it") patch = Path(__file__).with_name("no-logits.patch") check = subprocess.run(["git", "apply", "--check", str(patch)], cwd=source, capture_output=True) if check.returncode == 0: run(["git", "apply", patch], cwd=source) else: reverse = subprocess.run(["git", "apply", "--reverse", "--check", str(patch)], cwd=source, capture_output=True) if reverse.returncode: raise RuntimeError("Runtime memory patch cannot be applied or verified") cmake_exe = shutil.which("cmake") if not cmake_exe: try: import cmake cmake_exe = str(Path(cmake.CMAKE_BIN_DIR) / ("cmake.exe" if os.name == "nt" else "cmake")) except ImportError as error: raise RuntimeError("Install CMake first (python -m pip install cmake)") from error worker_source = ROOT / "crates/searchi-semantic/native" run([cmake_exe, "-S", worker_source, "-B", build, "-DCMAKE_BUILD_TYPE=Release", f"-DLLAMA_CPP_DIR={source}", f"-DSEARCHI_ACCELERATION={args.backend}"]) run([cmake_exe, "--build", build, "--config", "Release", "--parallel", args.jobs]) if vulkan_loader: for name in ["vulkan-1.dll", "VULKAN-LICENSE.txt"]: shutil.copy2(vulkan_loader / name, build / "Release" / name) print(f"Runtime build complete: {build}") if __name__ == "__main__": main()