Files
Genarrative/scripts/jenkins-prepare-cargo-env.sh

37 lines
1.1 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
set -euo pipefail
: "${CARGO_HOME:?需要设置 CARGO_HOME}"
: "${CARGO_TARGET_DIR:?需要设置 CARGO_TARGET_DIR}"
: "${SCCACHE_DIR:?需要设置 SCCACHE_DIR}"
ORIGINAL_HOME="${HOME:-}"
CARGO_BUILD_HOME="${CARGO_BUILD_HOME:-$(dirname "${CARGO_HOME}")/home}"
mkdir -p "${CARGO_HOME}" "${CARGO_TARGET_DIR}" "${SCCACHE_DIR}" "${CARGO_BUILD_HOME}"
# Jenkins agent 当前以 root 运行时,/root/.cargo/config 可能带有失效镜像配置。
# 生产构建使用组件级 HOME 与 CARGO_HOME避免被全局 Cargo 配置污染。
if [[ -z "${RUSTUP_HOME:-}" && -n "${ORIGINAL_HOME}" && -d "${ORIGINAL_HOME}/.rustup" ]]; then
export RUSTUP_HOME="${ORIGINAL_HOME}/.rustup"
fi
export HOME="${CARGO_BUILD_HOME}"
export CARGO_HOME
export CARGO_TARGET_DIR
export SCCACHE_DIR
cat >"${CARGO_HOME}/config.toml" <<'CARGO_CONFIG'
[registries.crates-io]
protocol = "sparse"
CARGO_CONFIG
echo "[cargo-env] HOME=${HOME}"
echo "[cargo-env] CARGO_HOME=${CARGO_HOME}"
echo "[cargo-env] CARGO_TARGET_DIR=${CARGO_TARGET_DIR}"
echo "[cargo-env] SCCACHE_DIR=${SCCACHE_DIR}"
if [[ -n "${RUSTUP_HOME:-}" ]]; then
echo "[cargo-env] RUSTUP_HOME=${RUSTUP_HOME}"
fi