ci: 多平台构建 支持 matrix 和交叉编译

- 使用 Ubuntu 24.04 runner
- 添加 cargo 镜像源
- 在一个 job 中顺序构建所有平台
- 支持:linux-amd64, linux-arm64, darwin-amd64, darwin-arm64, windows-amd64
- 每次 push 到 main 自动更新 release
This commit is contained in:
2026-04-24 03:44:37 +08:00
parent 849473aff4
commit d3c7243d33

View File

@@ -8,30 +8,40 @@ on:
jobs:
build:
runs-on: ubuntu24.04
container:
image: rust:1.82
steps:
- name: Setup mirrors
run: |
# 使用阿里云 apk 镜像源
echo -e 'https://mirrors.aliyun.com/alpine/v3.20/main/\nhttps://mirrors.aliyun.com/alpine/v3.20/community/' > /etc/apk/repositories
apk add git
echo 'deb https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse' | tee /etc/apt/sources.list
apt-get update -qq
- name: Install Rust
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
. "$HOME/.cargo/env"
# 安装交叉编译目标
rustup target add aarch64-unknown-linux-gnu || true
rustup target add x86_64-apple-darwin || true
rustup target add aarch64-apple-darwin || true
rustup target add x86_64-pc-windows-gnu || true
- name: Setup cargo mirror
run: |
# 使用阿里云 cargo 镜像源
mkdir -p ~/.cargo
echo '[source.crates-io]
replace-with = "ustc"
[source.ustc]
registry = "sparse+https://mirrors.ustc.edu.cn/crates.io/index/"' > ~/.cargo/config.toml
cat > ~/.cargo/config.toml << 'CARGO_EOF'
[source.crates-io]
replace-with = "ustc"
[source.ustc]
registry = "sparse+https://mirrors.ustc.edu.cn/crates.io/index/"
CARGO_EOF
- name: Checkout code
run: git clone https://hub.gaomia.site/titor/haibao-tts-cli.git /workspace/mimo-tts
- name: Build binaries
- name: Build all binaries
run: |
. "$HOME/.cargo/env"
cd /workspace/mimo-tts
# Linux x86_64
@@ -39,8 +49,20 @@ jobs:
mv target/release/mimo-tts mimo-tts-linux-amd64
# Linux ARM64
GOOS=linux GOARCH=arm64 cargo build --release -p mimo-tts
GOOS=linux GOARCH=arm64 cargo build --release -p mimo-tts --target aarch64-unknown-linux-gnu
mv target/release/mimo-tts mimo-tts-linux-arm64
# macOS x86_64
GOOS=darwin GOARCH=amd64 cargo build --release -p mimo-tts --target x86_64-apple-darwin
mv target/release/mimo-tts mimo-tts-darwin-amd64
# macOS ARM64
GOOS=darwin GOARCH=arm64 cargo build --release -p mimo-tts --target aarch64-apple-darwin
mv target/release/mimo-tts mimo-tts-darwin-arm64
# Windows x86_64
GOOS=windows GOARCH=amd64 cargo build --release -p mimo-tts --target x86_64-pc-windows-gnu
mv target/release/mimo-tts.exe mimo-tts-windows-amd64.exe
- name: Generate checksums
run: |