2022-02-10 / @syui

github , rust

github actionsでrustのcross compile

opensslのerrorが出る場合はsudo apt-get install -y -qq pkg-config libssl-devするといいらしい。

windowsのbuildやuploadは、同じ内容でも、うまく行ったり行かなかったりしたので、そのうち動かなくなりそう。

name: release

on:
  push:
    tags:
      - '*'

jobs:
  build:
    name: release binary
    strategy:
      matrix:
        include:
          - os: macos-latest
            artifact_prefix: macos
            target: x86_64-apple-darwin
            artifact_name: msr
            asset_name: msr-x86_64-apple-darwin
          - os: ubuntu-latest
            artifact_prefix: linux
            target: x86_64-unknown-linux-gnu
            artifact_name: msr
            asset_name: msr-x86_64-unknown-linux-gnu
          - os: windows-latest
            artifact_prefix: windows 
            target: x86_64-pc-windows-msvc
            artifact_name: msr.exe
            asset_name: msr-x86_64-pc-windows-msvc

    runs-on: ${{ matrix.os }}

    steps:
      - uses: actions/checkout@v1
      - name: installing rust toolchain
        uses: actions-rs/toolchain@v1
        with:
            profile: minimal
            toolchain: stable
            override: true
            components: rustfmt, clippy

      - name: installing needed macos dependencies
        if: matrix.os == 'macos-latest'
        run: brew install [email protected]
      - name: installing needed ubuntu dependencies
        if: matrix.os == 'ubuntu-latest'
        run: |
          sudo apt-get update
          sudo apt-get install -y -qq pkg-config libssl-dev libxcb1-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev
          sudo apt-get install -y -qq mingw-w64          
      - name: running cargo build
        uses: actions-rs/cargo@v1
        with:
          command: build
          toolchain: ${{ matrix.rust }}
          args: --release --target ${{ matrix.target }}

      - name: upload binaries to release
        uses: svenstaro/[email protected]
        with:
          repo_token: ${{ secrets.github_token }}
          file: target/${{ matrix.target }}/release/${{ matrix.artifact_name }}
          asset_name: ${{ matrix.asset_name }}
          tag: ${{ github.ref }}
          overwrite: true