aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/build.yml
blob: 788f7e833db8c6b72328ad71ddc9596e6a02d113 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
name: Build and Release

on:
  push:
    branches: [ main, master ]
    tags: [ 'v*' ]
  pull_request:
    branches: [ main, master ]

env:
  CARGO_TERM_COLOR: always

jobs:
  build:
    name: Build ${{ matrix.target }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          # Windows
          - target: x86_64-pc-windows-msvc
            os: windows-latest
            ext: .exe
            name: mikusays-windows-x64.exe
          - target: i686-pc-windows-msvc
            os: windows-latest
            ext: .exe
            name: mikusays-windows-x86.exe
          - target: aarch64-pc-windows-msvc
            os: windows-latest
            ext: .exe
            name: mikusays-windows-arm64.exe
          
          # Linux
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
            ext: ""
            name: mikusays-linux-x64
          - target: i686-unknown-linux-gnu
            os: ubuntu-latest
            ext: ""
            name: mikusays-linux-x86
          - target: aarch64-unknown-linux-gnu
            os: ubuntu-latest
            ext: ""
            name: mikusays-linux-arm64
          - target: armv7-unknown-linux-gnueabihf
            os: ubuntu-latest
            ext: ""
            name: mikusays-linux-armv7
          
          # macOS
          - target: x86_64-apple-darwin
            os: macos-latest
            ext: ""
            name: mikusays-macos-x64
          - target: aarch64-apple-darwin
            os: macos-latest
            ext: ""
            name: mikusays-macos-arm64

    steps:
    - name: Checkout code
      uses: actions/checkout@v4

    - name: Install Rust
      uses: dtolnay/rust-toolchain@stable
      with:
        targets: ${{ matrix.target }}

    - name: Install cross-compilation tools (Linux)
      if: matrix.os == 'ubuntu-latest'
      run: |
        sudo apt-get update
        sudo apt-get install -y gcc-multilib
        if [[ "${{ matrix.target }}" == "aarch64-unknown-linux-gnu" ]]; then
          sudo apt-get install -y gcc-aarch64-linux-gnu
        fi
        if [[ "${{ matrix.target }}" == "armv7-unknown-linux-gnueabihf" ]]; then
          sudo apt-get install -y gcc-arm-linux-gnueabihf
        fi
        if [[ "${{ matrix.target }}" == "i686-unknown-linux-gnu" ]]; then
          sudo apt-get install -y gcc-multilib
        fi

    - name: Cache cargo registry
      uses: actions/cache@v3
      with:
        path: ~/.cargo/registry
        key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}

    - name: Cache cargo index
      uses: actions/cache@v3
      with:
        path: ~/.cargo/git
        key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}

    - name: Cache cargo build
      uses: actions/cache@v3
      with:
        path: target
        key: ${{ runner.os }}-cargo-build-target-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}

    - name: Configure cross-compilation environment
      shell: bash
      run: |
        case "${{ matrix.target }}" in
          aarch64-unknown-linux-gnu)
            echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
            ;;
          armv7-unknown-linux-gnueabihf)
            echo "CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc" >> $GITHUB_ENV
            ;;
        esac

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

    - name: Strip binary (Unix)
      if: matrix.os != 'windows-latest'
      run: |
        case "${{ matrix.target }}" in
          aarch64-unknown-linux-gnu)
            aarch64-linux-gnu-strip target/${{ matrix.target }}/release/mikusays
            ;;
          armv7-unknown-linux-gnueabihf)
            arm-linux-gnueabihf-strip target/${{ matrix.target }}/release/mikusays
            ;;
          *)
            strip target/${{ matrix.target }}/release/mikusays
            ;;
        esac

    - name: Prepare artifact
      shell: bash
      run: |
        mkdir -p artifacts
        if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
          cp target/${{ matrix.target }}/release/mikusays.exe artifacts/${{ matrix.name }}
        else
          cp target/${{ matrix.target }}/release/mikusays artifacts/${{ matrix.name }}
        fi

    - name: Upload artifact
      uses: actions/upload-artifact@v3
      with:
        name: ${{ matrix.name }}
        path: artifacts/${{ matrix.name }}

  release:
    name: Create Release
    runs-on: ubuntu-latest
    needs: build
    if: startsWith(github.ref, 'refs/tags/')
    steps:
    - name: Checkout code
      uses: actions/checkout@v4

    - name: Download all artifacts
      uses: actions/download-artifact@v3
      with:
        path: artifacts

    - name: Prepare release assets
      run: |
        mkdir -p release-assets
        find artifacts -type f -executable -o -name "*.exe" | while read file; do
          cp "$file" release-assets/
        done
        # List files for debugging
        ls -la release-assets/

    - name: Create Release
      uses: softprops/action-gh-release@v1
      with:
        files: release-assets/*
        draft: false
        prerelease: false
        generate_release_notes: true
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}