Skip to content

Commit cb65ffb

Browse files
author
Terraphim CI
committed
Merge PR #487: feat: optimize builds for CI and reduce disk usage
Left-side: Build optimization features (CI profiles, sccache, cleanup) documented in PR. Right-side: Conflicts resolved (kept HEAD's error handling); cargo check PASS.
2 parents 34bcd63 + 15fc3ac commit cb65ffb

File tree

3 files changed

+138
-0
lines changed

3 files changed

+138
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Cleanup Target Directory
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * 0' # Weekly cleanup on Sundays at midnight UTC
6+
workflow_dispatch:
7+
8+
jobs:
9+
cleanup:
10+
name: Clean old build artifacts
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: write
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v4
17+
18+
- name: Setup Rust toolchain
19+
uses: actions-rust-lang/setup-rust-toolchain@v1
20+
with:
21+
toolchain: stable
22+
23+
- name: Clean release artifacts
24+
run: |
25+
cargo clean --release
26+
cargo clean --doc
27+
28+
- name: Display disk usage
29+
run: |
30+
echo "Target directory size after cleanup:"
31+
du -sh target/
32+
33+
- name: Summary
34+
run: |
35+
echo "### Cleanup completed" >> $GITHUB_STEP_SUMMARY
36+
echo "- Cleaned release artifacts" >> $GITHUB_STEP_SUMMARY
37+
echo "- Cleaned documentation artifacts" >> $GITHUB_STEP_SUMMARY

Cargo.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,18 @@ lto = true
4242
codegen-units = 1
4343
opt-level = 3
4444
panic = "abort"
45+
46+
# CI-optimized profiles for faster builds with less disk usage
47+
[profile.ci]
48+
inherits = "dev"
49+
incremental = false
50+
codegen-units = 16
51+
split-debuginfo = "off"
52+
debug = false
53+
strip = true
54+
55+
[profile.ci-release]
56+
inherits = "release"
57+
lto = "thin"
58+
codegen-units = 8
59+
strip = "symbols"

scripts/cleanup-build.sh

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/bin/bash
2+
# Cleanup build artifacts to prevent target directory bloat
3+
# Usage: ./scripts/cleanup-build.sh [options]
4+
# Options:
5+
# --aggressive Remove more artifacts (docs, unused deps)
6+
# --dry-run Show what would be deleted without actually deleting
7+
8+
set -euo pipefail
9+
10+
AGGRESSIVE=false
11+
DRY_RUN=false
12+
13+
while [[ $# -gt 0 ]]; do
14+
case $1 in
15+
--aggressive)
16+
AGGRESSIVE=true
17+
shift
18+
;;
19+
--dry-run)
20+
DRY_RUN=true
21+
shift
22+
;;
23+
*)
24+
echo "Unknown option: $1"
25+
echo "Usage: $0 [--aggressive] [--dry-run]"
26+
exit 1
27+
;;
28+
esac
29+
done
30+
31+
cd "$(git rev-parse --show-toplevel)" || exit 1
32+
33+
echo "=== Terraphim Build Cleanup ==="
34+
echo "Mode: $([ "$DRY_RUN" = true ] && echo 'DRY RUN (no changes)' || echo 'ACTIVE')"
35+
echo "Aggressive: $AGGRESSIVE"
36+
echo ""
37+
38+
# Calculate current size
39+
echo "Current target directory size:"
40+
du -sh target/ 2>/dev/null || echo "No target directory found"
41+
echo ""
42+
43+
# Cleanup commands
44+
cleanup_commands=(
45+
"Remove old release builds older than 7 days: find target/release -name '*.rlib' -mtime +7 -delete"
46+
"Remove debug rlibs older than 3 days: find target/debug -name '*.rlib' -mtime +3 -delete"
47+
"Remove doc directory: rm -rf target/doc"
48+
"Remove incremental compilation: rm -rf target/*/incremental"
49+
)
50+
51+
if [ "$AGGRESSIVE" = true ]; then
52+
cleanup_commands+=(
53+
"Remove all debug builds: cargo clean --debug"
54+
"Remove example builds: find target -name 'examples' -type d -exec rm -rf {} +"
55+
"Remove benchmark builds: find target -name 'benches' -type d -exec rm -rf {} +"
56+
)
57+
fi
58+
59+
# Execute cleanup
60+
for cmd in "${cleanup_commands[@]}"; do
61+
echo "Executing: $cmd"
62+
if [ "$DRY_RUN" = false ]; then
63+
eval "$cmd" 2>/dev/null || true
64+
fi
65+
done
66+
67+
echo ""
68+
69+
# Show sizes of large directories
70+
echo "=== Large directories in target ==="
71+
72+
find target -maxdepth 2 -type d -exec du -sh {} \; 2>/dev/null | sort -rh | head -20 || true
73+
74+
echo ""
75+
76+
# Final size after cleanup
77+
echo "Target directory size after cleanup:"
78+
du -sh target/ 2>/dev/null || echo "No target directory found"
79+
80+
echo ""
81+
if [ "$DRY_RUN" = false ]; then
82+
echo "Cleanup completed!"
83+
echo "Run with --dry-run to preview changes"
84+
else
85+
echo "Dry run completed. Run without --dry-run to execute cleanup."
86+
fi

0 commit comments

Comments
 (0)