|
| 1 | +name: Build |
| 2 | + |
| 3 | +env: |
| 4 | + MIN_SUPPORTED_RUST_VERSION: "1.46.0" |
| 5 | + CICD_INTERMEDIATES_DIR: "_cicd-intermediates" |
| 6 | + |
| 7 | +on: |
| 8 | + push: |
| 9 | + tags: |
| 10 | + - '*' |
| 11 | + |
| 12 | +jobs: |
| 13 | + build: |
| 14 | + name: ${{ matrix.job.target }} (${{ matrix.job.os }}) |
| 15 | + runs-on: ${{ matrix.job.os }} |
| 16 | + strategy: |
| 17 | + fail-fast: false |
| 18 | + matrix: |
| 19 | + job: |
| 20 | + # Tier 1 |
| 21 | + - { target: aarch64-unknown-linux-gnu , os: ubuntu-20.04, use-cross: true } |
| 22 | + # Need to find a way to install gcc |
| 23 | + # - { target: i686-pc-windows-gnu , os: windows-2019 } |
| 24 | + - { target: i686-pc-windows-msvc , os: windows-2019 } |
| 25 | + - { target: i686-unknown-linux-gnu , os: ubuntu-20.04, use-cross: true } |
| 26 | + - { target: x86_64-apple-darwin , os: macos-10.15 } |
| 27 | + - { target: x86_64-pc-windows-gnu , os: windows-2019 } |
| 28 | + - { target: x86_64-pc-windows-msvc , os: windows-2019 } |
| 29 | + - { target: x86_64-unknown-linux-gnu , os: ubuntu-20.04 } |
| 30 | + # Tier 2 with Host Tools |
| 31 | + - { target: aarch64-apple-darwin , os: macos-11.0 } |
| 32 | + - { target: aarch64-pc-windows-msvc , os: windows-2019 } |
| 33 | + - { target: aarch64-unknown-linux-musl , os: ubuntu-20.04, use-cross: true } |
| 34 | + - { target: arm-unknown-linux-gnueabi , os: ubuntu-20.04, use-cross: true } |
| 35 | + - { target: arm-unknown-linux-gnueabihf , os: ubuntu-20.04, use-cross: true } |
| 36 | + - { target: armv7-unknown-linux-gnueabihf , os: ubuntu-20.04, use-cross: true } |
| 37 | + - { target: mips-unknown-linux-gnu , os: ubuntu-20.04, use-cross: true } |
| 38 | + - { target: mips64-unknown-linux-gnuabi64 , os: ubuntu-20.04, use-cross: true } |
| 39 | + - { target: mips64el-unknown-linux-gnuabi64, os: ubuntu-20.04, use-cross: true } |
| 40 | + - { target: mipsel-unknown-linux-gnu , os: ubuntu-20.04, use-cross: true } |
| 41 | + - { target: powerpc-unknown-linux-gnu , os: ubuntu-20.04, use-cross: true } |
| 42 | + # powerpc64 unknown linux gnu doesn't work |
| 43 | + # - { target: powerpc64-unknown-linux-gnu , os: ubuntu-20.04, use-cross: true } |
| 44 | + - { target: powerpc64le-unknown-linux-gnu , os: ubuntu-20.04, use-cross: true } |
| 45 | + - { target: riscv64gc-unknown-linux-gnu , os: ubuntu-20.04, use-cross: true } |
| 46 | + - { target: s390x-unknown-linux-gnu , os: ubuntu-20.04, use-cross: true } |
| 47 | + # freebsd doesn't work |
| 48 | + # - { target: x86_64-unknown-freebsd , os: ubuntu-20.04, use-cross: true } |
| 49 | + # illumos doesn't work. |
| 50 | + # - { target: x86_64-unknown-illumos , os: ubuntu-20.04, use-cross: true } |
| 51 | + # - { target: arm-unknown-linux-musleabihf , os: ubuntu-20.04, use-cross: true } |
| 52 | + - { target: i686-unknown-linux-musl , os: ubuntu-20.04, use-cross: true } |
| 53 | + - { target: x86_64-unknown-linux-musl , os: ubuntu-20.04, use-cross: true } |
| 54 | + - { target: x86_64-unknown-netbsd , os: ubuntu-20.04, use-cross: true } |
| 55 | + # Tier 2 |
| 56 | + # - { target: aarch64-apple-ios , os: macos-11 } |
| 57 | + # - { target: aarch64-apple-ios-sim , os: macos-11 } |
| 58 | + # - { target: aarch64-fuchsia , os: ubuntu-20.04, use-cross: true } |
| 59 | + # - { target: aarch64-linux-android , os: ubuntu-20.04, use-cross: true } |
| 60 | + # - { target: aarch64-unknown-none-softfloat , os: ubuntu-20.04, use-cross: true } |
| 61 | + # - { target: aarch64-unknown-none , os: ubuntu-20.04, use-cross: true } |
| 62 | + # - { target: arm-linux-androideabi , os: ubuntu-20.04, use-cross: true } |
| 63 | + # - { target: arm-unknown-linux-musleabi , os: ubuntu-20.04, use-cross: true } |
| 64 | + # - { target: arm-unknown-linux-musleabihf , os: ubuntu-20.04, use-cross: true } |
| 65 | + # - { target: armebv7r-none-eabi , os: ubuntu-20.04, use-cross: true } |
| 66 | + # - { target: armebv7r-none-eabihf , os: ubuntu-20.04, use-cross: true } |
| 67 | + # - { target: armv5te-unknown-linux-gnueabi , os: ubuntu-20.04, use-cross: true } |
| 68 | + # - { target: armv5te-unknown-linux-musleabi , os: ubuntu-20.04, use-cross: true } |
| 69 | + # - { target: armv7-linux-androideabi , os: ubuntu-20.04, use-cross: true } |
| 70 | + # - { target: armv7-unknown-linux-gnueabi , os: ubuntu-20.04, use-cross: true } |
| 71 | + # - { target: armv7-unknown-linux-musleabi , os: ubuntu-20.04, use-cross: true } |
| 72 | + # - { target: armv7-unknown-linux-musleabihf , os: ubuntu-20.04, use-cross: true } |
| 73 | + # - { target: armv7a-none-eabi , os: ubuntu-20.04, use-cross: true } |
| 74 | + # - { target: armv7r-none-eabi , os: ubuntu-20.04, use-cross: true } |
| 75 | + # - { target: armv7r-none-eabihf , os: ubuntu-20.04, use-cross: true } |
| 76 | + # |
| 77 | + # - { target: x86_64-fortanix-unknown-sgx , os: ubuntu-20.04, use-cross: true } |
| 78 | + # - { target: x86_64-fuchsia , os: ubuntu-20.04, use-cross: true } |
| 79 | + # - { target: x86_64-linux-android , os: ubuntu-20.04, use-cross: true } |
| 80 | + # - { target: x86_64-pc-solaris , os: ubuntu-20.04, use-cross: true } |
| 81 | + # - { target: x86_64-unknown-linux-gnux32 , os: ubuntu-20.04, use-cross: true } |
| 82 | + # - { target: x86_64-unknown-redox , os: ubuntu-20.04, use-cross: true } |
| 83 | + # Tier 3 |
| 84 | + |
| 85 | + steps: |
| 86 | + - name: Checkout source code |
| 87 | + uses: actions/checkout@v2 |
| 88 | + |
| 89 | + - name: Install prerequisites |
| 90 | + shell: bash |
| 91 | + run: | |
| 92 | + case ${{ matrix.job.target }} in |
| 93 | + arm-unknown-linux-*) sudo apt-get -y update ; sudo apt-get -y install gcc-arm-linux-gnueabihf ;; |
| 94 | + aarch64-unknown-linux-gnu) sudo apt-get -y update ; sudo apt-get -y install gcc-aarch64-linux-gnu ;; |
| 95 | + esac |
| 96 | +
|
| 97 | + - name: Extract crate information |
| 98 | + shell: bash |
| 99 | + run: | |
| 100 | + echo "PROJECT_NAME=${{ github.event.repository.name }}" >> $GITHUB_ENV |
| 101 | + echo "PROJECT_VERSION=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n1)" >> $GITHUB_ENV |
| 102 | + echo "PROJECT_MAINTAINER=$(sed -n 's/^authors = \["\(.*\)"\]/\1/p' Cargo.toml)" >> $GITHUB_ENV |
| 103 | + echo "PROJECT_HOMEPAGE=$(sed -n 's/^homepage = "\(.*\)"/\1/p' Cargo.toml)" >> $GITHUB_ENV |
| 104 | +
|
| 105 | + - name: Install Rust toolchain |
| 106 | + uses: actions-rs/toolchain@v1 |
| 107 | + with: |
| 108 | + toolchain: stable |
| 109 | + target: ${{ matrix.job.target }} |
| 110 | + override: true |
| 111 | + profile: minimal # minimal component installation (ie, no documentation) |
| 112 | + |
| 113 | + - name: Show version information (Rust, cargo, GCC) |
| 114 | + shell: bash |
| 115 | + run: | |
| 116 | + gcc --version || true |
| 117 | + rustup -V |
| 118 | + rustup toolchain list |
| 119 | + rustup default |
| 120 | + cargo -V |
| 121 | + rustc -V |
| 122 | +
|
| 123 | + - name: Build |
| 124 | + uses: actions-rs/cargo@v1 |
| 125 | + with: |
| 126 | + use-cross: ${{ matrix.job.use-cross }} |
| 127 | + command: build |
| 128 | + args: --locked --release --target=${{ matrix.job.target }} |
| 129 | + |
| 130 | + - name: Strip debug information from executable |
| 131 | + id: strip |
| 132 | + shell: bash |
| 133 | + run: | |
| 134 | + # Figure out suffix of binary |
| 135 | + EXE_suffix="" |
| 136 | + case ${{ matrix.job.target }} in |
| 137 | + *-pc-windows-*) EXE_suffix=".exe" ;; |
| 138 | + esac; |
| 139 | +
|
| 140 | + # Figure out what strip tool to use if any |
| 141 | + STRIP="strip" |
| 142 | + case ${{ matrix.job.target }} in |
| 143 | + arm-unknown-linux-*) STRIP="arm-linux-gnueabihf-strip" ;; |
| 144 | + aarch64-pc-*) STRIP="" ;; |
| 145 | + aarch64-unknown-*) STRIP="" ;; |
| 146 | + armv7-unknown-*) STRIP="" ;; |
| 147 | + mips-unknown-*) STRIP="" ;; |
| 148 | + mips64-unknown-*) STRIP="" ;; |
| 149 | + mips64el-unknown-*) STRIP="" ;; |
| 150 | + mipsel-unknown-*) STRIP="" ;; |
| 151 | + powerpc-unknown-*) STRIP="" ;; |
| 152 | + powerpc64-unknown-*) STRIP="" ;; |
| 153 | + powerpc64le-unknown-*) STRIP="" ;; |
| 154 | + riscv64gc-unknown-*) STRIP="" ;; |
| 155 | + s390x-unknown-*) STRIP="" ;; |
| 156 | + x86_64-unknown-freebsd) STRIP="" ;; |
| 157 | + x86_64-unknown-illumos) STRIP="" ;; |
| 158 | + esac; |
| 159 | +
|
| 160 | + # Setup paths |
| 161 | + BIN_DIR="${{ env.CICD_INTERMEDIATES_DIR }}/stripped-release-bin/" |
| 162 | + mkdir -p "${BIN_DIR}" |
| 163 | + BIN_NAME="${{ env.PROJECT_NAME }}${EXE_suffix}" |
| 164 | + BIN_PATH="${BIN_DIR}/${BIN_NAME}" |
| 165 | + TRIPLET_NAME="${{ matrix.job.target }}" |
| 166 | +
|
| 167 | + # Copy the release build binary to the result location |
| 168 | + cp "target/$TRIPLET_NAME/release/${BIN_NAME}" "${BIN_DIR}" |
| 169 | +
|
| 170 | + # Also strip if possible |
| 171 | + if [ -n "${STRIP}" ]; then |
| 172 | + "${STRIP}" "${BIN_PATH}" |
| 173 | + fi |
| 174 | +
|
| 175 | + # Let subsequent steps know where to find the (stripped) bin |
| 176 | + echo ::set-output name=BIN_PATH::${BIN_PATH} |
| 177 | + echo ::set-output name=BIN_NAME::${BIN_NAME} |
| 178 | +
|
| 179 | + - name: Create tarball |
| 180 | + id: package |
| 181 | + shell: bash |
| 182 | + run: | |
| 183 | + PKG_suffix=".tar.gz" ; case ${{ matrix.job.target }} in *-pc-windows-*) PKG_suffix=".zip" ;; esac; |
| 184 | + PKG_BASENAME=${PROJECT_NAME}-v${PROJECT_VERSION}-${{ matrix.job.target }} |
| 185 | + PKG_NAME=${PKG_BASENAME}${PKG_suffix} |
| 186 | + echo ::set-output name=PKG_NAME::${PKG_NAME} |
| 187 | +
|
| 188 | + PKG_STAGING="${{ env.CICD_INTERMEDIATES_DIR }}/package" |
| 189 | + ARCHIVE_DIR="${PKG_STAGING}/${PKG_BASENAME}/" |
| 190 | + mkdir -p "${ARCHIVE_DIR}" |
| 191 | + mkdir -p "${ARCHIVE_DIR}/autocomplete" |
| 192 | +
|
| 193 | + # Binary |
| 194 | + cp "${{ steps.strip.outputs.BIN_PATH }}" "$ARCHIVE_DIR" |
| 195 | +
|
| 196 | + # base compressed package |
| 197 | + pushd "${PKG_STAGING}/" >/dev/null |
| 198 | + case ${{ matrix.job.target }} in |
| 199 | + *-pc-windows-*) 7z -y a "${PKG_NAME}" "${PKG_BASENAME}"/* | tail -2 ;; |
| 200 | + *) tar czf "${PKG_NAME}" "${PKG_BASENAME}"/* ;; |
| 201 | + esac; |
| 202 | + popd >/dev/null |
| 203 | +
|
| 204 | + # Let subsequent steps know where to find the compressed package |
| 205 | + echo ::set-output name=PKG_PATH::"${PKG_STAGING}/${PKG_NAME}" |
| 206 | +
|
| 207 | + - name: "Artifact upload: tarball" |
| 208 | + uses: actions/upload-artifact@master |
| 209 | + with: |
| 210 | + name: ${{ steps.package.outputs.PKG_NAME }} |
| 211 | + path: ${{ steps.package.outputs.PKG_PATH }} |
| 212 | + |
| 213 | + - name: Check for release |
| 214 | + id: is-release |
| 215 | + shell: bash |
| 216 | + run: | |
| 217 | + unset IS_RELEASE ; if [[ $GITHUB_REF =~ ^refs/tags/v[0-9].* ]]; then IS_RELEASE='true' ; fi |
| 218 | + echo ::set-output name=IS_RELEASE::${IS_RELEASE} |
| 219 | +
|
| 220 | + - name: Publish archives and packages |
| 221 | + uses: softprops/action-gh-release@v1 |
| 222 | + if: steps.is-release.outputs.IS_RELEASE |
| 223 | + with: |
| 224 | + files: | |
| 225 | + ${{ steps.package.outputs.PKG_PATH }} |
| 226 | + env: |
| 227 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 228 | + |
0 commit comments