"""Pinned third-party client build; all outputs remain in owned product staging.""" import hashlib import json import os from pathlib import Path import shutil import subprocess REPO = Path(__file__).resolve().parents[2] BUILD = REPO / ".runtime/wireguard-build" OUT = REPO / "apps/wireguard-client/build/macos-arm64" SOURCES = { "wireguard-go": ("0.0.20250522", "f333402bd9cbe0f3eeb02507bd14e23d7d639280"), "wireguard-tools": ("v1.0.20260223", "49ce333da02056ae7b22ee2aeb6afe8aaed79b19"), } def run(args, cwd=None, env=None): subprocess.run(args, cwd=cwd, env=env, check=True) def main(): BUILD.mkdir(parents=True, exist_ok=True) OUT.mkdir(parents=True, exist_ok=True) for name, (tag, commit) in SOURCES.items(): target = BUILD / name if not target.exists(): run(["git", "clone", "--quiet", "--depth", "1", "--branch", tag, "https://git.zx2c4.com/" + name, str(target)]) found = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=target, text=True).strip() if found != commit: raise ValueError("Third-party source identity differs") go = REPO / "apps/node-agent/build/_toolchain/go/bin/go" env = dict(os.environ, GOMAXPROCS="2", GOMEMLIMIT="512MiB", GOCACHE=str(BUILD / "go-cache"), GOPATH=str(BUILD / "go-modules"), CGO_ENABLED="0", GOOS="darwin", GOARCH="arm64") run([str(go), "build", "-p", "1", "-trimpath", "-ldflags=-s -w", "-o", str(OUT / "wireguard-go"), "."], BUILD / "wireguard-go", env) run(["make", "-j1", "wg"], BUILD / "wireguard-tools/src") shutil.copy2(BUILD / "wireguard-tools/src/wg", OUT / "wg") for binary in (OUT / "wg", OUT / "wireguard-go"): run(["codesign", "--force", "--sign", "-", str(binary)]) licenses = OUT / "licenses" licenses.mkdir(exist_ok=True) for name in SOURCES: shutil.copy2(BUILD / name / ("LICENSE" if name == "wireguard-go" else "COPYING"), licenses / (name + ".txt")) manifest = {"platform": "darwin-arm64", "sources": SOURCES, "files": {str(p.relative_to(OUT)): hashlib.sha256(p.read_bytes()).hexdigest() for p in sorted(OUT.rglob("*")) if p.is_file() and p.name != "manifest.json"}} (OUT / "manifest.json").write_text(json.dumps(manifest, indent=2) + "\n") print(json.dumps(manifest)) if __name__ == "__main__": main()