wasmc 1.0.0

Compile .wat files into .wasm binaries
name: release

on:
  push:
    tags: ["v*"]

jobs:
  publish:
    name: crates.io
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3
        name: Checkout

      - uses: aslilac/setup@v1
        with:
          archives: |
            https://mckayla.cloud/tomlq-linux-x64.tar.gz

      - run: |
          if [ "v$(tomlq package.version -f Cargo.toml)" == "${{ github.ref_name }}" ]; then
            exit 0
          fi

          echo "tag does not match version in Cargo.toml, refusing to publish"
          exit 1

      - uses: actions/cache@v3
        name: Configure cache
        with:
          path: |
            ~/.cargo/
            ./build/
          key: publish-cargo-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: publish-cargo-

      - run: cargo test
        name: Test

      - run: cargo publish
        name: Publish
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

  release:
    strategy:
      fail-fast: false
      matrix:
        release:
          # TODO: Figure out how to "setup pkg-config for cross-compilation"
          # - os: ubuntu-latest
          #   target: aarch64-unknown-linux-gnu
          #   executable: wasmc

          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            executable: wasmc

          - os: windows-latest
            target: aarch64-pc-windows-msvc
            executable: wasmc.exe

          - os: windows-latest
            target: x86_64-pc-windows-msvc
            executable: wasmc.exe

          - os: macos-latest
            target: aarch64-apple-darwin
            executable: wasmc

          - os: macos-latest
            target: x86_64-apple-darwin
            executable: wasmc

    name: ${{ matrix.release.target }}
    runs-on: ${{ matrix.release.os }}
    needs: publish

    steps:
      - uses: actions/checkout@v3
        name: Checkout

      - uses: actions/cache@v3
        name: Configure cache
        with:
          path: |
            ~/.cargo/
            ./build/
          key: release-${{ matrix.release.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: release-${{ matrix.release.target }}-cargo-

      - run: rustup target add ${{ matrix.release.target }}
        name: Prepare — ${{ matrix.release.target }}

      - run: cargo build --target ${{ matrix.release.target }} --release
        name: Build — ${{ matrix.release.target }}

      - run: tar -a -cf wasmc-${{ github.ref_name }}-${{ matrix.release.target }}.tar.gz ${{ matrix.release.executable }}
        name: Package (tar) — ${{ matrix.release.target }}
        working-directory: ./build/${{ matrix.release.target }}/release/

      - run: zip -r wasmc-${{ github.ref_name }}-${{ matrix.release.target }}.zip ${{ matrix.release.executable }}
        name: Package (zip) — ${{ matrix.release.target }}
        working-directory: ./build/${{ matrix.release.target }}/release/
        if: ${{ !startsWith(matrix.release.os, 'windows') }}

      - run: Compress-Archive ${{ matrix.release.executable }} -DestinationPath wasmc-${{ github.ref_name }}-${{ matrix.release.target }}.zip
        name: Package (zip) — ${{ matrix.release.target }}
        working-directory: ./build/${{ matrix.release.target }}/release/
        if: ${{ startsWith(matrix.release.os, 'windows') }}

      - uses: softprops/action-gh-release@v1
        name: Publish
        with:
          files: ./build/${{ matrix.release.target }}/release/wasmc-${{ github.ref_name }}-${{ matrix.release.target }}.*

      # We don't want the archives to be stored in the cache of the build directory
      - run: rm wasmc-${{ github.ref_name }}-${{ matrix.release.target }}.*
        name: Cleanup
        working-directory: ./build/${{ matrix.release.target }}/release/