optimize release profile executable size #35
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
push: | |
branches: | |
- main | |
tags: | |
- v* | |
pull_request: | |
permissions: | |
contents: read | |
defaults: | |
run: | |
shell: bash --noprofile --norc -euxo pipefail {0} | |
jobs: | |
test: | |
runs-on: ${{ matrix.runs-on }} | |
strategy: | |
fail-fast: false | |
matrix: | |
runs-on: [ubuntu-latest, macos-latest, windows-latest] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Cache dependencies | |
uses: Swatinem/rust-cache@v2 | |
- name: Build | |
run: cargo build | |
- name: Clippy | |
run: cargo clippy | |
- name: Test | |
run: cargo test | |
- name: Run | |
run: cargo run | |
build: | |
needs: test | |
runs-on: ${{ matrix.runs-on }} | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [linux, darwin, windows] | |
arch: [amd64, arm64] | |
include: | |
- os: linux | |
arch: amd64 | |
runs-on: ubuntu-latest | |
target: x86_64-unknown-linux-gnu | |
- os: linux | |
arch: arm64 | |
runs-on: ubuntu-latest | |
target: aarch64-unknown-linux-gnu | |
- os: darwin | |
arch: amd64 | |
runs-on: macos-latest | |
target: x86_64-apple-darwin | |
- os: darwin | |
arch: arm64 | |
runs-on: macos-latest | |
target: aarch64-apple-darwin | |
- os: windows | |
arch: amd64 | |
runs-on: windows-latest | |
target: x86_64-pc-windows-msvc | |
- os: windows | |
arch: arm64 | |
runs-on: windows-latest | |
target: aarch64-pc-windows-msvc | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Install target toolchain | |
if: matrix.arch == 'arm64' | |
run: | | |
rustup target add ${{ matrix.target }} | |
if [[ ${{ matrix.os }} == linux ]]; then | |
sudo apt-get install gcc-aarch64-linux-gnu | |
echo "RUSTFLAGS=-C linker=aarch64-linux-gnu-gcc" >> "$GITHUB_ENV" | |
fi | |
- name: Cache dependencies | |
uses: Swatinem/rust-cache@v2 | |
- name: Build | |
run: cargo build --release --target=${{ matrix.target }} | |
- name: Set executable name | |
id: executable | |
run: echo name=${{ github.event.repository.name }} >> "$GITHUB_OUTPUT" | |
- name: Run | |
if: matrix.arch == 'amd64' | |
run: target/${{ matrix.target }}/release/${{ steps.executable.outputs.name }} | |
- name: Set artifact name | |
id: artifact | |
run: echo name=${{ steps.executable.outputs.name }}_${{ startsWith(github.ref, 'refs/tags/v') && github.ref_name || | |
github.event.pull_request.head.sha || github.sha }}_${{ matrix.os }}_${{ matrix.arch }} >> "$GITHUB_OUTPUT" | |
- name: Build artifact | |
run: | | |
mkdir ${{ steps.artifact.outputs.name }} | |
cp README.md LICENSE target/${{ matrix.target }}/release/${{ steps.executable.outputs.name }} ${{ steps.artifact.outputs.name }} | |
if [[ ${{ matrix.os }} == windows ]]; then | |
powershell Compress-Archive -Path ${{ steps.artifact.outputs.name }} -DestinationPath ${{ steps.artifact.outputs.name }}.zip | |
else | |
zip -r ${{ steps.artifact.outputs.name }}.zip ${{ steps.artifact.outputs.name }} | |
fi | |
- name: Upload artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ steps.artifact.outputs.name }} | |
path: ${{ steps.artifact.outputs.name }}.zip | |
release: | |
needs: build | |
if: startsWith(github.ref, 'refs/tags/v') | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- name: Download artifacts | |
uses: actions/download-artifact@v3 | |
- name: Create release | |
uses: ncipollo/release-action@v1 | |
with: | |
name: Release ${{ github.ref_name }} | |
artifacts: '*/*.zip' |