diff --git a/.gitea/workflows/release.yaml b/.gitea/workflows/release.yaml index 6be5917..78e6229 100644 --- a/.gitea/workflows/release.yaml +++ b/.gitea/workflows/release.yaml @@ -7,60 +7,149 @@ on: env: TARGET: thumbv8m.main-none-eabihf + # The catthehacker image installs rust here and only symlinks ~/.rustup and ~/.cargo to it. + # actions/cache archives the symlink, not its contents, so point at the real paths. + RUSTUP_HOME: /usr/share/rust/.rustup + CARGO_HOME: /usr/share/rust/.cargo jobs: - build-and-release: + firmware: runs-on: ubuntu-latest container: - image: catthehacker/ubuntu:act-latest - defaults: - run: - shell: bash + image: catthehacker/ubuntu:rust-latest + strategy: + fail-fast: true + matrix: + variant: [cs4398, ak4490, evk] + env: + FEATURES: ${{ matrix.variant }},hid steps: - name: Checkout repository uses: actions/checkout@v4 + - name: Cache rustup + uses: actions/cache@v4 + with: + path: ${{ env.RUSTUP_HOME }} + key: rustup-firmware-${{ env.TARGET }}-${{ runner.os }} + - name: Install Rust Toolchain - uses: dtolnay/rust-toolchain@stable - - name: Install cargo-binutils - run: cargo install cargo-binutils - - name: Build Firmware Binaries run: | - cd firmware + rustup target install ${{ env.TARGET }} + rustup component add llvm-tools - # Array of "variant_name:features" - VARIANTS=( - "cs4398:cs4398,hid" - "ak4490:ak4490,hid" - "evk:evk,hid" - ) + - name: Cache cargo + uses: Swatinem/rust-cache@v2 + with: + shared-key: firmware-${{ matrix.variant }} - mkdir -p ../dist + - name: Install cargo-binutils + run: cargo binstall -y --locked cargo-binutils - for entry in "${VARIANTS[@]}"; do - IFS=":" read -r name features <<< "$entry" - echo "Building variant: $name with features: $features" + - name: Build firmware (${{ matrix.variant }}) + working-directory: firmware + run: cargo build --release --target ${{ env.TARGET }} --no-default-features --features "${{ env.FEATURES }}" - # 1. Compile release binary - cargo build --release --target ${{ env.TARGET }} --no-default-features --features "$features" + - name: Create hex file + working-directory: firmware + run: cargo objcopy --release --target ${{ env.TARGET }} --no-default-features --features "${{ env.FEATURES }}" -- -O ihex ../target/${{ env.TARGET }}/release/guac-${{ matrix.variant }}.hex - # 2. Paths setup - ELF_PATH="../target/${{ env.TARGET }}/release/guac" - HEX_PATH="../target/${{ env.TARGET }}/release/guac-${name}.hex" - RENAMED_ELF="../target/${{ env.TARGET }}/release/guac-${name}.elf" + - name: Package + run: | + out=target/${{ env.TARGET }}/release + cp "$out/guac" "$out/guac-${{ matrix.variant }}.elf" + mkdir -p dist + zip -j "dist/guac-firmware-${{ matrix.variant }}.zip" "$out/guac-${{ matrix.variant }}.elf" "$out/guac-${{ matrix.variant }}.hex" - # 3. Create .hex file via rust-objcopy - cargo objcopy --release --target ${{ env.TARGET }} --no-default-features --features "$features" -- -O ihex "$HEX_PATH" - cp "$ELF_PATH" "$RENAMED_ELF" + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: firmware-${{ matrix.variant }} + path: dist/*.zip - # 4. Package ELF and HEX into target-specific ZIP - ZIP_NAME="guac-firmware-${name}.zip" - zip -j "../dist/${ZIP_NAME}" "$RENAMED_ELF" "$HEX_PATH" - done + cli: + runs-on: ubuntu-latest + container: + image: catthehacker/ubuntu:rust-latest + strategy: + fail-fast: true + matrix: + target: + - aarch64-unknown-linux-musl + - x86_64-pc-windows-gnu + - x86_64-unknown-linux-musl + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Cache rustup + uses: actions/cache@v4 + with: + path: ${{ env.RUSTUP_HOME }} + key: rustup-cli-${{ matrix.target }}-${{ runner.os }} + + - name: Install Rust Toolchain + run: rustup target install ${{ matrix.target }} + + - name: Cache cargo + uses: Swatinem/rust-cache@v2 + with: + shared-key: cli-${{ matrix.target }} + + - name: Cache zigbuild install + uses: actions/cache@v4 + with: + path: /opt/zigvenv + key: zigbuild-venv-${{ runner.os }} + + # compiled libc/compiler-rt are per target, so these stay keyed on it + - name: Cache zig build artifacts + uses: actions/cache@v4 + with: + path: | + ~/.cache/zig + ~/.cache/cargo-zigbuild + key: zigbuild-cache-${{ matrix.target }}-${{ runner.os }} + + - name: Install cargo-zigbuild Toolchain + run: | + # venv keeps cargo-zigbuild and ziglang in one relocatable-by-path directory we can cache + [ -d /opt/zigvenv ] || python3 -m venv /opt/zigvenv + /opt/zigvenv/bin/pip install cargo-zigbuild + echo /opt/zigvenv/bin >> "$GITHUB_PATH" + + - name: Build cli (${{ matrix.target }}) + working-directory: cli + run: cargo zigbuild --release --target ${{ matrix.target }} + + - name: Package + run: | + bin=cli + [[ "${{ matrix.target }}" == *windows* ]] && bin=cli.exe + mkdir -p dist + zip -j "dist/guac-cli-${{ matrix.target }}.zip" "target/${{ matrix.target }}/release/$bin" + shell: bash + + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: cli-${{ matrix.target }} + path: dist/*.zip + + release: + needs: [firmware, cli] + runs-on: ubuntu-latest + container: + image: catthehacker/ubuntu:act-latest + steps: + - name: Download artifacts + uses: actions/download-artifact@v3 + with: + path: dist - name: Create Gitea Release uses: akkuman/gitea-release-action@v1 with: - files: dist/*.zip + files: dist/**/*.zip draft: false prerelease: false