Files
sqm-autorate-rust/Jenkinsfile
Nils Andreas Svee a653bcf279 ci: support static cross-compilation with vendored UCI
Add Dockerfile.ci with pkg-config for vendored UCI builds. Switch
Jenkinsfile from pre-built Docker images to Dockerfile-based agents
for full control over the build environment. Add static CRT linking
via RUSTFLAGS for standalone static binaries across the CI matrix.
2026-08-07 16:04:59 +07:00

98 lines
4.1 KiB
Groovy

pipeline {
agent any
stages {
stage('Main') {
matrix {
axes {
axis {
name 'TARGET'
values 'x86_64-musl', 'i686-musl', 'arm-musleabi', 'arm-musleabihf', 'armv7-musleabi', 'armv7-musleabihf', 'aarch64-musl', 'mips-musl', 'mipsel-musl', 'mips64-muslabi64', 'mips64el-muslabi64', 'riscv64gc-musl'
}
}
agent {
dockerfile {
filename 'Dockerfile.ci'
additionalBuildArgs "--pull --build-arg TARGET=${TARGET}"
}
}
stages {
stage('Build') {
steps {
sh '''
# 1. Set CARGO_HOME to a writable directory in the workspace
export CARGO_HOME="$(pwd)/.cargo"
mkdir -p "$CARGO_HOME"
# 2. Add local bin to PATH (for tools you might install)
export PATH="$(pwd)/.local/bin:${PATH}"
# 3. CRITICAL: Copy the cross-compilation config from the image's default location
# The image stores the linker configuration in /root/.cargo/config.toml.
# Without this, Cargo defaults to the host linker (cc) and fails.
if [ -f /root/.cargo/config.toml ]; then
cp /root/.cargo/config.toml "$CARGO_HOME/config.toml"
else
echo "WARNING: /root/.cargo/config.toml not found. Build may fail."
fi
# 4. Debug: Verify the config is present and correct
echo "--- Active Cargo Configuration ---"
cat "$CARGO_HOME/config.toml"
echo "----------------------------------"
# 5. Check Toolchain & Build
# Force standalone static artifacts across the entire CI matrix.
export RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }-C target-feature=+crt-static"
# We grep for "nightly" in the version string (e.g., "rustc 1.95.0-nightly...")
if rustc -V | grep -q "nightly"; then
echo "Detected Nightly toolchain. Enabling '-Z build-std' to support panic=abort..."
# Ensure rust-src is installed (needed for build-std)
# We use '|| true' so it doesn't fail if already installed or network flakes
rustup component add rust-src || true
cargo build --release -Z build-std=std,panic_abort
else
echo "Detected Stable toolchain. Building with standard pre-compiled library..."
cargo build --release
fi
'''
}
}
stage('Archive artifact') {
steps {
sh '''
# 1. Construct the specific path for the current architecture
# CARGO_BUILD_TARGET is provided by the Docker image (e.g., aarch64-unknown-linux-musl)
BINARY_PATH="target/${CARGO_BUILD_TARGET}/release/sqm-autorate-rust"
# 2. Verify it exists
if [ -f "$BINARY_PATH" ]; then
echo "Found compiled binary at: $BINARY_PATH"
# 3. Rename with the matrix tag (e.g., sqm-autorate-rust-aarch64-musl)
# This ensures unique filenames in the shared workspace root
cp "$BINARY_PATH" "sqm-autorate-rust-${TARGET}"
else
echo "ERROR: Could not find binary at $BINARY_PATH"
# List target dir to help debug if it fails
ls -R target/
exit 1
fi
'''
// 4. Archive the specific file we just copied
archiveArtifacts artifacts: "sqm-autorate-rust-${TARGET}", fingerprint: true, onlyIfSuccessful: true
}
}
}
}
}
}
}