1
0
forked from Eeveid/lightOps

🐛 fix(release): 修复原生目标构建时的 C 编译器选择

- 仅在 x86_64-unknown-linux-gnu 目标已安装且存在 x86_64-linux-gnu-gcc 时才选择 GNU 交叉目标
- 打包脚本在目标等于当前 Rust host target 时改为原生 cargo build,不再显式传 --target
- 避免 cc-rs 在原生构建场景下错误寻找 x86_64-linux-gnu-gcc 导致发布失败
This commit is contained in:
2026-05-26 10:48:19 +08:00
parent 4322023820
commit 9b63ef38c3
2 changed files with 8 additions and 3 deletions

View File

@@ -85,7 +85,7 @@ jobs:
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
if rustup target list --installed | grep -qx 'x86_64-unknown-linux-gnu'; then
if rustup target list --installed | grep -qx 'x86_64-unknown-linux-gnu' && command -v x86_64-linux-gnu-gcc >/dev/null 2>&1; then
BUILD_TARGET="x86_64-unknown-linux-gnu"
fi
fi

View File

@@ -111,6 +111,11 @@ PLATFORM="${TARGET:-$(detect_platform)}"
PACKAGE_NAME="lightops-${VERSION}-${PLATFORM}"
STAGE_DIR="target/release-package/${PACKAGE_NAME}"
ARCHIVE_PATH="${OUTPUT_DIR}/${PACKAGE_NAME}.tar.gz"
HOST_TARGET="$(rustc -vV 2>/dev/null | sed -n 's/^host: //p')"
NATIVE_TARGET="false"
if [[ -n "$TARGET" && -n "$HOST_TARGET" && "$TARGET" == "$HOST_TARGET" ]]; then
NATIVE_TARGET="true"
fi
if [[ "$SKIP_BUILD" != "true" ]]; then
log "构建前端"
@@ -124,7 +129,7 @@ if [[ "$SKIP_BUILD" != "true" ]]; then
log "构建 Rust 二进制"
cd "$ROOT"
if [[ -n "$TARGET" ]]; then
if [[ -n "$TARGET" && "$NATIVE_TARGET" != "true" ]]; then
cargo build --release --target "$TARGET" -p lightops-server -p lightops-agent
BIN_DIR="target/${TARGET}/release"
else
@@ -133,7 +138,7 @@ if [[ "$SKIP_BUILD" != "true" ]]; then
fi
else
cd "$ROOT"
if [[ -n "$TARGET" ]]; then
if [[ -n "$TARGET" && "$NATIVE_TARGET" != "true" ]]; then
BIN_DIR="target/${TARGET}/release"
else
BIN_DIR="target/release"