Skip to content

wip

wip #27

Workflow file for this run

name: Rust
on:
push:
branches: [ "master" ]
tags: [ "**" ]
pull_request:
branches: [ "master" ]
env:
CARGO_TERM_COLOR: always
BUILD_ARGS: "--bin chip-8-emu-bin --release"
SDL_VIDEODRIVER: "dummy"
SDL_AUDIODRIVER: "disk"
jobs:
build:
name: Build - ${{ matrix.platform.name }}
# By default, runs on Ubuntu, otherwise, override with the desired os
runs-on: ${{ matrix.platform.os || 'ubuntu-latest' }}
strategy:
matrix:
platform:
# Linux
- name: Linux x86_64
target: x86_64-unknown-linux-gnu
- name: Linux aarch64
target: aarch64-unknown-linux-gnu
use-cross: true
# Mac OS
- name: MacOS x86_64
os: macos-latest
target: x86_64-apple-darwin
- name: MacOS aarch64
os: macos-latest
target: aarch64-apple-darwin
# Windows
- name: Windows x86_64
# Use another GitHub action OS
os: windows-latest
target: x86_64-pc-windows-msvc
steps:
- uses: actions/checkout@v4
- name: Set up cargo cache
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ matrix.platform.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ matrix.platform.target }}-cargo-
- name: Install Linux Deps
run: |
sudo apt-get install -yqq alsa libasound2-dev libfontconfig1-dev
if: ${{ endsWith(matrix.platform.target, 'linux-gnu') && !matrix.platform.use-cross }}
- name: Install ${{ matrix.platform.target }} Toolchain
run: rustup target add ${{ matrix.platform.target }}
- name: Build ${{ matrix.platform.name }} binary
uses: actions-rs/cargo@v1
with:
command: build
use-cross: ${{ matrix.platform.use-cross }}
args: ${{ env.BUILD_ARGS }} --target ${{ matrix.platform.target }}
- name: Rename binary
run: |
mv target/${{ matrix.platform.target }}/release/chip-8-emu-bin${{ contains(matrix.platform.target, 'windows') && '.exe' || '' }} \
chip-8-emu-bin.${{ matrix.platform.target }}${{ contains(matrix.platform.target, 'windows') && '.exe' || '' }}
shell: bash
- name: Upload ${{ matrix.platform.name }} binary
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.platform.target }}
path: chip-8-emu-bin.${{ matrix.platform.target }}${{ contains(matrix.platform.target, 'windows') && '.exe' || '' }}
build-web:
name: Build - Web
# By default, runs on Ubuntu, otherwise, override with the desired os
runs-on: 'ubuntu-latest'
env:
CARGO_INSTALLS: |
wasm-pack
steps:
- uses: actions/checkout@v4
- name: Set up cargo cache
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: web-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: web-cargo-
- name: Set up cargo install cache
uses: actions/cache@v4
with:
path: installs
key: |
web-installs
${{ env.CARGO_INSTALLS }}
restore-keys: web-installs
- name: Install cargo dependencies
run: |
while IFS= read -r package; do
if [ "$package" != "" ]; then
cargo install "$package" --target-dir "installs/$package" || true
fi;
done <<< "$CARGO_INSTALLS"
- name: Install wasm32-unknown-unknown Toolchain
run: rustup target add wasm32-unknown-unknown
- name: Build wasm bundle
run: wasm-pack build --target bundler
- name: Pack wasm bundle
run: |
cd pkg
npm pack
cd -
- name: Rename binary
run: |
mv pkg/chip-8-emu-*.tgz \
chip-8-emu.wasm32-unknown-unknown.tgz
- name: Upload web bundle
uses: actions/upload-artifact@v4
with:
name: wasm32-unknown-unknown
path: chip-8-emu.wasm32-unknown-unknown.tgz
release:
name: Release
runs-on: 'ubuntu-latest'
if: ${{ startsWith(github.ref, 'refs/tags/') }}
needs: [ 'build', 'build-web' ]
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true
- name: Create release
uses: softprops/action-gh-release@v2
with:
files: artifacts/**