|
55 | 55 | - name: Install Rust toolchain |
56 | 56 | uses: dtolnay/rust-toolchain@stable |
57 | 57 |
|
| 58 | + - name: Preload Linux LibTorch |
| 59 | + if: runner.os == 'Linux' |
| 60 | + working-directory: flint |
| 61 | + shell: python |
| 62 | + run: | |
| 63 | + import os |
| 64 | + import pathlib |
| 65 | + import shutil |
| 66 | + import tempfile |
| 67 | + import urllib.request |
| 68 | + import zipfile |
| 69 | +
|
| 70 | + version = "2.12.1" |
| 71 | + url = ( |
| 72 | + "https://download.pytorch.org/libtorch/cpu/" |
| 73 | + f"libtorch-shared-with-deps-{version}%2Bcpu.zip" |
| 74 | + ) |
| 75 | + target_dir = pathlib.Path(os.environ.get("CARGO_TARGET_DIR", "target")) |
| 76 | + package_dir = target_dir / "store" / "libtorch" / version / "cpu" |
| 77 | + lib_dir = package_dir / "libtorch" / "lib" |
| 78 | + required = ("libc10.so", "libtorch_cpu.so", "libtorch.so") |
| 79 | +
|
| 80 | + if all((lib_dir / name).is_file() for name in required): |
| 81 | + raise SystemExit(0) |
| 82 | +
|
| 83 | + package_dir.parent.mkdir(parents=True, exist_ok=True) |
| 84 | + staging_dir = package_dir.with_name(f"{package_dir.name}.tmp") |
| 85 | + shutil.rmtree(staging_dir, ignore_errors=True) |
| 86 | +
|
| 87 | + archive_path = None |
| 88 | + try: |
| 89 | + with tempfile.NamedTemporaryFile( |
| 90 | + dir=package_dir.parent, suffix=".zip", delete=False |
| 91 | + ) as archive: |
| 92 | + archive_path = pathlib.Path(archive.name) |
| 93 | + request = urllib.request.Request( |
| 94 | + url, headers={"User-Agent": "flint-release-ci"} |
| 95 | + ) |
| 96 | + with urllib.request.urlopen(request, timeout=300) as response: |
| 97 | + shutil.copyfileobj(response, archive, length=1024 * 1024) |
| 98 | +
|
| 99 | + with zipfile.ZipFile(archive_path) as zip_file: |
| 100 | + damaged = zip_file.testzip() |
| 101 | + if damaged is not None: |
| 102 | + raise RuntimeError(f"damaged LibTorch member: {damaged}") |
| 103 | + zip_file.extractall(staging_dir) |
| 104 | +
|
| 105 | + if not all( |
| 106 | + (staging_dir / "libtorch" / "lib" / name).is_file() |
| 107 | + for name in required |
| 108 | + ): |
| 109 | + raise RuntimeError("LibTorch archive is missing required libraries") |
| 110 | +
|
| 111 | + shutil.rmtree(package_dir, ignore_errors=True) |
| 112 | + staging_dir.replace(package_dir) |
| 113 | + finally: |
| 114 | + if archive_path is not None: |
| 115 | + archive_path.unlink(missing_ok=True) |
| 116 | + shutil.rmtree(staging_dir, ignore_errors=True) |
| 117 | +
|
58 | 118 | - name: Build release runner |
59 | 119 | working-directory: flint |
60 | 120 | run: cargo build --release --locked --bin flint-ai |
|
0 commit comments