Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

fix(python): add Windows ARM64 support and extract cua-driver-uia.exe (#1850)

ddupont46681f2e3904
diff --git a/.github/workflows/cd-py-cua-driver.yml b/.github/workflows/cd-py-cua-driver.yml
index 23b1079246..87813e3bb8 100644
--- a/.github/workflows/cd-py-cua-driver.yml
+++ b/.github/workflows/cd-py-cua-driver.yml
@@ -77,14 +77,20 @@ jobs:
include:
- os: macos-latest
platform: macos
+ arch: universal
- os: ubuntu-latest
platform: linux
+ arch: x86_64
- os: windows-latest
platform: windows
+ arch: x86_64
+ - os: windows-latest
+ platform: windows
+ arch: arm64
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- - uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a20 # v5.3.0
+ - uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
with:
python-version: "3.12"
@@ -111,7 +117,7 @@ jobs:
shell: bash
run: |
cd libs/cua-driver/python
- python build_wheel.py --version "${{ needs.get-version.outputs.version }}"
+ python build_wheel.py --version "${{ needs.get-version.outputs.version }}" --arch "${{ matrix.arch }}"
- name: List built artifacts
shell: bash
@@ -120,7 +126,7 @@ jobs:
- uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
with:
- name: wheel-${{ matrix.platform }}
+ name: wheel-${{ matrix.platform }}-${{ matrix.arch }}
path: libs/cua-driver/python/dist/*.whl
if-no-files-found: error
@@ -128,9 +134,8 @@ jobs:
publish-pypi:
needs: [get-version, build-wheels]
runs-on: ubuntu-latest
- environment: pypi
permissions:
- id-token: write # For trusted publishing
+ contents: read
steps:
- name: Download all wheels
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
@@ -143,9 +148,14 @@ jobs:
run: |
ls -lh dist/
+ - name: Install twine
+ run: |
+ python -m pip install --upgrade pip
+ pip install twine
+
- name: Publish to PyPI
- uses: pypa/gh-action-pypi-publish@67339c736fd9354cd4f8cb0b744f2b82a74b5c70 # v1.12.2
- with:
- packages-dir: dist/
- skip-existing: true
- verbose: true
+ env:
+ TWINE_USERNAME: __token__
+ TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
+ run: |
+ python -m twine upload --skip-existing --verbose dist/*
diff --git a/libs/cua-driver/python/build_wheel.py b/libs/cua-driver/python/build_wheel.py
index cf03d758b0..eb8ed849bc 100644
--- a/libs/cua-driver/python/build_wheel.py
+++ b/libs/cua-driver/python/build_wheel.py
@@ -24,18 +24,34 @@ import zipfile
from pathlib import Path
-def get_platform_info():
- """Determine platform and architecture for binary selection."""
+def get_platform_info(arch_override: str = None):
+ """Determine platform and architecture for binary selection.
+
+ Args:
+ arch_override: Optional architecture override (e.g., 'arm64', 'x86_64', 'universal')
+ """
system = platform.system().lower()
- machine = platform.machine().lower()
- # Normalize architecture names
- if machine in ("x86_64", "amd64"):
- arch = "x86_64"
- elif machine in ("arm64", "aarch64"):
- arch = "arm64"
+ if arch_override:
+ # Normalize arch_override to handle common aliases/casing
+ arch_lower = arch_override.lower()
+ if arch_lower in ("x86_64", "amd64", "x64"):
+ arch = "x86_64"
+ elif arch_lower in ("arm64", "aarch64"):
+ arch = "arm64"
+ elif arch_lower == "universal":
+ arch = "universal"
+ else:
+ raise ValueError(f"Unsupported architecture override: {arch_override}")
else:
- raise ValueError(f"Unsupported architecture: {machine}")
+ machine = platform.machine().lower()
+ # Normalize architecture names
+ if machine in ("x86_64", "amd64"):
+ arch = "x86_64"
+ elif machine in ("arm64", "aarch64"):
+ arch = "arm64"
+ else:
+ raise ValueError(f"Unsupported architecture: {machine}")
# Map to cua-driver-rs release naming
if system == "darwin":
@@ -49,28 +65,29 @@ def get_platform_info():
raise ValueError(f"Unsupported platform: {system}")
-def get_release_url(version: str, platform_name: str, arch: str) -> tuple[str, str]:
- """Get the GitHub release URL and binary name for the platform.
+def get_release_url(version: str, platform_name: str, arch: str) -> tuple[str, list[str]]:
+ """Get the GitHub release URL and binary names for the platform.
Returns:
- Tuple of (download_url, binary_name_in_archive)
+ Tuple of (download_url, list_of_binary_names_in_archive)
"""
base_url = f"https://github.com/trycua/cua/releases/download/cua-driver-rs-v{version}"
if platform_name == "darwin":
# Universal binary tarball
filename = f"cua-driver-rs-{version}-darwin-universal-binary.tar.gz"
- binary_name = "cua-driver"
+ binary_names = ["cua-driver"]
elif platform_name == "linux":
filename = f"cua-driver-rs-{version}-linux-{arch}-binary.tar.gz"
- binary_name = "cua-driver"
+ binary_names = ["cua-driver"]
elif platform_name == "windows":
filename = f"cua-driver-rs-{version}-windows-{arch}-binary.zip"
- binary_name = "cua-driver.exe"
+ # Windows includes both main executable and UIAccess worker
+ binary_names = ["cua-driver.exe", "cua-driver-uia.exe"]
else:
raise ValueError(f"Unknown platform: {platform_name}")
- return f"{base_url}/{filename}", binary_name
+ return f"{base_url}/{filename}", binary_names
def verify_sha256(file_path: Path, expected_sha256: str) -> None:
@@ -146,42 +163,80 @@ def download_file(url: str, dest: Path, expected_sha256: str) -> None:
raise RuntimeError(f"Failed to download {url}: {e}")
-def extract_binary(archive_path: Path, binary_name: str, dest_dir: Path) -> Path:
- """Extract the binary from the archive."""
+def extract_binaries(archive_path: Path, binary_names: list[str], dest_dir: Path) -> list[Path]:
+ """Extract the binaries from the archive.
+
+ Args:
+ archive_path: Path to the archive file
+ binary_names: List of binary names to extract
+ dest_dir: Destination directory
+
+ Returns:
+ List of paths to extracted binaries
+ """
dest_dir.mkdir(parents=True, exist_ok=True)
- dest_path = dest_dir / binary_name
+ extracted_paths = []
if archive_path.suffix == ".zip":
with zipfile.ZipFile(archive_path, "r") as zf:
- # Find the binary in the zip (exact match or ends with /<binary_name>)
- for name in zf.namelist():
- # Match exact name or path ending with /binary_name
- if name == binary_name or name.endswith(f"/{binary_name}"):
- with zf.open(name) as src, open(dest_path, "wb") as dst:
- shutil.copyfileobj(src, dst)
- break
- else:
- raise ValueError(f"Binary {binary_name} not found in {archive_path}")
+ for binary_name in binary_names:
+ dest_path = dest_dir / binary_name
+ # Find the binary in the zip (exact match or ends with /<binary_name>)
+ for name in zf.namelist():
+ # Match exact name or path ending with /binary_name
+ if name == binary_name or name.endswith(f"/{binary_name}"):
+ with zf.open(name) as src, open(dest_path, "wb") as dst:
+ shutil.copyfileobj(src, dst)
+ extracted_paths.append(dest_path)
+ print(f"Extracted binary to {dest_path}")
+ break
+ else:
+ raise ValueError(f"Binary {binary_name} not found in {archive_path}")
else:
# .tar.gz
with tarfile.open(archive_path, "r:gz") as tf:
- # The -binary tarballs have the binary at the root
- tf.extract(binary_name, dest_dir)
+ for binary_name in binary_names:
+ # The -binary tarballs have the binary at the root
+ tf.extract(binary_name, dest_dir)
+ dest_path = dest_dir / binary_name
+ extracted_paths.append(dest_path)
+ print(f"Extracted binary to {dest_path}")
# Make executable on Unix
if sys.platform != "win32":
- os.chmod(dest_path, 0o755)
+ for path in extracted_paths:
+ os.chmod(path, 0o755)
- print(f"Extracted binary to {dest_path}")
- return dest_path
+ return extracted_paths
-def build_wheel(package_dir: Path) -> None:
- """Build the wheel using hatchling."""
+def build_wheel(package_dir: Path, target_arch: str = None) -> None:
+ """Build the wheel using hatchling.
+
+ Args:
+ package_dir: Directory containing pyproject.toml
+ target_arch: Target architecture for cross-compilation (x86_64, arm64)
+ """
print("\nBuilding wheel...")
+
+ env = os.environ.copy()
+
+ # Set platform tag override for cross-compilation
+ if target_arch:
+ system = platform.system().lower()
+ if system == "windows":
+ # Override wheel platform tag for Windows cross-compilation
+ if target_arch == "arm64":
+ env["_PYTHON_HOST_PLATFORM"] = "win-arm64"
+ elif target_arch == "x86_64":
+ env["_PYTHON_HOST_PLATFORM"] = "win-amd64"
+ # Linux and macOS don't need overrides for our use case
+ # (macOS uses universal binary, Linux builds on native arch)
+
subprocess.run(
[sys.executable, "-m", "build", "--wheel"],
cwd=package_dir,
+ env=env,
check=True,
)
print("Wheel built successfully!")
@@ -194,6 +249,10 @@ def main():
default="0.5.1",
help="cua-driver-rs version to download (default: 0.5.1)",
)
+ parser.add_argument(
+ "--arch",
+ help="Architecture override (e.g., 'arm64', 'x86_64', 'universal')",
+ )
parser.add_argument(
"--skip-download",
action="store_true",
@@ -208,10 +267,10 @@ def main():
if not args.skip_download:
# Get platform info and download URL
- platform_name, arch = get_platform_info()
+ platform_name, arch = get_platform_info(args.arch)
print(f"Building for {platform_name}-{arch}")
- url, binary_name = get_release_url(args.version, platform_name, arch)
+ url, binary_names = get_release_url(args.version, platform_name, arch)
archive_name = url.split("/")[-1]
archive_path = download_dir / archive_name
@@ -228,12 +287,12 @@ def main():
verify_sha256(archive_path, expected_sha256)
print("✓ Cached archive checksum verified")
- # Extract binary
- extract_binary(archive_path, binary_name, bin_dir)
+ # Extract binaries
+ extract_binaries(archive_path, binary_names, bin_dir)
else:
print("Skipping download (using existing binary)")
- # Verify binary exists
+ # Verify main binary exists
expected_binary = "cua-driver.exe" if sys.platform == "win32" else "cua-driver"
binary_path = bin_dir / expected_binary
if not binary_path.exists():
@@ -242,11 +301,17 @@ def main():
f"Run without --skip-download or place binary manually."
)
- print(f"Binary ready at: {binary_path}")
+ print(f"\nBinary ready at: {binary_path}")
print(f"Binary size: {binary_path.stat().st_size / 1024 / 1024:.2f} MB")
- # Build the wheel
- build_wheel(script_dir)
+ # List all binaries in bin directory
+ print(f"\nAll binaries in {bin_dir}:")
+ for binary in bin_dir.iterdir():
+ if binary.is_file():
+ print(f" - {binary.name} ({binary.stat().st_size / 1024 / 1024:.2f} MB)")
+
+ # Build the wheel (pass target arch for cross-compilation)
+ build_wheel(script_dir, target_arch=arch if not args.skip_download else None)
if __name__ == "__main__":
diff --git a/libs/cua-driver/python/pyproject.toml b/libs/cua-driver/python/pyproject.toml
index 5695ddbe19..9eca0d334e 100644
--- a/libs/cua-driver/python/pyproject.toml
+++ b/libs/cua-driver/python/pyproject.toml
@@ -50,3 +50,4 @@ packages = ["src/cua_driver"]
artifacts = [
"src/cua_driver/bin/*",
]
+pure-python = false