name: Cross compile BoringTun

on:
  workflow_dispatch:

jobs:
  BoringTun:
    name: Cross compile BoringTun
    runs-on: ubuntu-latest
    strategy: 
      matrix:
        target: [ aarch64-apple-darwin, x86_64-apple-darwin, s390x-unknown-linux-gnu, aarch64-unknown-linux-gnu, x86_64-unknown-linux-gnu ]
    steps:
      - name: Check code
        uses: actions/checkout@v2
      - name: Git clone BoringTun
        run: |
          git clone https://github.com/cloudflare/boringtun
          cp -r boringtun/* .
          bash <(curl -sSf https://sh.rustup.rs) -y
          $HOME/.cargo/bin/rustup target add ${{ matrix.target }}
          $HOME/.cargo/bin/rustup show
          
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          override: true
      - uses: actions-rs/cargo@v1
        with:
          use-cross: true
          command: build
          args: --release --bin boringtun-cli --all-features --target ${{ matrix.target }}
          
      - name: Archives boringtun-cli
        run: |
          tar czvf boringtun-cli_${{ matrix.target }}.tar.gz ./target/release/boringtun-cli 
          
      - name: Release binaries 
        uses: softprops/action-gh-release@v1
        with:
          tag_name: BoringTun
          files: ./boringtun-cli_${{ matrix.target }}.tar.gz
        env:
          GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
