Skip to content

improve cross compile pipelines #12

improve cross compile pipelines

improve cross compile pipelines #12

Workflow file for this run

name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
inputs:
build_aarch64_flatpak:
description: 'Build aarch64 Flatpak (slow, ~6 hours with QEMU)'
required: false
default: false
type: boolean
build_riscv64:
description: 'Build riscv64 debug binary'
required: false
default: false
type: boolean
env:
CARGO_TERM_COLOR: always
jobs:
check:
name: Check & Build
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
pkg-config \
libglib2.0-dev \
libgstreamer1.0-dev \
libgstreamer-plugins-base1.0-dev \
libgstreamer-plugins-bad1.0-dev \
gstreamer1.0-plugins-base \
gstreamer1.0-plugins-good \
gstreamer1.0-plugins-bad \
gstreamer1.0-plugins-ugly \
gstreamer1.0-libav \
libwayland-dev \
libxkbcommon-dev \
libinput-dev \
libudev-dev \
libseat-dev
- name: Install just
uses: extractions/setup-just@v2
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Check formatting
run: just fmt-check
- name: Run cargo check
run: just cargo-check
- name: Run tests
run: just test
- name: Build release
run: just build-release
# Cross-compiled debug builds to verify compilation on all target architectures
# x86_64 and aarch64 always run; riscv64 runs on main or manual trigger
build-x86_64:
name: Build (x86_64)
runs-on: ubuntu-latest
needs: check
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: x86_64-unknown-linux-gnu
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
pkg-config \
libglib2.0-dev \
libgstreamer1.0-dev \
libgstreamer-plugins-base1.0-dev \
libgstreamer-plugins-bad1.0-dev \
libwayland-dev \
libxkbcommon-dev \
libinput-dev \
libudev-dev \
libseat-dev
- name: Build debug binary
run: cargo build --target x86_64-unknown-linux-gnu
build-aarch64:
name: Build (aarch64)
runs-on: ubuntu-latest
needs: check
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: aarch64-unknown-linux-gnu
- name: Install cross
run: cargo install cross --git https://github.com/cross-rs/cross
- name: Build debug binary
run: cross build --target aarch64-unknown-linux-gnu
build-riscv64:
name: Build (riscv64)
runs-on: ubuntu-latest
needs: check
# Run on push to main, or on manual trigger with build_riscv64=true
if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.build_riscv64)
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: riscv64gc-unknown-linux-gnu
- name: Install cross
run: cargo install cross --git https://github.com/cross-rs/cross
- name: Build debug binary
run: cross build --target riscv64gc-unknown-linux-gnu
# Flatpak build times (using QEMU emulation for non-x86_64):
#
# | Architecture | Duration |
# |--------------|---------------------|
# | x86_64 | ~20 minutes |
# | aarch64 | ~5 hours 47 minutes |
# | riscv64 | failed immediately |
#
# The aarch64 build uses QEMU emulation on an x86_64 runner, which is extremely
# slow (compiling Rust under emulation).
#
# Options for native ARM64 runners:
# 1. GitHub's ARM runners (runs-on: ubuntu-24.04-arm64) - requires GitHub Team/Enterprise or larger runners (paid)
# 2. Self-hosted runner - free, but you need your own ARM hardware
# 3. Disable aarch64 for now - build locally when needed
#
# aarch64: Runs on push to main, but on PRs only when manually triggered via workflow_dispatch
# riscv64 disabled: Flathub doesn't provide org.freedesktop.Platform runtime for riscv64
flatpak-x86_64:
name: Flatpak (x86_64)
runs-on: ubuntu-latest
needs: check
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Install Flatpak and flatpak-builder
run: |
sudo apt-get update
sudo apt-get install -y flatpak flatpak-builder
- name: Add Flathub remote
run: |
sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
- name: Install Flatpak SDK and runtime
run: |
sudo flatpak install -y --noninteractive flathub org.freedesktop.Platform//25.08 --arch=x86_64
sudo flatpak install -y --noninteractive flathub org.freedesktop.Sdk//25.08 --arch=x86_64
sudo flatpak install -y --noninteractive flathub org.freedesktop.Sdk.Extension.rust-stable//25.08 --arch=x86_64
- name: Install just
uses: extractions/setup-just@v2
- name: Install Python dependencies for cargo-sources generator
run: |
pip install aiohttp toml tomlkit
- name: Build Flatpak bundle
run: just flatpak-bundle-arch x86_64
- name: Upload Flatpak bundle
uses: actions/upload-artifact@v4
with:
name: cosmic-camera-x86_64.flatpak
path: cosmic-camera-x86_64.flatpak
if-no-files-found: error
retention-days: 7
flatpak-aarch64:
name: Flatpak (aarch64)
runs-on: ubuntu-latest
needs: check
# Run on push to main, or on manual trigger with build_aarch64_flatpak=true
if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.build_aarch64_flatpak)
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Install Flatpak and flatpak-builder
run: |
sudo apt-get update
sudo apt-get install -y flatpak flatpak-builder
- name: Set up QEMU for multi-arch builds
uses: docker/setup-qemu-action@v3
with:
platforms: arm64
- name: Add Flathub remote
run: |
sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
- name: Install Flatpak SDK and runtime
run: |
sudo flatpak install -y --noninteractive flathub org.freedesktop.Platform//25.08 --arch=aarch64
sudo flatpak install -y --noninteractive flathub org.freedesktop.Sdk//25.08 --arch=aarch64
sudo flatpak install -y --noninteractive flathub org.freedesktop.Sdk.Extension.rust-stable//25.08 --arch=aarch64
- name: Install just
uses: extractions/setup-just@v2
- name: Install Python dependencies for cargo-sources generator
run: |
pip install aiohttp toml tomlkit
- name: Build Flatpak bundle
run: just flatpak-bundle-arch aarch64
- name: Upload Flatpak bundle
uses: actions/upload-artifact@v4
with:
name: cosmic-camera-aarch64.flatpak
path: cosmic-camera-aarch64.flatpak
if-no-files-found: error
retention-days: 7