cargo-binstall/.github/workflows/build.yml
Jiahao XU 707b173de1
Create universal binary for MacOS in workflow release (#551)
* Create universal binary for MacOS in workflow build
* Update README

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2022-11-22 16:52:36 +11:00

149 lines
4.2 KiB
YAML

name: Build
on:
workflow_call:
inputs:
for_release:
description: "True if the build is for a release"
required: true
default: false
type: boolean
workflow_dispatch:
inputs:
for_release:
description: "True if the build is for a release"
required: true
default: false
type: boolean
env:
CARGO_TERM_COLOR: always
CARGO_UNSTABLE_SPARSE_REGISTRY: "true"
jobs:
build:
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
debug_features: [ rustls, pkg-config ]
- target: x86_64-apple-darwin
os: macos-latest
- target: aarch64-apple-darwin
os: macos-latest
- target: x86_64-pc-windows-msvc
os: windows-latest
debug_features: [ native-tls ]
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
- target: armv7-unknown-linux-musleabihf
os: ubuntu-20.04
use-cross: true
- target: armv7-unknown-linux-gnueabihf
os: ubuntu-20.04
use-cross: true
- target: aarch64-unknown-linux-musl
os: ubuntu-latest
use-cross: true
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
use-cross: true
runs-on: ${{ matrix.os }}
name: ${{ matrix.target }}
steps:
- uses: actions/checkout@v3
- name: Configure toolchain
run: |
rustup toolchain install --profile minimal --no-self-update nightly
rustup default nightly
- name: Install cross
if: matrix.use-cross
uses: taiki-e/install-action@v1
with:
tool: cross
- name: Install host target
if: "!matrix.use-cross"
run: rustup target add ${{ matrix.target }}
- name: Install rust-src
if: inputs.for_release
run: rustup component add rust-src
- name: Select compile settings
shell: bash
run: |
jq \
--argjson for_release '${{ toJSON(inputs.for_release) }}' \
--argjson matrix '${{ toJSON(matrix) }}' \
-nrf .github/scripts/compile-settings.jq \
| tee -a $GITHUB_ENV
- name: Configure caching
uses: actions/cache@v3
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}-${{ env.COUTPUT }}
- name: Install musl-tools
if: ${{ matrix.target == 'x86_64-unknown-linux-musl' }}
run: sudo apt-get install -y musl-tools
- name: Install deps
if: ${{ matrix.target == 'x86_64-unknown-linux-gnu' && !startsWith(github.ref, 'refs/tags/v') }}
run: sudo .github/scripts/install-deps.sh
- name: Build
run: ${{ env.CTOOL }} build ${{ env.CARGS }}
env:
RUSTFLAGS: ${{ env.RUSTFLAGS }}
- name: Get output
shell: bash
run: |
cp target/${{ matrix.target }}/${{ env.COUTPUT }}/${{ env.CBIN }} ${{ env.CBIN }}
chmod +x ${{ env.CBIN }} || true
ls -l ${{ env.CBIN }}
- name: Upload output
uses: actions/upload-artifact@v3
with:
retention-days: 1
name: "${{ matrix.target }}.${{ env.CBIN }}"
path: "${{ env.CBIN }}"
macos_universal_bin:
needs: build
runs-on: macos-latest
env:
aarch64: aarch64-apple-darwin.cargo-binstall
x86_64: x86_64-apple-darwin.cargo-binstall
steps:
- name: Download aarch64 artifact
uses: actions/download-artifact@v3
with:
name: ${{ env.aarch64 }}
path: ${{ env.aarch64 }}
- name: Download x86-64 artifact
uses: actions/download-artifact@v3
with:
name: ${{ env.x86_64 }}
path: ${{ env.x86_64 }}
- name: Create universal binary for MacOS
run: lipo -create -output cargo-binstall $aarch64/cargo-binstall $x86_64/cargo-binstall
- name: Upload output
uses: actions/upload-artifact@v3
with:
retention-days: 1
name: universal-apple-darwin.cargo-binstall
path: cargo-binstall