An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Improve Linux OCR compatibility with glibc 2.28 https://github.com/siyuan-note/siyuan/issues/20591
Danielf7a860e9274a
diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.mdindex b72ae4b211..deafa7aae0 100644--- a/.github/CONTRIBUTING.md+++ b/.github/CONTRIBUTING.md@@ -70,7 +70,7 @@ Use `--workspace` for notebook data and `--wd` for application resources indepenDesktop packaging runs `scripts/prepare-ocr.py` to prepare the pinned models and native runtime. Run `python scripts/prepare-ocr.py --runtime windows-amd64 --check-only` or `python3 scripts/prepare-ocr.py --runtime linux-arm64 --build-worker --check-only` to check native prerequisites without downloading assets or compiling anything.* Windows: the release builder must have redistribution rights under its Visual Studio license and the matching x64/ARM64 **release** CRT files from `VC/Redist/MSVC`. The script discovers installed Visual Studio through `vswhere` or `VCToolsRedistDir`. Set `SIYUAN_OCR_VC_REDIST_DIR` to `VC/Redist/MSVC/<version>` (containing `x64` and/or `arm64`) or the target's `Microsoft.VC*.CRT` directory for a custom location or cross-host packaging. Use official Visual Studio redist files, not DLLs copied from `System32`, debug runtimes, or third-party DLL download sites. The preparation step checks architecture and required exports, bundles the transitive CRT dependencies beside ONNX Runtime, and records their SHA-256 digests and licensing notice. Keep this app-local runtime updated when preparing releases. See Microsoft's [redistribution terms](https://learn.microsoft.com/en-us/visualstudio/releases/2022/redistribution#visual-c-runtime-files). It does not install system-wide runtimes or require elevation on end-user machines-* Linux: the OCR worker needs a **glibc** compiler even when the kernel uses a musl toolchain. Install native `gcc` and the appropriate cross compiler before running `scripts/linux-build.sh`. On Debian/Ubuntu, AMD64-to-ARM64 builds need `gcc-aarch64-linux-gnu`; ARM64-to-AMD64 builds need `gcc-x86-64-linux-gnu`. Both can be installed with `sudo apt-get install gcc gcc-aarch64-linux-gnu gcc-x86-64-linux-gnu`. Optional `SIYUAN_OCR_CC_AMD64` and `SIYUAN_OCR_CC_ARM64` overrides select target-specific compiler commands; the script verifies their target triples and does not reuse the kernel's musl `CC`+* Linux: the desktop OCR worker targets **glibc 2.28** on both AMD64 and ARM64, independently of the kernel's musl toolchain. The preparation script downloads the pinned Zig compiler from `scripts/ocr-assets.json`, verifies its checksum, and caches it in `.cache/ocr/`; the compiler is not distributed in the application. Install `binutils` for the `readelf` compatibility check. Optional `SIYUAN_OCR_CC_AMD64` and `SIYUAN_OCR_CC_ARM64` overrides select compiler commands with a glibc 2.28 or older sysroot; newer headers and artifacts requiring newer glibc symbols are rejected. `--check-only` validates the default toolchain selection without downloading it. Docker uses its separate Alpine/musl OCR build and is unchanged### iOSdiff --git a/.github/CONTRIBUTING.zh-CN.md b/.github/CONTRIBUTING.zh-CN.mdindex 07167ad635..51928b03e8 100644--- a/.github/CONTRIBUTING.zh-CN.md+++ b/.github/CONTRIBUTING.zh-CN.md@@ -70,7 +70,7 @@ NPM 镜像:桌面端打包会运行 `scripts/prepare-ocr.py`,准备固定版本的模型和原生运行库。可以先执行 `python scripts/prepare-ocr.py --runtime windows-amd64 --check-only` 或 `python3 scripts/prepare-ocr.py --runtime linux-arm64 --build-worker --check-only` 检查原生依赖,不会下载资源或执行编译。* Windows:发布构建者须具有 Visual Studio 许可证授予的再分发权,并从 `VC/Redist/MSVC` 提供对应 x64/ARM64 架构的**发布版** CRT 文件。脚本通过 `vswhere` 或 `VCToolsRedistDir` 查找已安装的 Visual Studio。自定义位置或跨主机打包时,将 `SIYUAN_OCR_VC_REDIST_DIR` 指向含 `x64`、`arm64` 子目录的 `VC/Redist/MSVC/<version>`,也可以直接指向目标架构的 `Microsoft.VC*.CRT` 目录。仅使用官方 Visual Studio 再分发文件,不要从 `System32`、调试运行库或第三方 DLL 下载站收集文件。准备步骤会检查架构和必需的导出符号,将 CRT 的传递依赖放在 ONNX Runtime 旁,并记录 SHA-256 摘要及许可说明。发布时应及时更新这些应用本地运行库,详见 Microsoft 的[再分发条款](https://learn.microsoft.com/en-us/visualstudio/releases/2022/redistribution#visual-c-runtime-files)。该方案不会安装系统级运行库,也不需要最终用户提权-* Linux:即使内核采用 musl 工具链,OCR 辅助进程仍需要 **glibc** 编译器。运行 `scripts/linux-build.sh` 前须准备本机 `gcc` 和对应的交叉编译器。在 Debian/Ubuntu 上,AMD64 主机构建 ARM64 需要 `gcc-aarch64-linux-gnu`,ARM64 主机构建 AMD64 需要 `gcc-x86-64-linux-gnu`;可执行 `sudo apt-get install gcc gcc-aarch64-linux-gnu gcc-x86-64-linux-gnu` 安装。可选环境变量 `SIYUAN_OCR_CC_AMD64`、`SIYUAN_OCR_CC_ARM64` 分别指定目标架构的编译器命令,脚本会校验目标三元组,不会复用内核的 musl `CC`+* Linux:桌面 OCR 辅助进程的 AMD64、ARM64 构建统一以 **glibc 2.28** 为兼容目标,独立于内核的 musl 工具链。准备脚本下载 `scripts/ocr-assets.json` 中固定版本的 Zig 编译器,校验摘要并缓存在 `.cache/ocr/`,不随应用分发。请安装 `binutils`,以便使用 `readelf` 检查兼容性。可选环境变量 `SIYUAN_OCR_CC_AMD64`、`SIYUAN_OCR_CC_ARM64` 分别指定带 glibc 2.28 或更旧 sysroot 的编译器命令;脚本会拒绝较新头文件及依赖较新 glibc 符号的产物。`--check-only` 仅校验默认工具链选择,不下载工具链。Docker 继续使用独立的 Alpine/musl OCR 构建流程### iOSdiff --git a/scripts/ocr-assets.json b/scripts/ocr-assets.jsonindex f41da518f1..9548acf36e 100644--- a/scripts/ocr-assets.json+++ b/scripts/ocr-assets.json@@ -25,6 +25,22 @@"size": 55571}],+ "linuxWorker": {+ "glibc": "2.28",+ "zigVersion": "0.15.2",+ "toolchains": {+ "x86_64": {+ "url": "https://ziglang.org/download/0.15.2/zig-x86_64-linux-0.15.2.tar.xz",+ "sha256": "02aa270f183da276e5b5920b1dac44a63f1a49e55050ebde3aecc9eb82f93239",+ "size": 53733924+ },+ "aarch64": {+ "url": "https://ziglang.org/download/0.15.2/zig-aarch64-linux-0.15.2.tar.xz",+ "sha256": "958ed7d1e00d0ea76590d27666efbf7a932281b3d7ba0c6b01b0ff26498f667f",+ "size": 49471996+ }+ }+ },"runtime": {"windows-amd64": {"url": "https://github.com/microsoft/onnxruntime/releases/download/v1.24.3/onnxruntime-win-x64-1.24.3.zip",diff --git a/scripts/prepare-ocr.py b/scripts/prepare-ocr.pyindex cda30ad091..7ecb72b90c 100644--- a/scripts/prepare-ocr.py+++ b/scripts/prepare-ocr.py@@ -162,33 +162,82 @@ def prepare_windows_crt(target, directory, source):(directory / "vc-runtime-files.json").write_text(json.dumps({name: digest(directory / name) for name in sorted(selected)}, indent=2) + "\n", encoding="utf-8")-def linux_worker_environment(target):+def linux_worker_zig(check_only=False):+ config = MANIFEST["linuxWorker"]+ host = {"amd64": "x86_64", "arm64": "aarch64"}.get(platform.machine().lower(), platform.machine().lower())+ if platform.system() != "Linux" or host not in config["toolchains"]:+ raise RuntimeError("Default Linux OCR toolchain requires a Linux AMD64 or ARM64 build host")+ entry = config["toolchains"][host]+ archive_name = entry["url"].rsplit("/", 1)[1]+ directory = CACHE / archive_name.removesuffix(".tar.xz")+ executable = directory / "zig"+ if check_only:+ return executable+ archive = CACHE / archive_name+ download(entry, archive)+ stamp = directory / ".siyuan-source-sha256"+ if not executable.is_file() or not stamp.is_file() or stamp.read_text(encoding="utf-8") != entry["sha256"]:+ # 仅解包已校验的官方工具链,缓存目录不随安装包分发。+ with tempfile.TemporaryDirectory(prefix="zig-", dir=CACHE) as temporary:+ with tarfile.open(archive) as source:+ source.extractall(temporary, filter="data")+ extracted = Path(temporary) / directory.name+ if directory.exists():+ if directory.resolve().parent != CACHE.resolve() or directory.is_symlink():+ raise RuntimeError(f"Invalid OCR toolchain cache directory: {directory}")+ shutil.rmtree(directory)+ extracted.rename(directory)+ stamp.write_text(entry["sha256"], encoding="utf-8")+ version = subprocess.check_output([str(executable), "version"], encoding="utf-8").strip()+ if version != config["zigVersion"]:+ raise RuntimeError(f"Unexpected OCR compiler version: {version}")+ return executable+++def linux_worker_environment(target, check_only=False):architecture = target.split("-", 1)[1]triples = {"amd64": "x86_64-linux-gnu", "arm64": "aarch64-linux-gnu"}- host = {"x86_64": "amd64", "amd64": "amd64", "aarch64": "arm64", "arm64": "arm64"}.get(platform.machine().lower())variable = "SIYUAN_OCR_CC_" + architecture.upper()- compiler = os.environ.get(variable) or ("gcc" if host == architecture and platform.system() == "Linux" else triples[architecture] + "-gcc")- command = shlex.split(compiler)+ compiler = os.environ.get(variable)+ glibc = MANIFEST["linuxWorker"]["glibc"]+ command = shlex.split(compiler) if compiler else [str(linux_worker_zig(check_only)), "cc", "-target", f"{triples[architecture]}.{glibc}"]+ environment = os.environ.copy()+ environment.update(GOOS="linux", GOARCH=architecture, CGO_ENABLED="1", CC=shlex.join(command))+ if not compiler and check_only:+ return environmentif not command or not shutil.which(command[0]):- package = {"amd64": "gcc-x86-64-linux-gnu", "arm64": "gcc-aarch64-linux-gnu"}[architecture]- raise RuntimeError(f"Missing OCR compiler {compiler}. Install gcc/{package} or set {variable} to a glibc target compiler")- triple = subprocess.check_output(command + ["-dumpmachine"], encoding="utf-8").strip()- if triple.split("-", 1)[0] != triples[architecture].split("-", 1)[0] or "-linux-gnu" not in triple:- raise RuntimeError(f"OCR compiler {compiler} targets {triple}; {target} requires {triples[architecture]} (glibc)")+ raise RuntimeError(f"Missing OCR compiler {compiler}; set {variable} to a glibc <= {glibc} target compiler")+ if compiler:+ triple = subprocess.check_output(command + ["-dumpmachine"], encoding="utf-8").strip()+ if triple.split("-", 1)[0] != triples[architecture].split("-", 1)[0] or "-linux-gnu" not in triple:+ raise RuntimeError(f"OCR compiler {compiler} targets {triple}; {target} requires {triples[architecture]} (glibc)")macros = subprocess.check_output(command + ["-dM", "-E", "-x", "c", "-"], input="#include <features.h>\n", encoding="utf-8")if not re.search(r"^#define __GLIBC__ \d+$", macros, re.M):raise RuntimeError(f"OCR compiler {compiler} does not use glibc headers; musl wrappers cannot load the bundled runtime")- environment = os.environ.copy()- # 内核可使用 musl 静态链接;识别辅助进程必须匹配随包分发的 glibc 原生运行库。- environment.update(GOOS="linux", GOARCH=architecture, CGO_ENABLED="1", CC=shlex.join(command))+ major = re.search(r"^#define __GLIBC__ (\d+)$", macros, re.M)+ minor = re.search(r"^#define __GLIBC_MINOR__ (\d+)$", macros, re.M)+ if not minor or (int(major[1]), int(minor[1])) > tuple(map(int, glibc.split("."))):+ raise RuntimeError(f"OCR compiler must target glibc <= {glibc}; use the default Zig toolchain or an older sysroot")+ # 不继承内核的 musl 编译器,双架构统一使用指定的 glibc 兼容目标。return environment-def runtime_prerequisites(target, build_worker):+def verify_linux_glibc(path):+ environment = {**os.environ, "LC_ALL": "C"}+ output = subprocess.check_output(["readelf", "--version-info", "--wide", str(path)], encoding="utf-8", env=environment)+ versions = [tuple(map(int, value.split("."))) for value in re.findall(r"Name: GLIBC_(\d+(?:\.\d+)+)", output)]+ limit = MANIFEST["linuxWorker"]["glibc"]+ if not versions or max(versions) > tuple(map(int, limit.split("."))):+ raise RuntimeError(f"Linux OCR artifact must require glibc <= {limit}: {path}")+++def runtime_prerequisites(target, build_worker, check_only=False):if target.startswith("windows-"):return windows_crt_directory(target)if target.startswith("linux-") and build_worker:- return linux_worker_environment(target)+ if not shutil.which("readelf"):+ raise RuntimeError("Missing readelf; install binutils to verify Linux OCR compatibility")+ return linux_worker_environment(target, check_only)return None@@ -347,6 +396,8 @@ def prepare_runtime(target, build_worker, prerequisites=None):prepare_windows_crt(target, directory, prerequisites)if target.startswith("linux-") and build_worker:subprocess.run(["go", "build", "-trimpath", "-ldflags=-s -w", "-o", str(directory / "siyuan-ocr"), "./ocr/cmd/ocr-worker"], cwd=ROOT / "kernel", env=prerequisites, check=True)+ verify_linux_glibc(directory / "siyuan-ocr")+ verify_linux_glibc(directory / entry["library"])def remove_obsolete_models():@@ -368,7 +419,7 @@ def main():args = parser.parse_args()if args.check_only and args.runtime == "none":parser.error("--check-only requires --runtime")- prerequisites = runtime_prerequisites(args.runtime, args.build_worker)+ prerequisites = runtime_prerequisites(args.runtime, args.build_worker, check_only=args.check_only)if args.check_only:print(f"OCR prerequisites ready: {args.runtime}")returndiff --git a/scripts/test_prepare_ocr.py b/scripts/test_prepare_ocr.pyindex c2b8e5893a..63d39b4e0f 100644--- a/scripts/test_prepare_ocr.py+++ b/scripts/test_prepare_ocr.py@@ -355,39 +355,43 @@ class ResourceTests(unittest.TestCase):patch.object(prepare, "MANIFEST", {"runtime": {"linux-amd64": entry}}), \patch.object(prepare, "CACHE", self.root / "cache"):prepare.prepare_runtime("linux-amd64", False)- with patch.object(prepare, "download") as download, patch.object(prepare.subprocess, "run") as build:+ with patch.object(prepare, "download") as download, patch.object(prepare.subprocess, "run") as build, \+ patch.object(prepare, "verify_linux_glibc") as verify:prepare.prepare_runtime("linux-amd64", True, {"CC": "gcc"})download.assert_not_called()build.assert_called_once()self.assertEqual(build.call_args.kwargs["env"], {"CC": "gcc"})+ self.assertEqual(verify.call_count, 2)class CompilerTests(unittest.TestCase):- def test_selects_native_and_cross_compilers_without_inheriting_kernel_cc(self):- for host, target, compiler, triple in (- ("x86_64", "amd64", "gcc", "x86_64-linux-gnu"),- ("aarch64", "arm64", "gcc", "aarch64-linux-gnu"),- ("x86_64", "arm64", "aarch64-linux-gnu-gcc", "aarch64-linux-gnu"),- ("aarch64", "amd64", "x86_64-linux-gnu-gcc", "x86_64-linux-gnu"),+ def test_selects_glibc_228_for_both_architectures_without_inheriting_kernel_cc(self):+ for host, target, triple in (+ ("x86_64", "amd64", "x86_64-linux-gnu"),+ ("aarch64", "arm64", "aarch64-linux-gnu"),+ ("x86_64", "arm64", "aarch64-linux-gnu"),+ ("aarch64", "amd64", "x86_64-linux-gnu"),):with self.subTest(host=host, target=target), patch.dict(os.environ, {"CC": "wrong-linux-musl-gcc"}, clear=True), \patch.object(prepare.platform, "machine", return_value=host), \patch.object(prepare.platform, "system", return_value="Linux"), \+ patch.object(prepare, "linux_worker_zig", return_value=Path("/tools/zig")), \patch.object(prepare.shutil, "which", return_value="/usr/bin/compiler"), \- patch.object(prepare.subprocess, "check_output", side_effect=[triple, "#define __GLIBC__ 2\n"]) as probe:+ patch.object(prepare.subprocess, "check_output", return_value="#define __GLIBC__ 2\n#define __GLIBC_MINOR__ 28\n") as probe:environment = prepare.linux_worker_environment("linux-" + target)- self.assertEqual(environment["CC"], compiler)+ command = [str(Path("/tools/zig")), "cc", "-target", triple + ".2.28"]+ self.assertEqual(environment["CC"], prepare.shlex.join(command))self.assertEqual(environment["GOARCH"], target)self.assertEqual(environment["CGO_ENABLED"], "1")- self.assertEqual(probe.call_args_list[0].args, ([compiler, "-dumpmachine"],))- self.assertEqual(probe.call_count, 2)+ self.assertEqual(probe.call_args_list[0].args, (command + ["-dM", "-E", "-x", "c", "-"],))+ self.assertEqual(probe.call_count, 1)def test_explicit_compiler_supports_paths_with_spaces(self):with patch.dict(os.environ, {"SIYUAN_OCR_CC_AMD64": "'/opt/cross tools/gcc'"}, clear=True), \patch.object(prepare.platform, "machine", return_value="AMD64"), \patch.object(prepare.platform, "system", return_value="Windows"), \patch.object(prepare.shutil, "which", return_value="/opt/cross tools/gcc"), \- patch.object(prepare.subprocess, "check_output", side_effect=["x86_64-linux-gnu", "#define __GLIBC__ 2\n"]) as probe:+ patch.object(prepare.subprocess, "check_output", side_effect=["x86_64-linux-gnu", "#define __GLIBC__ 2\n#define __GLIBC_MINOR__ 28\n"]) as probe:self.assertEqual(prepare.linux_worker_environment("linux-amd64")["CC"], "'/opt/cross tools/gcc'")self.assertEqual(probe.call_args_list[0].args, (["/opt/cross tools/gcc", "-dumpmachine"],))@@ -399,11 +403,11 @@ class CompilerTests(unittest.TestCase):prepare.linux_worker_environment("linux-amd64")def test_rejects_missing_wrong_architecture_and_musl_compilers(self):- with patch.dict(os.environ, {}, clear=True), patch.object(prepare.shutil, "which", return_value=None):+ with patch.dict(os.environ, {"SIYUAN_OCR_CC_AMD64": "gcc"}, clear=True), patch.object(prepare.shutil, "which", return_value=None):with self.assertRaisesRegex(RuntimeError, "Missing OCR compiler"):prepare.linux_worker_environment("linux-amd64")for triple in ("aarch64-linux-gnu", "x86_64-linux-musl", "x86_64-apple-darwin"):- with self.subTest(triple=triple), patch.dict(os.environ, {}, clear=True), \+ with self.subTest(triple=triple), patch.dict(os.environ, {"SIYUAN_OCR_CC_AMD64": "gcc"}, clear=True), \patch.object(prepare.shutil, "which", return_value="/usr/bin/gcc"), \patch.object(prepare.subprocess, "check_output", return_value=triple):with self.assertRaisesRegex(RuntimeError, "requires x86_64-linux-gnu"):@@ -414,17 +418,80 @@ class CompilerTests(unittest.TestCase):patch.object(prepare, "runtime_prerequisites") as prerequisites, \patch.object(prepare, "download") as download, patch.object(prepare, "prepare_runtime") as runtime:prepare.main()- prerequisites.assert_called_once_with("linux-arm64", True)+ prerequisites.assert_called_once_with("linux-arm64", True, check_only=True)download.assert_not_called()runtime.assert_not_called()def test_linux_missing_compiler_fails_before_downloading(self):- with patch.dict(os.environ, {}, clear=True), patch.object(prepare.shutil, "which", return_value=None), \+ with patch.dict(os.environ, {"SIYUAN_OCR_CC_AMD64": "gcc"}, clear=True), patch.object(prepare.shutil, "which", side_effect=lambda name: "readelf" if name == "readelf" else None), \patch.object(prepare, "download") as download:with self.assertRaisesRegex(RuntimeError, "Missing OCR compiler"):prepare.prepare_runtime("linux-amd64", True)download.assert_not_called()+ def test_explicit_newer_or_unknown_sysroot_is_rejected(self):+ for minor in ("#define __GLIBC_MINOR__ 34\n", ""):+ with self.subTest(minor=minor), patch.dict(os.environ, {"SIYUAN_OCR_CC_AMD64": "gcc"}, clear=True), \+ patch.object(prepare.shutil, "which", return_value="gcc"), \+ patch.object(prepare.subprocess, "check_output", side_effect=["x86_64-linux-gnu", "#define __GLIBC__ 2\n" + minor]):+ with self.assertRaisesRegex(RuntimeError, "must target glibc <= 2.28"):+ prepare.linux_worker_environment("linux-amd64")++ def test_default_check_only_selects_toolchain_without_downloads_or_execution(self):+ with patch.dict(os.environ, {}, clear=True), \+ patch.object(prepare.platform, "machine", return_value="x86_64"), \+ patch.object(prepare.platform, "system", return_value="Linux"), \+ patch.object(prepare, "download") as download, patch.object(prepare.subprocess, "check_output") as probe:+ environment = prepare.linux_worker_environment("linux-arm64", check_only=True)+ self.assertIn("aarch64-linux-gnu.2.28", environment["CC"])+ download.assert_not_called()+ probe.assert_not_called()++ def test_artifact_verification_uses_required_symbol_versions(self):+ for version, accepted in (("2.17", True), ("2.28", True), ("2.34", False), ("", False)):+ with self.subTest(version=version), patch.object(prepare.subprocess, "check_output", return_value=+ "Name: GLIBC_" + version if version else "No version information found"):+ if accepted:+ prepare.verify_linux_glibc(Path("siyuan-ocr"))+ else:+ with self.assertRaisesRegex(RuntimeError, "must require glibc <= 2.28"):+ prepare.verify_linux_glibc(Path("siyuan-ocr"))++ def test_default_toolchain_extracts_verified_archive_and_reuses_cache(self):+ with tempfile.TemporaryDirectory() as temporary:+ root = Path(temporary)+ archive = root / "toolchain.tar.xz"+ with tarfile.open(archive, "w:xz") as output:+ info = tarfile.TarInfo("toolchain/zig")+ info.size = 8+ output.addfile(info, io.BytesIO(b"compiler"))+ entry = {"url": archive.as_uri(), "sha256": prepare.digest(archive), "size": archive.stat().st_size}+ manifest = {"linuxWorker": {"zigVersion": "0.15.2", "toolchains": {"x86_64": entry}}}+ with patch.object(prepare, "MANIFEST", manifest), patch.object(prepare, "CACHE", root / "cache"), \+ patch.object(prepare.platform, "machine", return_value="x86_64"), \+ patch.object(prepare.platform, "system", return_value="Linux"), \+ patch.object(prepare.subprocess, "check_output", return_value="0.15.2\n"):+ compiler = prepare.linux_worker_zig()+ self.assertEqual(compiler.read_bytes(), b"compiler")+ with patch.object(prepare.tarfile, "open") as unpack:+ self.assertEqual(prepare.linux_worker_zig(), compiler)+ unpack.assert_not_called()++ def test_default_toolchain_checks_version(self):+ with tempfile.TemporaryDirectory() as temporary:+ root = Path(temporary)+ with patch.object(prepare, "CACHE", root), patch.object(prepare, "download"), \+ patch.object(prepare.platform, "machine", return_value="x86_64"), \+ patch.object(prepare.platform, "system", return_value="Linux"):+ directory = root / "zig-x86_64-linux-0.15.2"+ directory.mkdir()+ (directory / "zig").write_bytes(b"compiler")+ (directory / ".siyuan-source-sha256").write_text(+ prepare.MANIFEST["linuxWorker"]["toolchains"]["x86_64"]["sha256"], encoding="utf-8")+ with patch.object(prepare.subprocess, "check_output", return_value="unexpected\n"):+ with self.assertRaisesRegex(RuntimeError, "Unexpected OCR compiler version"):+ prepare.linux_worker_zig()+if __name__ == "__main__":unittest.main()