|
| 1 | +name: Build Binaries |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ master ] |
| 6 | + tags: [ 'v*' ] |
| 7 | + pull_request: |
| 8 | + branches: [ master ] |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +env: |
| 12 | + CARGO_TERM_COLOR: always |
| 13 | + |
| 14 | +jobs: |
| 15 | + build: |
| 16 | + name: Build ${{ matrix.target }} |
| 17 | + runs-on: ${{ matrix.os }} |
| 18 | + strategy: |
| 19 | + fail-fast: false |
| 20 | + matrix: |
| 21 | + include: |
| 22 | + # Linux builds (using cross for cross-compilation) |
| 23 | + - target: x86_64-unknown-linux-gnu |
| 24 | + os: ubuntu-latest |
| 25 | + use_cross: false |
| 26 | + binary_name: tobaru |
| 27 | + - target: x86_64-unknown-linux-musl |
| 28 | + os: ubuntu-latest |
| 29 | + use_cross: true |
| 30 | + binary_name: tobaru |
| 31 | + - target: aarch64-unknown-linux-gnu |
| 32 | + os: ubuntu-latest |
| 33 | + use_cross: true |
| 34 | + binary_name: tobaru |
| 35 | + - target: aarch64-unknown-linux-musl |
| 36 | + os: ubuntu-latest |
| 37 | + use_cross: true |
| 38 | + binary_name: tobaru |
| 39 | + |
| 40 | + # macOS builds (native compilation) |
| 41 | + - target: x86_64-apple-darwin |
| 42 | + os: macos-latest |
| 43 | + use_cross: false |
| 44 | + binary_name: tobaru |
| 45 | + - target: aarch64-apple-darwin |
| 46 | + os: macos-latest |
| 47 | + use_cross: false |
| 48 | + binary_name: tobaru |
| 49 | + |
| 50 | + # Windows builds |
| 51 | + # TODO: enable when working |
| 52 | + # - target: x86_64-pc-windows-msvc |
| 53 | + # os: windows-latest |
| 54 | + # use_cross: false |
| 55 | + # binary_name: tobaru.exe |
| 56 | + # - target: aarch64-pc-windows-msvc |
| 57 | + # os: windows-latest |
| 58 | + # use_cross: false |
| 59 | + # binary_name: tobaru.exe |
| 60 | + |
| 61 | + steps: |
| 62 | + - uses: actions/checkout@v4 |
| 63 | + |
| 64 | + - name: Install Rust |
| 65 | + uses: dtolnay/rust-toolchain@stable |
| 66 | + with: |
| 67 | + targets: ${{ matrix.target }} |
| 68 | + |
| 69 | + - name: Install system dependencies |
| 70 | + if: matrix.use_cross == true |
| 71 | + run: | |
| 72 | + sudo apt-get update |
| 73 | + case "${{ matrix.target }}" in |
| 74 | + "aarch64-unknown-linux-gnu") |
| 75 | + sudo apt-get install -y gcc-aarch64-linux-gnu |
| 76 | + ;; |
| 77 | + "aarch64-unknown-linux-musl") |
| 78 | + sudo apt-get install -y gcc-aarch64-linux-gnu musl-tools |
| 79 | + ;; |
| 80 | + "x86_64-unknown-linux-musl") |
| 81 | + sudo apt-get install -y musl-tools |
| 82 | + ;; |
| 83 | + esac |
| 84 | +
|
| 85 | + - name: Install cross-compilation tool |
| 86 | + if: matrix.use_cross == true |
| 87 | + run: | |
| 88 | + cargo install cross |
| 89 | +
|
| 90 | + - name: Setup cache |
| 91 | + uses: Swatinem/rust-cache@v2 |
| 92 | + with: |
| 93 | + key: ${{ matrix.target }} |
| 94 | + |
| 95 | + - name: Build binary (using cross) |
| 96 | + if: matrix.use_cross == true |
| 97 | + run: cross build --release --target ${{ matrix.target }} |
| 98 | + |
| 99 | + - name: Build binary (native) |
| 100 | + if: matrix.use_cross == false |
| 101 | + run: cargo build --release --target ${{ matrix.target }} |
| 102 | + |
| 103 | + - name: Verify binary exists |
| 104 | + run: | |
| 105 | + if [ -f "target/${{ matrix.target }}/release/${{ matrix.binary_name }}" ]; then |
| 106 | + echo "Binary found: target/${{ matrix.target }}/release/${{ matrix.binary_name }}" |
| 107 | + ls -la "target/${{ matrix.target }}/release/${{ matrix.binary_name }}" |
| 108 | +
|
| 109 | + # Show file type and architecture |
| 110 | + file "target/${{ matrix.target }}/release/${{ matrix.binary_name }}" || true |
| 111 | +
|
| 112 | + # Test the binary can be executed (for native builds only) |
| 113 | + if [[ "${{ matrix.target }}" == "x86_64-unknown-linux-gnu" ]]; then |
| 114 | + echo "Testing binary execution..." |
| 115 | + "./target/${{ matrix.target }}/release/${{ matrix.binary_name }}" --help || echo "Binary test failed, but file exists" |
| 116 | + fi |
| 117 | + else |
| 118 | + echo "Binary not found!" |
| 119 | + echo "Contents of release directory:" |
| 120 | + ls -la "target/${{ matrix.target }}/release/" || echo "Release directory doesn't exist" |
| 121 | + exit 1 |
| 122 | + fi |
| 123 | +
|
| 124 | + - name: Prepare binary (Unix) |
| 125 | + if: "!contains(matrix.os, 'windows')" |
| 126 | + run: | |
| 127 | + mkdir -p artifacts |
| 128 | + cp "target/${{ matrix.target }}/release/${{ matrix.binary_name }}" "artifacts/${{ matrix.binary_name }}" |
| 129 | +
|
| 130 | + # Strip the binary to reduce size |
| 131 | + if command -v strip &> /dev/null; then |
| 132 | + strip "artifacts/${{ matrix.binary_name }}" || echo "Strip failed, continuing..." |
| 133 | + fi |
| 134 | +
|
| 135 | + # Create tarball |
| 136 | + cd artifacts |
| 137 | + tar -czf ${{ github.event.repository.name }}-${{ matrix.target }}.tar.gz "${{ matrix.binary_name }}" |
| 138 | +
|
| 139 | + # Debug: show what files were created |
| 140 | + echo "Contents of artifacts directory:" |
| 141 | + ls -la |
| 142 | +
|
| 143 | + # Verify the tarball was created |
| 144 | + if [ -f "${{ github.event.repository.name }}-${{ matrix.target }}.tar.gz" ]; then |
| 145 | + echo "Tarball created successfully: ${{ github.event.repository.name }}-${{ matrix.target }}.tar.gz" |
| 146 | + else |
| 147 | + echo "ERROR: Tarball was not created!" |
| 148 | + exit 1 |
| 149 | + fi |
| 150 | +
|
| 151 | + rm "${{ matrix.binary_name }}" |
| 152 | +
|
| 153 | + - name: Prepare binary (Windows) |
| 154 | + if: contains(matrix.os, 'windows') |
| 155 | + shell: bash |
| 156 | + run: | |
| 157 | + mkdir -p artifacts |
| 158 | + cp "target/${{ matrix.target }}/release/${{ matrix.binary_name }}" "artifacts/${{ matrix.binary_name }}" |
| 159 | + cd artifacts |
| 160 | + 7z a ${{ github.event.repository.name }}-${{ matrix.target }}.zip "${{ matrix.binary_name }}" |
| 161 | +
|
| 162 | + - name: Verify artifacts before upload |
| 163 | + run: | |
| 164 | + echo "Checking for artifacts to upload..." |
| 165 | + ls -la artifacts/ || echo "artifacts directory not found" |
| 166 | +
|
| 167 | + # Check for expected file patterns |
| 168 | + if ls artifacts/*.tar.gz 1> /dev/null 2>&1; then |
| 169 | + echo "Found .tar.gz files:" |
| 170 | + ls -la artifacts/*.tar.gz |
| 171 | + fi |
| 172 | +
|
| 173 | + if ls artifacts/*.zip 1> /dev/null 2>&1; then |
| 174 | + echo "Found .zip files:" |
| 175 | + ls -la artifacts/*.zip |
| 176 | + fi |
| 177 | +
|
| 178 | + - name: Upload artifacts |
| 179 | + uses: actions/upload-artifact@v4 |
| 180 | + with: |
| 181 | + name: ${{ github.event.repository.name }}-${{ matrix.target }} |
| 182 | + path: | |
| 183 | + artifacts/*.tar.gz |
| 184 | + artifacts/*.zip |
| 185 | + if-no-files-found: error |
| 186 | + |
| 187 | + release: |
| 188 | + name: Create Release |
| 189 | + needs: build |
| 190 | + if: startsWith(github.ref, 'refs/tags/') |
| 191 | + runs-on: ubuntu-latest |
| 192 | + steps: |
| 193 | + - name: Download all artifacts |
| 194 | + uses: actions/download-artifact@v4 |
| 195 | + with: |
| 196 | + path: artifacts |
| 197 | + |
| 198 | + - name: List artifacts |
| 199 | + run: | |
| 200 | + echo "Downloaded artifacts:" |
| 201 | + find artifacts -type f -name "*.tar.gz" -o -name "*.zip" | sort |
| 202 | +
|
| 203 | + - name: Flatten artifacts |
| 204 | + run: | |
| 205 | + mkdir -p release-artifacts |
| 206 | + find artifacts -type f \( -name "*.tar.gz" -o -name "*.zip" \) -exec cp {} release-artifacts/ \; |
| 207 | + ls -la release-artifacts/ |
| 208 | +
|
| 209 | + - name: Create Release |
| 210 | + uses: softprops/action-gh-release@v2 |
| 211 | + with: |
| 212 | + files: release-artifacts/* |
| 213 | + draft: true |
| 214 | + generate_release_notes: true |
0 commit comments