cross 让这变得非常容易,尤其是因为它得到了 actions-rs/cargo 的支持。
我正在使用类似的东西
name: 'Release'
on:
push:
tags:
- 'v*'
env:
CARGO_INCREMENTAL: 0
jobs:
build:
name: Binary
strategy:
fail-fast: false
matrix:
job:
- { target: x86_64-unknown-linux-musl, exe: amd64-linux, os: ubuntu-latest }
- { target: aarch64-unknown-linux-musl, exe: aarch64-linux, os: ubuntu-latest }
- { target: armv7-unknown-linux-musleabi, exe: armv7-linux, os: ubuntu-latest }
- { target: wasm32-wasi, exe: wasi.wasm, os: ubuntu-latest }
- { target: x86_64-apple-darwin, exe: macos, os: macos-latest }
- { target: x86_64-pc-windows-msvc, exe: windows.exe, os: windows-2019 }
runs-on: ${{ matrix.job.os }}
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.62.0
override: true
target: ${{ matrix.job.target }}
components: rust-src # necessary for wasi, because there isn't a cross image for it
- uses: actions-rs/cargo@v1
with:
use-cross: true
args: --release --target=${{ matrix.job.target }} --locked
command: build
- name: Rename result
run: |
rm target/${{ matrix.job.target }}/release/name-of-binary.d
cp target/${{ matrix.job.target }}/release/name-of-binary* name-of-binary-${{ matrix.job.exe }}
- name: Archive production artifacts
uses: actions/upload-artifact@v2
with:
name: arty
path: name-of-binary-${{ matrix.job.exe }}
# Release artifacts in a separate step to make sure all are successfully produced and no partial release is created
在my projects 之一上。
我还指定
[profile.release]
lto = "fat"
strip = "debuginfo"
在我的Cargo.toml 中使发布的文件更好一点。
值得注意的是,Rust crates 比 Go 更容易在 C/C++ 库中构建和链接,可能会调用 CMake 或更糟。交叉编译这样的 crate 可能要困难得多,如何准确地做到这一点取决于特定的 crate。