ci(build): Integrate nightly size experiments for continuous evaluation

This commit is contained in:
Nils Andreas Svee committed 2026-10-26 15:35:08 +07:00
1 parent f08d40bfe9
commit ea8734a7aa
1 file changed
+130 -105
+130 -105
View File
@@ -7,23 +7,14 @@ on:
pull_request: pull_request:
branches: [main] branches: [main]
workflow_dispatch: workflow_dispatch:
inputs:
build_mode:
description: "Build configuration"
type: choice
required: true
default: standard
options:
- standard
- nightly-experiments
permissions: permissions:
contents: read contents: read
env: env:
CARGO_TERM_COLOR: always CARGO_TERM_COLOR: always
# Measure before stripping; package stripped copies separately.
CARGO_PROFILE_RELEASE_STRIP: none CARGO_PROFILE_RELEASE_STRIP: none
BUILD_MODE: ${{ inputs.build_mode || 'standard' }}
jobs: jobs:
build: build:
@@ -58,21 +49,24 @@ jobs:
uses: builtin:checkout uses: builtin:checkout
- name: Configure Rust directories - name: Configure Rust directories
# Cross remote does not traverse hidden directories under /root.
run: | run: |
echo "CARGO_HOME=$RUNNER_TEMP/cargo" >> "$GITHUB_ENV" echo "CARGO_HOME=$RUNNER_TEMP/cargo" >> "$GITHUB_ENV"
echo "RUSTUP_HOME=$RUNNER_TEMP/rustup" >> "$GITHUB_ENV" echo "RUSTUP_HOME=$RUNNER_TEMP/rustup" >> "$GITHUB_ENV"
echo "$RUNNER_TEMP/cargo/bin" >> "$GITHUB_PATH" echo "$RUNNER_TEMP/cargo/bin" >> "$GITHUB_PATH"
- name: Install Rust toolchain - name: Install standard Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@ecabd13d1c56bd1345c230e542e9144811ad706f # v2 uses: actions-rust-lang/setup-rust-toolchain@ecabd13d1c56bd1345c230e542e9144811ad706f # v2
with: with:
toolchain: ${{ (inputs.build_mode == 'nightly-experiments' || startsWith(matrix.target, 'mips')) && 'nightly' || 'stable' }} toolchain: ${{ startsWith(matrix.target, 'mips') && 'nightly' || 'stable' }}
cache: false cache: false
build-warnings: warn build-warnings: warn
- name: Install nightly standard library sources - name: Install nightly toolchain and standard library sources
if: inputs.build_mode == 'nightly-experiments' run: |
run: rustup component add rust-src --toolchain nightly rustup toolchain install nightly \
--profile minimal \
--component rust-src
- name: Install cross and binary tools - name: Install cross and binary tools
run: | run: |
@@ -91,7 +85,7 @@ jobs:
- name: Build, verify, package, and compare - name: Build, verify, package, and compare
env: env:
# MIPS std needs CRT objects from the cross GCC toolchain. # MIPS build-std needs cross GCC's CRT objects.
RUSTFLAGS: ${{ startsWith(matrix.target, 'mips') && '-C target-feature=+crt-static -C link-self-contained=no' || '-C target-feature=+crt-static' }} RUSTFLAGS: ${{ startsWith(matrix.target, 'mips') && '-C target-feature=+crt-static -C link-self-contained=no' || '-C target-feature=+crt-static' }}
CROSS_REMOTE: "true" CROSS_REMOTE: "true"
CROSS_REMOTE_COPY_FULL_TARGET_DIR: ${{ startsWith(matrix.target, 'mips') && 'true' || 'false' }} CROSS_REMOTE_COPY_FULL_TARGET_DIR: ${{ startsWith(matrix.target, 'mips') && 'true' || 'false' }}
@@ -101,29 +95,29 @@ jobs:
declare -A raw_size declare -A raw_size
declare -A stripped_size declare -A stripped_size
declare -A compressed_size declare -A compressed_size
declare -a variants
mkdir -p dist mkdir -p dist
cross_cmd=(cross) # MIPS requires nightly build-std via Cross.toml.
if [[ "$BUILD_MODE" == "nightly-experiments" ]]; then # Every other standard build uses stable.
cross_cmd+=(+nightly) standard_toolchain=stable
if [[ "$TARGET" == mips* ]]; then
standard_toolchain=nightly
fi fi
build_variant() { build_variant() {
local variant="$1" local variant="$1"
local features="$2" local toolchain="$2"
shift 2 local features="$3"
shift 3
local binary="target/${RUST_TARGET}/release/irtt-client" local binary="target/${RUST_TARGET}/release/irtt-client"
local directory="dist/${variant}" local directory="dist/${variant}"
local artifact="dist/irtt-client-${TARGET}-${variant}.tar.gz" local artifact="dist/irtt-client-${TARGET}-${variant}.tar.gz"
echo "::group::Build ${variant} (${features})" echo "::group::Build ${variant} (${toolchain}, ${features})"
# Additional arguments allow individual variants to cross "+${toolchain}" build \
# customize build-std, std features and panic behavior.
"${cross_cmd[@]}" build \
--release \ --release \
--locked \ --locked \
--target "$RUST_TARGET" \ --target "$RUST_TARGET" \
@@ -133,8 +127,7 @@ jobs:
--features "$features" \ --features "$features" \
"$@" "$@"
# Check dynamic linking without relying on pipeline # Reject dynamically linked executables.
# behavior under pipefail.
readelf --program-headers "$binary" > /tmp/program-headers.txt readelf --program-headers "$binary" > /tmp/program-headers.txt
readelf --dynamic "$binary" > /tmp/dynamic-section.txt readelf --dynamic "$binary" > /tmp/dynamic-section.txt
@@ -154,11 +147,10 @@ jobs:
stat -c %s "$directory/irtt-client" stat -c %s "$directory/irtt-client"
) )
# Each archive contains an executable named irtt-client.
tar -czf "$artifact" -C "$directory" irtt-client tar -czf "$artifact" -C "$directory" irtt-client
compressed_size[$variant]=$(stat -c %s "$artifact") compressed_size[$variant]=$(stat -c %s "$artifact")
variants+=("$variant")
echo "::endgroup::" echo "::endgroup::"
} }
@@ -166,7 +158,7 @@ jobs:
numfmt --to=iec-i --suffix=B --format='%.1f' "$1" numfmt --to=iec-i --suffix=B --format='%.1f' "$1"
} }
# Positive means larger than baseline; negative means smaller. # Negative means smaller than the reference binary.
delta() { delta() {
awk -v base="$1" -v current="$2" 'BEGIN { awk -v base="$1" -v current="$2" 'BEGIN {
if (base == 0) { if (base == 0) {
@@ -177,105 +169,138 @@ jobs:
}' }'
} }
reduction() { print_row() {
awk -v full="$1" -v minimal="$2" 'BEGIN { local variant="$1"
if (full == 0) { local label="$2"
printf "N/A" local baseline="$3"
} else { local comparison
printf "%.1f%%", 100 * (full - minimal) / full
} if [[ "$variant" == "$baseline" ]]; then
}' comparison="Baseline"
else
comparison=$(delta \
"${compressed_size[$baseline]}" \
"${compressed_size[$variant]}")
fi
printf '| %s | %s | %s | %s | %s |\n' \
"$label" \
"$(human "${raw_size[$variant]}")" \
"$(human "${stripped_size[$variant]}")" \
"$(human "${compressed_size[$variant]}")" \
"$comparison"
} }
# Standard builds preserve the existing toolchain policy: # ---------------------------------------------------------
# stable everywhere except MIPS, which requires nightly. # Standard builds: stable except MIPS.
# # ---------------------------------------------------------
# Experimental mode uses nightly for every variant so
# compiler-version differences don't affect comparisons.
full_features=client
if [[ "$HAS_STATS_FEATURE" == "true" ]]; then if [[ "$HAS_STATS_FEATURE" == "true" ]]; then
build_variant full "client,stats" full_features="client,stats"
build_variant minimal "client" fi
baseline="minimal"
build_variant full "$standard_toolchain" "$full_features"
standard_baseline=full
if [[ "$HAS_STATS_FEATURE" == "true" ]]; then
build_variant minimal "$standard_toolchain" client
standard_baseline=minimal
fi
# ---------------------------------------------------------
# Nightly baseline: identical compiler for all experiments.
#
# MIPS already uses nightly for standard builds, so reuse
# those binaries rather than compiling them twice.
# ---------------------------------------------------------
if [[ "$standard_toolchain" == "nightly" ]]; then
nightly_full=full
nightly_baseline="$standard_baseline"
else else
# Compatibility with main before stats feature gating. nightly_full=nightly-full
build_variant full "client" build_variant nightly-full nightly "$full_features"
baseline="full"
nightly_baseline=nightly-full
if [[ "$HAS_STATS_FEATURE" == "true" ]]; then
build_variant nightly-minimal nightly client
nightly_baseline=nightly-minimal
fi
fi fi
if [[ "$BUILD_MODE" == "nightly-experiments" ]]; then # ---------------------------------------------------------
# Existing Cross.toml already rebuilds std on MIPS. # Nightly size experiments, always enabled.
# On other targets, the normal builds use prebuilt std. # ---------------------------------------------------------
build_variant rebuilt-std "client" \ # Rebuild std with the ordinary std feature set.
-Z build-std build_variant rebuilt-std nightly client \
-Z build-std
# Rebuild std without backtrace support, retaining # Rebuild std without backtrace support.
# normal panic unwinding. # Retain normal panic unwinding.
build_variant no-backtrace "client" \ build_variant no-backtrace nightly client \
-Z build-std \ -Z build-std \
-Z build-std-features=panic-unwind -Z build-std-features=panic-unwind
# Most aggressive experiment: no unwinding, panic # Aggressive option: terminate immediately on panic.
# reporting, or std backtrace support. build_variant immediate-abort nightly client \
build_variant immediate-abort "client" \ -Z panic-immediate-abort \
-Z panic-immediate-abort \ -Z build-std \
-Z build-std \ -Z build-std-features= \
-Z build-std-features= \ --config 'profile.release.panic="immediate-abort"'
--config 'profile.release.panic="immediate-abort"'
fi # ---------------------------------------------------------
# Job summary.
# ---------------------------------------------------------
{ {
echo "### irtt-client: ${TARGET}" echo "### irtt-client: ${TARGET}"
echo echo
echo "Build mode: \`${BUILD_MODE}\`"
echo "#### Standard builds"
echo
echo "Toolchain: \`${standard_toolchain}\`"
echo echo
echo '| Variant | Unstripped | Stripped | Compressed | Compressed vs baseline |' echo '| Variant | Unstripped | Stripped | Compressed | Compressed vs baseline |'
echo '|:--|--:|--:|--:|--:|' echo '|:--|--:|--:|--:|--:|'
for variant in "${variants[@]}"; do print_row full "Full" "$standard_baseline"
if [[ "$variant" == "$baseline" ]]; then
comparison="Baseline"
else
comparison=$(delta \
"${compressed_size[$baseline]}" \
"${compressed_size[$variant]}")
fi
printf '| %s | %s | %s | %s | %s |\n' \
"$variant" \
"$(human "${raw_size[$variant]}")" \
"$(human "${stripped_size[$variant]}")" \
"$(human "${compressed_size[$variant]}")" \
"$comparison"
done
if [[ "$HAS_STATS_FEATURE" == "true" ]]; then if [[ "$HAS_STATS_FEATURE" == "true" ]]; then
echo print_row minimal "Minimal" "$standard_baseline"
echo '#### Full vs minimal'
echo
echo '| Unstripped reduction | Stripped reduction | Compressed reduction |'
echo '|--:|--:|--:|'
printf '| %s | %s | %s |\n' \
"$(reduction "${raw_size[full]}" "${raw_size[minimal]}")" \
"$(reduction "${stripped_size[full]}" "${stripped_size[minimal]}")" \
"$(reduction "${compressed_size[full]}" "${compressed_size[minimal]}")"
else
echo
echo "The stats feature is not available; client includes statistics."
fi fi
if [[ "$BUILD_MODE" == "nightly-experiments" ]]; then echo
echo "#### Nightly experiments"
echo
echo '| Variant | Unstripped | Stripped | Compressed | Compressed vs baseline |'
echo '|:--|--:|--:|--:|--:|'
print_row "$nightly_full" "Nightly full" "$nightly_baseline"
if [[ "$HAS_STATS_FEATURE" == "true" ]]; then
print_row "$nightly_baseline" "Nightly minimal" "$nightly_baseline"
fi
print_row rebuilt-std "Rebuilt std" "$nightly_baseline"
print_row no-backtrace "No backtrace" "$nightly_baseline"
print_row immediate-abort "Immediate abort" "$nightly_baseline"
if [[ "$standard_toolchain" == "stable" ]]; then
echo echo
echo '#### Experiment details' echo "Nightly vs stable baseline (compressed): $(delta \
"${compressed_size[$standard_baseline]}" \
"${compressed_size[$nightly_baseline]}")"
else
echo echo
echo '- `rebuilt-std`: nightly `-Z build-std`, default std features' echo "MIPS: standard and nightly baselines are identical."
echo '- `no-backtrace`: rebuilt std with `panic-unwind` only' echo "Cross.toml already enables build-std for these targets."
echo '- `immediate-abort`: rebuilt std with immediate panic termination' fi
if [[ "$HAS_STATS_FEATURE" != "true" ]]; then
echo echo
echo 'MIPS already uses build-std through Cross.toml.' echo "Statistics feature not detected; client includes statistics."
echo 'All measurements use the same target and nightly toolchain.'
fi fi
} >> "$GITHUB_STEP_SUMMARY" } >> "$GITHUB_STEP_SUMMARY"