diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 1b41fb3..e80efb3 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -7,69 +7,47 @@ on: jobs: build: + name: Build ${{ matrix.target }} runs-on: ubuntu-latest - container: - image: ubuntu:22.04 + # A matrix lets us run the job twice in parallel: once for x86, once for arm. + strategy: + matrix: + include: + - target: x86_64-unknown-linux-gnu + use-cross: false + - target: aarch64-unknown-linux-gnu + use-cross: true steps: - # ========================= - # 1. system dependencies - # ========================= - - name: install system deps - run: | - apt-get update - apt-get install -y \ - git curl ca-certificates build-essential - - # ========================= - # 2. install Rust (user-space, correct PATH) - # ========================= - - name: install rust - run: | - curl https://sh.rustup.rs -sSf | sh -s -- -y - echo "$HOME/.cargo/bin" >> $GITHUB_PATH - . "$HOME/.cargo/env" - rustc --version - cargo --version - - # ========================= - # 3. checkout (NOW works because git exists) - # ========================= - - name: checkout + - name: Checkout repository uses: actions/checkout@v4 - # ========================= - # 4. install cross - # ========================= - - name: install cross - run: | - . "$HOME/.cargo/env" - cargo install cross --locked + # Sets up Rust correctly and caches it + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + targets: ${{ matrix.target }} - # ========================= - # 5. build x86_64 - # ========================= - - name: build x86_64 - run: | - . "$HOME/.cargo/env" - cargo build --release --target x86_64-unknown-linux-gnu + # Downloads pre-compiled `cross` binary instantly (saves ~3 mins vs cargo install) + - name: Install cross + if: matrix.use-cross == true + uses: taiki-e/install-action@v2 + with: + tool: cross - # ========================= - # 6. build ARM64 via cross - # ========================= - - name: build arm64 + # Builds using cargo for x86, and cross for ARM + - name: Build binary run: | - . "$HOME/.cargo/env" - cross build --release --target aarch64-unknown-linux-gnu + if [ "${{ matrix.use-cross }}" == "true" ]; then + cross build --release --target ${{ matrix.target }} + else + cargo build --release --target ${{ matrix.target }} + fi - # ========================= - # 7. upload artifacts - # ========================= - - name: upload artifacts + # Uploads the artifact. They will be separated by target name. + - name: Upload artifacts uses: actions/upload-artifact@v4 with: - name: escape-room-binaries - path: | - target/x86_64-unknown-linux-gnu/release/escape_room_server - target/aarch64-unknown-linux-gnu/release/escape_room_server + name: escape-room-server-${{ matrix.target }} + path: target/${{ matrix.target }}/release/escape_room_server