diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml new file mode 100644 index 0000000..1aa705d --- /dev/null +++ b/.github/workflows/rust.yml @@ -0,0 +1,89 @@ +name: Rust + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +env: + RELEASE_BIN: favicon + RELEASE_DIR: artifacts + CARGO_TERM_COLOR: always + GITHUB_REF: '${{ github.ref }}' + WINDOWS_TARGET: x86_64-pc-windows-msvc + MACOS_TARGET: x86_64-apple-darwin + MACOS_SILICON_TARGET: aarch64-apple-darwin + LINUX_AMD64_TARGET: x86_64-unknown-linux-musl + LINUX_ARM64_TARGET: aarch64-unknown-linux-musl + +jobs: + build: + name: Build artifacts + runs-on: ${{ matrix.os }} + strategy: + matrix: + include: + - target: x86_64-unknown-linux-musl + os: ubuntu-latest + rust: stable + - target: aarch64-unknown-linux-musl + os: ubuntu-latest + rust: stable + - target: x86_64-apple-darwin + os: macos-latest + rust: stable + - target: aarch64-apple-darwin + os: macos-latest + rust: stable + - target: x86_64-pc-windows-msvc + os: windows-latest + rust: stable + + steps: + - uses: actions/checkout@v3 + - name: Install C compilation tooling (Linux) + if: matrix.os == 'ubuntu-latest' + run: | + sudo apt-get update -y + sudo apt-get install clang gcc-aarch64-linux-gnu -y + echo "TARGET_CC=clang" >> $GITHUB_ENV + echo "CFLAGS_aarch64_unknown_linux_musl=--sysroot=/usr/aarch64-linux-gnu" >> $GITHUB_ENV + echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=/usr/aarch64-linux-gnu/bin/ld" >> $GITHUB_ENV + - name: Install p7zip (MacOS) + if: matrix.os == 'macos-latest' + run: brew install p7zip + + - name: Add rustup target + run: rustup target add ${{ matrix.target }} + - name: Build + run: cargo build --release --target ${{ matrix.target }} + - name: Set RUSTFLAGS (Windows) + if: matrix.os == 'windows-latest' + run: echo "RUSTFLAGS=-Ctarget-feature=+crt-static" >> $GITHUB_ENV + + - name: Create artifact directory + run: | + mkdir ${{ env.RELEASE_DIR }} + mkdir -p ${{ env.RELEASE_DIR }}/${{ env.RELEASE_BIN }}-${{ steps.get_version.outputs.VERSION }}-${{ matrix.target }} + - name: Move binaries (Linux/MacOS) + if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest' + run: | + mv ./target/${{ matrix.target }}/release/${{ env.RELEASE_BIN }} ${{ env.RELEASE_DIR }}/${{ env.RELEASE_BIN }}-${{ steps.get_version.outputs.VERSION }}-${{ matrix.target }}/${{ env.RELEASE_BIN }} + mv ${{ env.RELEASE_ADDS }} ./${{ env.RELEASE_DIR }}/${{ env.RELEASE_BIN }}-${{ steps.get_version.outputs.VERSION }}-${{ matrix.target }} + - name: Move binaries (Windows) + if: matrix.os == 'windows-latest' + shell: bash + run: | + cp ./target/${{ matrix.target }}/release/${{ env.RELEASE_BIN }}.exe ./${{ env.RELEASE_DIR }}/${{ env.RELEASE_BIN }}-${{ steps.get_version.outputs.VERSION }}-${{ matrix.target }}/${{ env.RELEASE_BIN }}.exe + mv ${{ env.RELEASE_ADDS }} ./${{ env.RELEASE_DIR }}/${{ env.RELEASE_BIN }}-${{ steps.get_version.outputs.VERSION }}-${{ matrix.target }} + - name: Create tarball + shell: bash + run: 7z a -ttar -so -an ./${{ env.RELEASE_DIR }}/${{ env.RELEASE_BIN }}-${{ steps.get_version.outputs.VERSION }}-${{ matrix.target }} | 7z a -si ./${{ env.RELEASE_DIR }}/${{ env.RELEASE_BIN }}-${{ steps.get_version.outputs.VERSION }}-${{ matrix.target }}.tar.gz + + - name: Upload Zip + uses: actions/upload-artifact@v1 + with: + name: ${{ matrix.target }} + path: ./${{ env.RELEASE_DIR }} +