Cross build with action-rs

This commit is contained in:
Patrick Dung 2021-10-10 02:21:30 +08:00
parent 602a327aa8
commit c614520405
2 changed files with 118 additions and 0 deletions

111
.github/workflows/publish-crossbuild.yml vendored Normal file
View File

@ -0,0 +1,111 @@
name: Release using cross build
on:
release:
types: [published]
env:
CARGO_TERM_COLOR: always
jobs:
publish-to-github:
name: Publish to Github
runs-on: ${{ matrix.os }}
continue-on-error: false
strategy:
fail-fast: false
matrix:
include:
- build: aarch64
os: ubuntu-18.04
target: aarch64-unknown-linux-gnu
linker: gcc-aarch64-linux-gnu
use-cross: true
asset_name: meilisearch-linux-aarch64
- build: aarch64
os: ubuntu-latest
target: aarch64-unknown-linux-musl
linker: gcc-aarch64-linux-gnu
use-cross: true
asset_name: meilisearch-linux-aarch64-musl
- build: linux
os: ubuntu-latest
target: x86_64-unknown-linux-musl
use-cross: true
asset_name: meilisearch-linux-amd64-musl
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Installing Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
target: ${{ matrix.target }}
override: true
- name: APT update
run: |
sudo apt update
- name: Install target specific tools
if: matrix.use-cross
run: |
sudo apt-get install -y ${{ matrix.linker }}
- name: Configure target aarch64 GNU
if: matrix.target == 'aarch64-unknown-linux-gnu'
# LD gold won't work with MUSL
env:
JEMALLOC_SYS_WITH_LG_PAGE: 16
RUSTFLAGS: '-Clink-arg=-fuse-ld=gold'
run: |
echo '[target.aarch64-unknown-linux-gnu]' >> ~/.cargo/config
echo 'linker = "aarch64-linux-gnu-gcc"' >> ~/.cargo/config
- name: Configure target aarch64 MUSL
if: matrix.target == 'aarch64-unknown-linux-musl'
env:
JEMALLOC_SYS_WITH_LG_PAGE: 16
run: |
sudo apt-get install -y musl-tools
- name: Configure target x86_64 MUSL
if: matrix.target == 'x86_64-unknown-linux-musl'
run: |
sudo apt-get install -y musl-tools
- name: Cargo build
uses: actions-rs/cargo@v1
with:
command: build
use-cross: ${{ matrix.use-cross }}
args: --release --target ${{ matrix.target }}
# Strip debuginfo for target aarch64 GNU
# MUSL binary are static linked
- name: Strip debuginfo for target aarch64 GNU
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
/usr/bin/aarch64-linux-gnu-strip --strip-debug --target=elf64-littleaarch64 target/${{ matrix.target }}/release/meilisearch -o target/${{ matrix.target }}/release/meilisearch-stripped
- name: List target output files
run: ls -lR ./target
- name: Upload the binary to release
uses: svenstaro/upload-release-action@v1-release
with:
repo_token: ${{ secrets.PUBLISH_TOKEN }}
file: target/${{ matrix.target }}/release/meilisearch
asset_name: ${{ matrix.asset_name }}
tag: ${{ github.ref }}
- name: Upload stripped binary to release (aarch64 GNU only)
if: matrix.target == 'aarch64-unknown-linux-gnu'
uses: svenstaro/upload-release-action@v1-release
with:
repo_token: ${{ secrets.PUBLISH_TOKEN }}
file: target/${{ matrix.target }}/release/meilisearch-stripped
asset_name: ${{ matrix.asset_name }}-stripped
tag: ${{ github.ref }}

7
Cross.toml Normal file
View File

@ -0,0 +1,7 @@
[build.env]
passthrough = [
"RUST_BACKTRACE",
"CARGO_TERM_COLOR",
"RUSTFLAGS",
"JEMALLOC_SYS_WITH_LG_PAGE"
]