Skip to content

Build All Platforms #13

Build All Platforms

Build All Platforms #13

Workflow file for this run

name: Build All Platforms
on:
workflow_dispatch:
inputs:
publish-target:
description: 'Publish target: pypi or testpypi'
required: false
default: 'pypi'
type: choice
options:
- pypi
- testpypi
env:
CARGO_TERM_COLOR: always
RUSTC_WRAPPER: ""
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, macos-latest]
fail-fast: false
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
fetch-depth: 2
submodules: true
- name: Install Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@2b1f5e9b395427c92ee4e3331786ca3c37afe2d7
- name: Set up cargo cache
uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4
with:
shared-key: "rust-${{ matrix.os }}"
workspaces: "src/bridgex -> src/bridgex/target"
save-if: ${{ github.event_name == 'workflow_dispatch' }}
- name: Install linux dependencies
if: runner.os == 'Linux'
run: |
sudo apt update
base_packages="build-essential libssl-dev pkg-config libglib2.0-dev libgtk-3-dev libudev-dev libxdo-dev libfreetype6-dev libfontconfig1-dev libegl1-mesa-dev libgl1-mesa-dev libwayland-egl1-mesa libgles2-mesa-dev libx11-dev libxcursor-dev libxrandr-dev libxi-dev libxkbcommon-dev libwayland-dev cmake"
sudo apt install -y $base_packages libwebkit2gtk-4.1-dev || sudo apt install -y $base_packages libwebkit2gtk-4.0-dev
- name: Build Rust binary
run: cargo build --release --manifest-path src/bridgex/Cargo.toml
- name: Stage binary for wheel (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
New-Item -ItemType Directory -Force -Path python\bridgex\bin | Out-Null
Copy-Item -Force src\bridgex\target\release\bridgex.exe python\bridgex\bin\bridgex.exe
- name: Stage binary for wheel (macOS)
if: runner.os == 'macOS'
shell: bash
run: |
mkdir -p python/bridgex/bin
cp src/bridgex/target/release/bridgex python/bridgex/bin/bridgex
chmod +x python/bridgex/bin/bridgex
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'pip'
cache-dependency-path: |
pyproject.toml
- name: Install Python build tools
run: python -m pip install --upgrade pip build
- name: Build Python wheel (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: python -m build --wheel --outdir dist -C--build-option=bdist_wheel -C--build-option=--plat-name=win_amd64
- name: Verify wheel tag (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
$wheel = Get-ChildItem -Path dist -Filter *.whl | Where-Object { $_.Name -match 'win_amd64' } | Select-Object -First 1
if (-not $wheel) {
Get-ChildItem -Path dist -Filter *.whl | ForEach-Object { $_.Name }
throw "Expected a win_amd64 wheel in dist/."
}
- name: Build Python wheel (macOS)
if: runner.os == 'macOS'
shell: bash
run: |
arch=$(uname -m)
if [ "$arch" = "arm64" ]; then
plat="macosx_11_0_arm64"
else
plat="macosx_10_9_x86_64"
fi
python -m build --wheel --outdir dist -C--build-option=bdist_wheel -C--build-option=--plat-name=$plat
- name: Verify wheel tag (macOS)
if: runner.os == 'macOS'
shell: bash
run: |
ls -la dist || true
if ! ls dist/*.whl >/dev/null 2>&1; then
echo "No wheels found in dist/."
exit 1
fi
if ! ls dist/*macosx*.whl >/dev/null 2>&1; then
echo "Expected a macosx wheel in dist/."
exit 1
fi
- name: Skip Python wheel build (Linux)
if: runner.os == 'Linux'
run: echo "Skipping Python wheel build on Linux."
- name: Upload Python artifacts
if: runner.os != 'Linux'
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f
with:
name: dist-${{ matrix.os }}
path: dist/
publish:
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
fetch-depth: 2
submodules: true
- name: Install Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@2b1f5e9b395427c92ee4e3331786ca3c37afe2d7
- name: Install Linux dependencies
run: |
sudo apt update
base_packages="build-essential libssl-dev pkg-config libglib2.0-dev libgtk-3-dev libudev-dev libxdo-dev libfreetype6-dev libfontconfig1-dev libegl1-mesa-dev libgl1-mesa-dev libwayland-egl1-mesa libgles2-mesa-dev libx11-dev libxcursor-dev libxrandr-dev libxi-dev libxkbcommon-dev libwayland-dev cmake"
sudo apt install -y $base_packages libwebkit2gtk-4.1-dev || sudo apt install -y $base_packages libwebkit2gtk-4.0-dev
- name: Verify crate packaging
run: cargo package --allow-dirty --manifest-path src/bridgex/Cargo.toml
- name: Crates.io dry-run
run: |
# No public crates.io test registry exists.
# Use this dry run to validate the package without uploading.
cargo publish --dry-run --allow-dirty --manifest-path src/bridgex/Cargo.toml
- name: Publish crate to crates.io
if: github.event_name == 'workflow_dispatch'
run: cargo publish --allow-dirty --token "${{ secrets.CRATES_IO_TOKEN }}" --manifest-path src/bridgex/Cargo.toml
env:
CARGO_REGISTRIES_CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install Python build tools
run: python -m pip install --upgrade pip twine
- name: Download Python artifacts
uses: actions/download-artifact@v4
with:
path: dist-artifacts
- name: List wheel artifacts
run: |
find dist-artifacts -type f \( -name '*.whl' -o -name '*.tar.gz' \) | sort
- name: Publish package to PyPI
if: github.event_name == 'workflow_dispatch' && github.event.inputs.publish-target == 'pypi'
run: |
set -e
files=$(find dist-artifacts -type f \( -iname '*win32*.whl' -o -iname '*win_amd64*.whl' -o -iname '*win_arm64*.whl' -o -iname '*macosx*.whl' \) | tr '\n' ' ')
if [ -z "$files" ]; then
echo "No Windows/macOS wheels found to upload."
exit 1
fi
echo "Uploading files: $files"
python -m twine upload $files
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
- name: Publish package to Test PyPI
if: github.event_name == 'workflow_dispatch' && github.event.inputs.publish-target == 'testpypi'
run: |
set -e
files=$(find dist-artifacts -type f \( -iname '*win32*.whl' -o -iname '*win_amd64*.whl' -o -iname '*win_arm64*.whl' -o -iname '*macosx*.whl' \) | tr '\n' ' ')
if [ -z "$files" ]; then
echo "No Windows/macOS wheels found to upload to Test PyPI."
exit 1
fi
echo "Uploading files to Test PyPI: $files"
python -m twine upload --repository-url https://test.pypi.org/legacy/ $files
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TEST_API_TOKEN }}