Skip to content

The only downloader you need. 下载器的集大成者。

ci(windows): libtorrent arm64 wheel 改从独立仓库下载

XiaoYouChRb6c79c3e2479
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 4394d39a..ef15bd8d 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -183,34 +183,23 @@ jobs:
echo "version=$version" >> $env:GITHUB_OUTPUT
echo "python=$((Get-Content .python-version).Trim())" >> $env:GITHUB_OUTPUT
- - name: Cache libtorrent wheel
- if: ${{ matrix.architecture == 'arm64' }}
- id: libtorrent-cache
- uses: actions/cache@v6
- with:
- path: libtorrent-wheel
- key: libtorrent-win_arm64-py${{ steps.libtorrent.outputs.python }}-${{ steps.libtorrent.outputs.version }}-${{ hashFiles('scripts/build_libtorrent_wheel.py') }}
-
- - name: Set up MSBuild
- if: ${{ matrix.architecture == 'arm64' && steps.libtorrent-cache.outputs.cache-hit != 'true' }}
- uses: microsoft/setup-msbuild@v2
-
- - name: Build libtorrent wheel
- if: ${{ matrix.architecture == 'arm64' && steps.libtorrent-cache.outputs.cache-hit != 'true' }}
- # b2 找不到编译器时会卡住而不是报错
- timeout-minutes: 120
- run: uv run --no-sync python scripts/build_libtorrent_wheel.py "${{ steps.libtorrent.outputs.version }}" "${{ steps.libtorrent.outputs.python }}" libtorrent-wheel
-
- name: Install libtorrent wheel
if: ${{ matrix.architecture == 'arm64' }}
shell: pwsh
- run: uv pip install (Get-ChildItem libtorrent-wheel/*.whl).FullName
-
- - name: Run tests
- if: ${{ matrix.architecture == 'arm64' }}
env:
- QT_QPA_PLATFORM: offscreen
- run: uv run --no-sync pytest
+ GH_TOKEN: ${{ github.token }}
+ REPO: XiaoYouChR/libtorrent-python-win-arm64
+ PREFIX: v${{ steps.libtorrent.outputs.version }}-py${{ steps.libtorrent.outputs.python }}-
+ run: |
+ $tag = gh release list -R $env:REPO --limit 1000 --json tagName --jq '.[].tagName' | Where-Object { $_.StartsWith($env:PREFIX) } | Sort-Object { [int]$_.Substring($env:PREFIX.Length) } | Select-Object -Last 1
+ if (-not $tag) {
+ throw "No $env:PREFIX* wheel in $env:REPO, run Build there first"
+ }
+ gh release download $tag -R $env:REPO -p "*.whl" -D libtorrent-wheel
+ $wheel = Get-ChildItem libtorrent-wheel/*.whl
+ gh release verify-asset $tag $wheel.FullName -R $env:REPO
+ if ($LASTEXITCODE) { exit $LASTEXITCODE }
+ uv pip install $wheel.FullName
- name: Build with Nuitka
run: |
diff --git a/scripts/build_libtorrent_wheel.py b/scripts/build_libtorrent_wheel.py
deleted file mode 100644
index d45775a4..00000000
--- a/scripts/build_libtorrent_wheel.py
+++ /dev/null
@@ -1,60 +0,0 @@
-#!/usr/bin/env python3
-"""Build the libtorrent win_arm64 wheel from the upstream tag.
-
-PyPI has no win_arm64 wheel. OpenSSL follows the upstream tag's own
-cibuildwheel config, so the wheel matches the x64 one on PyPI. Boost uses the
-latest release instead of the upstream one, because the windows-11-arm runner
-only has Visual Studio 2026, and b2 knows it since Boost 1.91.
-
-Usage:
- python scripts/build_libtorrent_wheel.py <libtorrent version> <python version> <output folder>
-"""
-import os
-import re
-import shutil
-import subprocess
-import sys
-from pathlib import Path
-
-UPSTREAM = "https://github.com/arvidn/libtorrent.git"
-BOOST = "https://github.com/boostorg/boost.git"
-OPENSSL_FOLDER = Path(r"C:\Program Files\OpenSSL")
-
-
-def run(*args: str, cwd: Path | None = None, env: dict[str, str] | None = None) -> None:
- subprocess.run(args, cwd=cwd, env=env, check=True)
-
-
-def fetchLatestBoostVersion() -> str:
- tags = subprocess.run(("git", "ls-remote", "--tags", "--refs", BOOST, "boost-*"),
- capture_output=True, text=True, check=True).stdout
- versions = re.findall(r"refs/tags/boost-(\d+\.\d+\.\d+)$", tags, re.MULTILINE)
- return max(versions, key=lambda v: tuple(map(int, v.split("."))))
-
-
-def main() -> None:
- version, pythonVersion, outputFolder = sys.argv[1:]
- source = Path(os.environ["RUNNER_TEMP"]) / "libtorrent"
-
- run("git", "clone", "--depth=1", f"--branch=v{version}",
- "--recurse-submodules", "--shallow-submodules", UPSTREAM, str(source))
- run("git", "apply", "../patch-libdatachannel-32bit-builds.patch", cwd=source / "deps" / "libdatachannel")
-
- run("vcpkg", "install", "--triplet=arm64-windows-static", cwd=source / "tools")
- # 上游 pyproject 的 B2_EXTRA_ARGS 固定从这里找 OpenSSL
- shutil.rmtree(OPENSSL_FOLDER, ignore_errors=True)
- run("cmd", "/c", "mklink", "/J", str(OPENSSL_FOLDER),
- str(source / "tools" / "vcpkg_installed" / "arm64-windows-static"))
-
- env = os.environ | {
- "CIBW_BUILD": f"cp{pythonVersion.replace('.', '')}-win_arm64",
- "CIBW_ARCHS_WINDOWS": "ARM64",
- # 上游只给 win32、win_amd64 配了装 Boost 的 before-all
- "CIBW_BEFORE_ALL_WINDOWS": f"bash -c './tools/cibuildwheel/setup_boost.sh {fetchLatestBoostVersion()} $BOOST_ROOT'",
- "CIBW_TEST_SKIP": "*",
- }
- run("uvx", "cibuildwheel", "--output-dir", str(Path(outputFolder).resolve()), cwd=source, env=env)
-
-
-if __name__ == "__main__":
- main()