Package portable Linux runtime and verify Google CPU search

This commit is contained in:
karl committed 2026-10-13 00:43:20 +02:00
1 parent e3558a0104
commit 0b56ab553c
22 files changed
+1585 -16

No files matched your search

@@ -1,11 +1,87 @@
"""Redistributable preparation tests; no native builds or GPU execution."""
from pathlib import Path
import json
import tempfile
import unittest
from unittest.mock import patch
import build_runtime
from build_runtime import bundle_windows_crt, WINDOWS_CRT_FILES
class LinuxRuntimeTests(unittest.TestCase):
def test_only_normal_linux_vulkan_modes_use_shared_dispatch(self):
with patch.object(build_runtime.sys, "platform", "linux"), patch.object(build_runtime.platform, "machine", return_value="x86_64"):
for backend in ["auto", "vulkan"]:
self.assertTrue(build_runtime.linux_dispatch(backend))
for backend in ["cpu", "cuda", "metal"]:
self.assertFalse(build_runtime.linux_dispatch(backend))
with patch.object(build_runtime.sys, "platform", "darwin"):
self.assertFalse(build_runtime.linux_dispatch("auto"))
with patch.object(build_runtime.sys, "platform", "linux"), patch.object(build_runtime.platform, "machine", return_value="aarch64"):
self.assertFalse(build_runtime.linux_dispatch("auto"))
self.assertFalse(build_runtime.linux_dispatch("vulkan"))
def test_readelf_parses_needed_soname_and_runpath_without_executing_worker(self):
output = " 0x1 (NEEDED) Shared library: [libggml.so.0]\n 0xe (SONAME) Library soname: [libggml-cpu-x64.so]\n 0x1d (RUNPATH) Library runpath: [$ORIGIN]\n"
with patch.object(build_runtime.subprocess, "check_output", return_value=output) as command:
result = build_runtime.elf_dynamic(Path("worker"))
self.assertEqual(result, {"NEEDED": ["libggml.so.0"], "SONAME": ["libggml-cpu-x64.so"], "RUNPATH": ["$ORIGIN"]})
command.assert_called_once_with(["readelf", "--dynamic", "worker"], text=True)
def fixture(self, root):
root = Path(root)
(root / "bin").mkdir()
(root / "searchi-gemma-worker").write_bytes(b"worker")
for name in ["ggml", "ggml-base", "llama", "mtmd"]:
(root / "bin" / f"lib{name}.so").write_bytes(name.encode())
for variant in build_runtime.LINUX_CPU_VARIANTS:
(root / f"libggml-cpu-{variant}.so").write_bytes(variant.encode())
(root / "libggml-vulkan.so").write_bytes(b"vulkan")
return root
def metadata(self, path):
result = {"RUNPATH": ["$ORIGIN"], "NEEDED": ["libstdc++.so.6", "libc.so.6"]}
if path.parent.name == "bin":
result["SONAME"] = [path.name + ".0"]
if path.name == "libggml-vulkan.so":
result["NEEDED"].append("libvulkan.so.1")
return result
def test_flattened_core_and_bounded_modules_have_hashed_inventory(self):
with tempfile.TemporaryDirectory() as directory:
root = self.fixture(directory)
with patch.object(build_runtime, "elf_dynamic", side_effect=self.metadata):
build_runtime.bundle_linux_libraries(root)
manifest = json.loads((root / "runtime-libraries.json").read_text())
self.assertEqual(manifest["platform"], "linux")
self.assertEqual(len(manifest["libraries"]), 5 + len(build_runtime.LINUX_CPU_VARIANTS))
self.assertTrue((root / "libllama.so.0").is_file())
self.assertTrue(all(not (root / item["path"]).is_symlink() for item in manifest["libraries"]))
self.assertTrue(all(len(item["sha256"]) == 64 for item in manifest["libraries"]))
def test_startup_gpu_dependency_and_build_tree_rpath_are_rejected(self):
for problem in ["gpu", "rpath", "missing"]:
with self.subTest(problem=problem), tempfile.TemporaryDirectory() as directory:
root = self.fixture(directory)
previous = root / "libllama.so.0"
previous.write_bytes(b"previous flattened core")
def metadata(path):
result = self.metadata(path)
if path.name == "searchi-gemma-worker":
if problem == "gpu":
result["NEEDED"].append("libvulkan.so.1")
elif problem == "rpath":
result["RUNPATH"] = ["/private/build"]
else:
result["NEEDED"].append("libunpackaged.so.9")
return result
with patch.object(build_runtime, "elf_dynamic", side_effect=metadata), self.assertRaises(RuntimeError):
build_runtime.bundle_linux_libraries(root)
self.assertFalse((root / "runtime-libraries.json").exists())
self.assertEqual(previous.read_bytes(), b"previous flattened core")
class CrtTests(unittest.TestCase):
def fixture(self, directory):
root = Path(directory)