🐛 fix(workflow): 固定使用新版 Rust stable 工具链

- 发布工作流不再依赖 runner 自带 rustc/cargo 版本
- 改为通过 rustup 安装并默认切换到 stable 工具链,兼容 Cargo.lock v4
- 构建步骤统一加载 ~/.cargo/env,避免旧版系统 cargo 抢占路径
This commit is contained in:
2026-05-26 19:54:18 +08:00
parent 8db385cca6
commit f1491ba114

View File

@@ -48,40 +48,24 @@ jobs:
set -eux
if command -v apt-get >/dev/null 2>&1; then
apt-get update
apt-get install -y build-essential pkg-config sqlite3 curl tar ca-certificates nodejs npm rustc cargo
apt-get install -y build-essential pkg-config sqlite3 curl tar ca-certificates nodejs npm
elif command -v dnf >/dev/null 2>&1; then
dnf install -y gcc gcc-c++ make pkgconf-pkg-config sqlite curl tar ca-certificates nodejs npm rust cargo
dnf install -y gcc gcc-c++ make pkgconf-pkg-config sqlite curl tar ca-certificates nodejs npm
elif command -v yum >/dev/null 2>&1; then
yum install -y gcc gcc-c++ make pkgconfig sqlite curl tar ca-certificates nodejs npm rust cargo
yum install -y gcc gcc-c++ make pkgconfig sqlite curl tar ca-certificates nodejs npm
elif command -v pacman >/dev/null 2>&1; then
pacman -Sy --noconfirm base-devel pkgconf sqlite curl tar ca-certificates nodejs npm rust cargo
pacman -Sy --noconfirm base-devel pkgconf sqlite curl tar ca-certificates nodejs npm
fi
- name: 安装 Rust
run: |
set -eux
PATH_BASE="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
PATH_EXTRA=""
OLD_IFS="$IFS"
IFS=':'
set -- $PATH
IFS="$OLD_IFS"
for entry in "$@"; do
[ -n "$entry" ] || continue
[ "$entry" = "$HOME/.cargo/bin" ] && continue
case ":$PATH_BASE:$PATH_EXTRA:" in
*":$entry:"*) continue ;;
esac
PATH_EXTRA="${PATH_EXTRA:+$PATH_EXTRA:}$entry"
done
export PATH="$PATH_BASE${PATH_EXTRA:+:$PATH_EXTRA}"
if ! command -v cargo >/dev/null 2>&1 || ! command -v rustc >/dev/null 2>&1; then
[ -f "$HOME/.cargo/env" ] && . "$HOME/.cargo/env"
fi
if ! command -v cargo >/dev/null 2>&1 || ! command -v rustc >/dev/null 2>&1; then
if ! command -v rustup >/dev/null 2>&1; then
curl --proto '=https' --tlsv1.2 -fsSL https://sh.rustup.rs | sh -s -- -y --profile minimal
. "$HOME/.cargo/env"
fi
. "$HOME/.cargo/env"
rustup toolchain install stable --profile minimal --no-self-update
rustup default stable
HOST_TARGET="$(rustc -vV | sed -n 's/^host: //p')"
BUILD_TARGET="$HOST_TARGET"
if [ "$HOST_TARGET" != "x86_64-unknown-linux-gnu" ] && command -v rustup >/dev/null 2>&1; then
@@ -97,24 +81,7 @@ jobs:
- name: 构建发布包
run: |
set -eux
PATH_BASE="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
PATH_EXTRA=""
OLD_IFS="$IFS"
IFS=':'
set -- $PATH
IFS="$OLD_IFS"
for entry in "$@"; do
[ -n "$entry" ] || continue
[ "$entry" = "$HOME/.cargo/bin" ] && continue
case ":$PATH_BASE:$PATH_EXTRA:" in
*":$entry:"*) continue ;;
esac
PATH_EXTRA="${PATH_EXTRA:+$PATH_EXTRA:}$entry"
done
export PATH="$PATH_BASE${PATH_EXTRA:+:$PATH_EXTRA}"
if ! command -v cargo >/dev/null 2>&1 || ! command -v rustc >/dev/null 2>&1; then
[ -f "$HOME/.cargo/env" ] && . "$HOME/.cargo/env"
fi
. "$HOME/.cargo/env"
cd lightops-src
TAG="$(cat /tmp/lightops-release-tag)"
VERSION="${TAG#v}"