Исправить production builder для старых CPU без AVX2 и обновить документацию сборки
This commit is contained in:
+91
-18
@@ -10,6 +10,7 @@ VERIFY_TOOLCHAIN_CHECKSUMS="${VERIFY_TOOLCHAIN_CHECKSUMS:-false}"
|
||||
GO_ARCHIVE_SHA256="${GO_ARCHIVE_SHA256:-}"
|
||||
NODE_ARCHIVE_SHA256="${NODE_ARCHIVE_SHA256:-}"
|
||||
BUN_ARCHIVE_SHA256="${BUN_ARCHIVE_SHA256:-}"
|
||||
BUN_FLAVOR="${BUN_FLAVOR:-auto}"
|
||||
|
||||
verify_archive_sha256() {
|
||||
local archive="$1"
|
||||
@@ -119,30 +120,102 @@ ensure_go() {
|
||||
[ "$(go_version "$GO_BIN")" = "$GO_REQUIRED" ] || fail "Go version mismatch: required $GO_REQUIRED, got $($GO_BIN version)"
|
||||
}
|
||||
|
||||
cpu_has_avx2() {
|
||||
grep -m1 '^flags' /proc/cpuinfo 2>/dev/null | grep -qw avx2
|
||||
}
|
||||
|
||||
select_bun_artifact() {
|
||||
case "$BUN_FLAVOR" in
|
||||
auto)
|
||||
if cpu_has_avx2; then
|
||||
BUN_ARTIFACT="bun-linux-x64"
|
||||
else
|
||||
BUN_ARTIFACT="bun-linux-x64-baseline"
|
||||
fi
|
||||
;;
|
||||
x64|bun-linux-x64)
|
||||
BUN_ARTIFACT="bun-linux-x64"
|
||||
;;
|
||||
baseline|x64-baseline|bun-linux-x64-baseline)
|
||||
BUN_ARTIFACT="bun-linux-x64-baseline"
|
||||
;;
|
||||
*)
|
||||
fail "unsupported BUN_FLAVOR: $BUN_FLAVOR (use auto, x64, or x64-baseline)"
|
||||
;;
|
||||
esac
|
||||
|
||||
BUN_COMPILE_TARGET="$BUN_ARTIFACT"
|
||||
export BUN_ARTIFACT BUN_COMPILE_TARGET
|
||||
}
|
||||
|
||||
bun_version() {
|
||||
local bun="$1"
|
||||
"$bun" --version 2>/dev/null || true
|
||||
}
|
||||
|
||||
ensure_bun() {
|
||||
select_bun_artifact
|
||||
|
||||
local managed="$TOOLCHAIN_DIR/bun/bin/bun"
|
||||
if [ -x "$managed" ] && [ "$($managed --version)" = "$BUN_REQUIRED" ]; then
|
||||
BUN_BIN="$managed"
|
||||
elif command -v bun >/dev/null 2>&1 && [ "$(bun --version)" = "$BUN_REQUIRED" ]; then
|
||||
BUN_BIN="$(command -v bun)"
|
||||
else
|
||||
log_info "Installing Bun $BUN_REQUIRED into $TOOLCHAIN_DIR/bun"
|
||||
mkdir -p "$TOOLCHAIN_DIR/downloads" "$TOOLCHAIN_DIR/bun"
|
||||
local archive="$TOOLCHAIN_DIR/downloads/bun-linux-x64-${BUN_REQUIRED}.zip"
|
||||
download_file "https://github.com/oven-sh/bun/releases/download/bun-v${BUN_REQUIRED}/bun-linux-x64.zip" "$archive"
|
||||
verify_archive_sha256 "$archive" "$BUN_ARCHIVE_SHA256" "BUN_ARCHIVE"
|
||||
rm -rf "$TOOLCHAIN_DIR/bun-tmp" "$TOOLCHAIN_DIR/bun"
|
||||
mkdir -p "$TOOLCHAIN_DIR/bun-tmp"
|
||||
unzip -q "$archive" -d "$TOOLCHAIN_DIR/bun-tmp"
|
||||
mkdir -p "$TOOLCHAIN_DIR/bun/bin"
|
||||
install -m 0755 "$TOOLCHAIN_DIR/bun-tmp/bun-linux-x64/bun" "$managed"
|
||||
rm -rf "$TOOLCHAIN_DIR/bun-tmp"
|
||||
BUN_BIN="$managed"
|
||||
local selected_bun=""
|
||||
local actual=""
|
||||
|
||||
if [ -x "$managed" ]; then
|
||||
actual="$(bun_version "$managed")"
|
||||
if [ "$actual" = "$BUN_REQUIRED" ]; then
|
||||
selected_bun="$managed"
|
||||
else
|
||||
log_info "Ignoring managed Bun at $managed: required $BUN_REQUIRED, got ${actual:-failed to execute}"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$selected_bun" ] && command -v bun >/dev/null 2>&1; then
|
||||
local system_bun
|
||||
system_bun="$(command -v bun)"
|
||||
|
||||
if [ "$system_bun" != "$managed" ]; then
|
||||
actual="$(bun_version "$system_bun")"
|
||||
if [ "$actual" = "$BUN_REQUIRED" ]; then
|
||||
selected_bun="$system_bun"
|
||||
else
|
||||
log_info "Ignoring system Bun at $system_bun: required $BUN_REQUIRED, got ${actual:-failed to execute}"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$selected_bun" ]; then
|
||||
log_info "Installing Bun $BUN_REQUIRED ($BUN_ARTIFACT) into $TOOLCHAIN_DIR/bun"
|
||||
|
||||
mkdir -p "$TOOLCHAIN_DIR/downloads" "$TOOLCHAIN_DIR/bun"
|
||||
|
||||
local archive="$TOOLCHAIN_DIR/downloads/${BUN_ARTIFACT}-${BUN_REQUIRED}.zip"
|
||||
download_file "https://github.com/oven-sh/bun/releases/download/bun-v${BUN_REQUIRED}/${BUN_ARTIFACT}.zip" "$archive"
|
||||
verify_archive_sha256 "$archive" "$BUN_ARCHIVE_SHA256" "BUN_ARCHIVE"
|
||||
|
||||
rm -rf "$TOOLCHAIN_DIR/bun-tmp" "$TOOLCHAIN_DIR/bun"
|
||||
mkdir -p "$TOOLCHAIN_DIR/bun-tmp"
|
||||
|
||||
unzip -q "$archive" -d "$TOOLCHAIN_DIR/bun-tmp"
|
||||
|
||||
mkdir -p "$TOOLCHAIN_DIR/bun/bin"
|
||||
install -m 0755 "$TOOLCHAIN_DIR/bun-tmp/${BUN_ARTIFACT}/bun" "$managed"
|
||||
|
||||
rm -rf "$TOOLCHAIN_DIR/bun-tmp"
|
||||
|
||||
selected_bun="$managed"
|
||||
fi
|
||||
|
||||
BUN_BIN="$selected_bun"
|
||||
export BUN_BIN
|
||||
export PATH="$(dirname "$BUN_BIN"):$PATH"
|
||||
[ "$($BUN_BIN --version)" = "$BUN_REQUIRED" ] || fail "Bun version mismatch: required $BUN_REQUIRED, got $($BUN_BIN --version)"
|
||||
|
||||
actual="$(bun_version "$BUN_BIN")"
|
||||
|
||||
if [ "$actual" != "$BUN_REQUIRED" ]; then
|
||||
fail "Bun version mismatch: required $BUN_REQUIRED, got ${actual:-failed to execute}. Selected artifact: ${BUN_ARTIFACT}. On old CPUs without AVX2 use BUN_FLAVOR=x64-baseline."
|
||||
fi
|
||||
|
||||
log_info "Using Bun $actual; artifact=$BUN_ARTIFACT; compile_target=$BUN_COMPILE_TARGET"
|
||||
}
|
||||
|
||||
node_version() {
|
||||
|
||||
Reference in New Issue
Block a user