diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1f351d7..0caa866 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,35 +12,36 @@ on: required: false default: false type: boolean - build_riscv64: - description: 'Build riscv64 debug binary' - required: false - default: false - type: boolean + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true env: CARGO_TERM_COLOR: always jobs: check: - name: Check & Build + name: Check & Test 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 + uses: dtolnay/rust-toolchain@master with: + toolchain: stable 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 \ @@ -78,9 +79,6 @@ jobs: - 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: @@ -91,18 +89,20 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 with: - fetch-depth: 0 fetch-tags: true - name: Install Rust toolchain - uses: dtolnay/rust-toolchain@stable + uses: dtolnay/rust-toolchain@master with: + toolchain: stable 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 \ @@ -123,12 +123,12 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 with: - fetch-depth: 0 fetch-tags: true - name: Install Rust toolchain - uses: dtolnay/rust-toolchain@stable + uses: dtolnay/rust-toolchain@master with: + toolchain: stable targets: aarch64-unknown-linux-gnu - name: Install cross @@ -137,22 +137,21 @@ jobs: - 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 + uses: dtolnay/rust-toolchain@master with: + toolchain: stable targets: riscv64gc-unknown-linux-gnu - name: Install cross @@ -161,24 +160,6 @@ jobs: - 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 @@ -187,7 +168,6 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 with: - fetch-depth: 0 fetch-tags: true - name: Install Flatpak and flatpak-builder @@ -201,9 +181,10 @@ jobs: - name: Install Flatpak SDK and runtime run: | - sudo flatpak install -y --noninteractive flathub org.freedesktop.Platform//24.08 --arch=x86_64 - sudo flatpak install -y --noninteractive flathub org.freedesktop.Sdk//24.08 --arch=x86_64 - sudo flatpak install -y --noninteractive flathub org.freedesktop.Sdk.Extension.rust-stable//24.08 --arch=x86_64 + 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 + sudo flatpak install -y --noninteractive flathub com.system76.Cosmic.BaseApp//stable --arch=x86_64 - name: Install just uses: extractions/setup-just@v2 @@ -220,6 +201,7 @@ jobs: with: name: cosmic-camera-x86_64.flatpak path: cosmic-camera-x86_64.flatpak + if-no-files-found: error retention-days: 7 flatpak-aarch64: @@ -232,7 +214,6 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 with: - fetch-depth: 0 fetch-tags: true - name: Install Flatpak and flatpak-builder @@ -251,9 +232,10 @@ jobs: - name: Install Flatpak SDK and runtime run: | - sudo flatpak install -y --noninteractive flathub org.freedesktop.Platform//24.08 --arch=aarch64 - sudo flatpak install -y --noninteractive flathub org.freedesktop.Sdk//24.08 --arch=aarch64 - sudo flatpak install -y --noninteractive flathub org.freedesktop.Sdk.Extension.rust-stable//24.08 --arch=aarch64 + 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 + sudo flatpak install -y --noninteractive flathub com.system76.Cosmic.BaseApp//stable --arch=aarch64 - name: Install just uses: extractions/setup-just@v2 @@ -270,4 +252,5 @@ jobs: with: name: cosmic-camera-aarch64.flatpak path: cosmic-camera-aarch64.flatpak + if-no-files-found: error retention-days: 7 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 268ad2f..8113e17 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -32,8 +32,9 @@ jobs: fetch-tags: true - name: Install Rust toolchain - uses: dtolnay/rust-toolchain@stable + uses: dtolnay/rust-toolchain@master with: + toolchain: stable targets: ${{ matrix.target }} - name: Install cross-compilation tools @@ -103,9 +104,10 @@ jobs: - name: Install Flatpak SDK and runtime run: | - sudo flatpak install -y --noninteractive flathub org.freedesktop.Platform//24.08 --arch=x86_64 - sudo flatpak install -y --noninteractive flathub org.freedesktop.Sdk//24.08 --arch=x86_64 - sudo flatpak install -y --noninteractive flathub org.freedesktop.Sdk.Extension.rust-stable//24.08 --arch=x86_64 + 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 + sudo flatpak install -y --noninteractive flathub com.system76.Cosmic.BaseApp//stable --arch=x86_64 - name: Install just uses: extractions/setup-just@v2 @@ -121,6 +123,7 @@ jobs: with: name: flatpak-x86_64 path: cosmic-camera-x86_64.flatpak + if-no-files-found: error retention-days: 1 # Build Flatpak for aarch64 (QEMU emulation, slow but necessary for releases) @@ -150,9 +153,10 @@ jobs: - name: Install Flatpak SDK and runtime run: | - sudo flatpak install -y --noninteractive flathub org.freedesktop.Platform//24.08 --arch=aarch64 - sudo flatpak install -y --noninteractive flathub org.freedesktop.Sdk//24.08 --arch=aarch64 - sudo flatpak install -y --noninteractive flathub org.freedesktop.Sdk.Extension.rust-stable//24.08 --arch=aarch64 + 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 + sudo flatpak install -y --noninteractive flathub com.system76.Cosmic.BaseApp//stable --arch=aarch64 - name: Install just uses: extractions/setup-just@v2 @@ -168,6 +172,7 @@ jobs: with: name: flatpak-aarch64 path: cosmic-camera-aarch64.flatpak + if-no-files-found: error retention-days: 1 # Create the GitHub release with all artifacts diff --git a/Cross.toml b/Cross.toml new file mode 100644 index 0000000..af0f054 --- /dev/null +++ b/Cross.toml @@ -0,0 +1,20 @@ +# Cross-compilation configuration +# https://github.com/cross-rs/cross + +[target.aarch64-unknown-linux-gnu] +# Use custom Dockerfile based on Ubuntu 22.04 (which has libseat-dev) +dockerfile = "docker/Dockerfile.aarch64" + +[target.aarch64-unknown-linux-gnu.env] +passthrough = [ + "RUST_BACKTRACE" +] + +[target.riscv64gc-unknown-linux-gnu] +# Use custom Dockerfile based on Ubuntu 22.04 (which has libseat-dev) +dockerfile = "docker/Dockerfile.riscv64" + +[target.riscv64gc-unknown-linux-gnu.env] +passthrough = [ + "RUST_BACKTRACE" +] diff --git a/docker/Dockerfile.aarch64 b/docker/Dockerfile.aarch64 new file mode 100644 index 0000000..f8755d6 --- /dev/null +++ b/docker/Dockerfile.aarch64 @@ -0,0 +1,46 @@ +# Cross-compilation image for aarch64-unknown-linux-gnu +FROM ubuntu:24.04 + +ENV DEBIAN_FRONTEND=noninteractive + +# Configure apt sources: amd64 from archive.ubuntu.com, arm64 from ports.ubuntu.com +RUN rm -f /etc/apt/sources.list /etc/apt/sources.list.d/ubuntu.sources && \ + echo 'deb [arch=amd64] http://archive.ubuntu.com/ubuntu noble main universe' > /etc/apt/sources.list && \ + echo 'deb [arch=amd64] http://archive.ubuntu.com/ubuntu noble-updates main universe' >> /etc/apt/sources.list && \ + echo 'deb [arch=amd64] http://security.ubuntu.com/ubuntu noble-security main universe' >> /etc/apt/sources.list && \ + echo 'deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports noble main universe' >> /etc/apt/sources.list && \ + echo 'deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports noble-updates main universe' >> /etc/apt/sources.list && \ + echo 'deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports noble-security main universe' >> /etc/apt/sources.list + +# Install base tools (before adding arm64 architecture) +RUN apt-get update && apt-get install -y \ + curl \ + build-essential \ + pkg-config \ + && rm -rf /var/lib/apt/lists/* + +# Add arm64 architecture +RUN dpkg --add-architecture arm64 + +# Install cross-compilation toolchain and dependencies +RUN apt-get update && apt-get install -y \ + gcc-aarch64-linux-gnu \ + g++-aarch64-linux-gnu \ + libglib2.0-dev:arm64 \ + libgstreamer1.0-dev:arm64 \ + libgstreamer-plugins-base1.0-dev:arm64 \ + libgstreamer-plugins-bad1.0-dev:arm64 \ + libwayland-dev:arm64 \ + libxkbcommon-dev:arm64 \ + libinput-dev:arm64 \ + libudev-dev:arm64 \ + libseat-dev:arm64 \ + && rm -rf /var/lib/apt/lists/* + +# Set up environment for cross-compilation +ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc \ + CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc \ + CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++ \ + PKG_CONFIG_ALLOW_CROSS=1 \ + PKG_CONFIG_PATH=/usr/lib/aarch64-linux-gnu/pkgconfig:/usr/share/pkgconfig \ + PKG_CONFIG_SYSROOT_DIR=/ diff --git a/docker/Dockerfile.riscv64 b/docker/Dockerfile.riscv64 new file mode 100644 index 0000000..4fd3caa --- /dev/null +++ b/docker/Dockerfile.riscv64 @@ -0,0 +1,46 @@ +# Cross-compilation image for riscv64gc-unknown-linux-gnu +FROM ubuntu:24.04 + +ENV DEBIAN_FRONTEND=noninteractive + +# Configure apt sources: amd64 from archive.ubuntu.com, riscv64 from ports.ubuntu.com +RUN rm -f /etc/apt/sources.list /etc/apt/sources.list.d/ubuntu.sources && \ + echo 'deb [arch=amd64] http://archive.ubuntu.com/ubuntu noble main universe' > /etc/apt/sources.list && \ + echo 'deb [arch=amd64] http://archive.ubuntu.com/ubuntu noble-updates main universe' >> /etc/apt/sources.list && \ + echo 'deb [arch=amd64] http://security.ubuntu.com/ubuntu noble-security main universe' >> /etc/apt/sources.list && \ + echo 'deb [arch=riscv64] http://ports.ubuntu.com/ubuntu-ports noble main universe' >> /etc/apt/sources.list && \ + echo 'deb [arch=riscv64] http://ports.ubuntu.com/ubuntu-ports noble-updates main universe' >> /etc/apt/sources.list && \ + echo 'deb [arch=riscv64] http://ports.ubuntu.com/ubuntu-ports noble-security main universe' >> /etc/apt/sources.list + +# Install base tools (before adding riscv64 architecture) +RUN apt-get update && apt-get install -y \ + curl \ + build-essential \ + pkg-config \ + && rm -rf /var/lib/apt/lists/* + +# Add riscv64 architecture +RUN dpkg --add-architecture riscv64 + +# Install cross-compilation toolchain and dependencies +RUN apt-get update && apt-get install -y \ + gcc-riscv64-linux-gnu \ + g++-riscv64-linux-gnu \ + libglib2.0-dev:riscv64 \ + libgstreamer1.0-dev:riscv64 \ + libgstreamer-plugins-base1.0-dev:riscv64 \ + libgstreamer-plugins-bad1.0-dev:riscv64 \ + libwayland-dev:riscv64 \ + libxkbcommon-dev:riscv64 \ + libinput-dev:riscv64 \ + libudev-dev:riscv64 \ + libseat-dev:riscv64 \ + && rm -rf /var/lib/apt/lists/* + +# Set up environment for cross-compilation +ENV CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_GNU_LINKER=riscv64-linux-gnu-gcc \ + CC_riscv64gc_unknown_linux_gnu=riscv64-linux-gnu-gcc \ + CXX_riscv64gc_unknown_linux_gnu=riscv64-linux-gnu-g++ \ + PKG_CONFIG_ALLOW_CROSS=1 \ + PKG_CONFIG_PATH=/usr/lib/riscv64-linux-gnu/pkgconfig:/usr/share/pkgconfig \ + PKG_CONFIG_SYSROOT_DIR=/ diff --git a/io.github.freddyfunk.CosmicCamera.yml b/io.github.freddyfunk.CosmicCamera.yml index 0a50edf..8693edb 100644 --- a/io.github.freddyfunk.CosmicCamera.yml +++ b/io.github.freddyfunk.CosmicCamera.yml @@ -54,5 +54,6 @@ modules: - type: dir path: . - cargo-sources.json + # Note: No additional GStreamer plugins needed - app uses pipewiresrc which is # included in org.freedesktop.Platform via PipeWire's gst-plugin-pipewire diff --git a/justfile b/justfile index d8ca167..87c9e3c 100644 --- a/justfile +++ b/justfile @@ -191,6 +191,7 @@ flatpak-build: flatpak-cargo-sources # Build Flatpak bundle for distribution flatpak-bundle: flatpak-cargo-sources #!/usr/bin/env bash + set -euo pipefail echo "Building Flatpak bundle..." # Generate version file for flatpak build just get-version > .flatpak-version @@ -265,10 +266,9 @@ flatpak-deps: RUNTIME_VERSION=$(grep 'runtime-version:' {{APPID}}.yml | sed "s/.*runtime-version: *['\"]\\?\\([^'\"]*\\)['\"]\\?/\\1/") echo "Using runtime version: $RUNTIME_VERSION" flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo - flatpak remote-add --if-not-exists cosmic https://flatpak.system76.com/cosmic.flatpakrepo flatpak install -y flathub org.freedesktop.Platform//${RUNTIME_VERSION} flatpak install -y flathub org.freedesktop.Sdk//${RUNTIME_VERSION} - flatpak install -y cosmic com.system76.Cosmic.BaseApp//stable + flatpak install -y flathub com.system76.Cosmic.BaseApp//stable echo "Flatpak dependencies installed!" # Full clean (cargo + vendor + flatpak) @@ -277,10 +277,17 @@ clean-all: clean clean-vendor flatpak-clean # Build Flatpak bundle for a specific architecture (for CI) flatpak-bundle-arch arch: flatpak-cargo-sources #!/usr/bin/env bash + set -euo pipefail echo "Building Flatpak bundle for {{arch}}..." # Generate version file for flatpak build just get-version > .flatpak-version flatpak-builder --repo=repo --force-clean --arch={{arch}} build-dir {{APPID}}.yml flatpak build-bundle repo {{name}}-{{arch}}.flatpak {{APPID}} --arch={{arch}} rm -f .flatpak-version + # Verify the bundle was created + if [ ! -f "{{name}}-{{arch}}.flatpak" ]; then + echo "Error: Flatpak bundle was not created!" + exit 1 + fi echo "Flatpak bundle created: {{name}}-{{arch}}.flatpak" + ls -la {{name}}-{{arch}}.flatpak