1+ #! /usr/bin/env bash
2+
3+ # Star Frame Tutorial SBF Builder
4+ # Build all tutorial programs as Solana BPF/SBF (.so files)
5+
6+ set -e
7+
8+ # Colors for output
9+ RED=' \033[0;31m'
10+ GREEN=' \033[0;32m'
11+ YELLOW=' \033[0;33m'
12+ BLUE=' \033[0;34m'
13+ NC=' \033[0m' # No Color
14+
15+ # Configuration
16+ TUTORIALS=(" basic-0" " basic-1" " basic-2" " basic-4" " basic-5" )
17+ BASIC_3_PROGRAMS=(" puppet" " puppet-master" )
18+ FAILED_BUILDS=()
19+
20+ # Function to print colored output
21+ print_color () {
22+ echo -e " ${1}${2}${NC} "
23+ }
24+
25+ # Function to print section header
26+ print_header () {
27+ echo " "
28+ print_color " $BLUE " " ========================================="
29+ print_color " $BLUE " " $1 "
30+ print_color " $BLUE " " ========================================="
31+ }
32+
33+ # Function to build a single program
34+ build_program () {
35+ local dir=$1
36+ local name=$2
37+
38+ if [ -d " $dir " ]; then
39+ print_color " $YELLOW " " Building $name as SBF..."
40+
41+ if (cd " $dir " && cargo build-sbf 2>&1 | tee build.log); then
42+ # Check if .so file was created
43+ if [ -f " $dir /target/deploy/${name// -/ _} .so" ]; then
44+ print_color " $GREEN " " ✓ $name built successfully"
45+ local size=$( du -h " $dir /target/deploy/${name// -/ _} .so" | cut -f1)
46+ print_color " $GREEN " " → Program size: $size "
47+ else
48+ print_color " $RED " " ✗ $name build completed but .so file not found"
49+ FAILED_BUILDS+=(" $name " )
50+ fi
51+ else
52+ print_color " $RED " " ✗ Failed to build $name "
53+ FAILED_BUILDS+=(" $name " )
54+ fi
55+ else
56+ print_color " $YELLOW " " ⚠ Directory $dir not found, skipping..."
57+ fi
58+ }
59+
60+ # Function to test a program with SBF
61+ test_program () {
62+ local dir=$1
63+ local name=$2
64+
65+ if [ -d " $dir " ] && [ -f " $dir /target/deploy/${name// -/ _} .so" ]; then
66+ print_color " $YELLOW " " Testing $name with SBF binary..."
67+
68+ if (cd " $dir " && USE_BIN=true cargo test 2>&1 | grep -E " (test result:|passed|failed)" ); then
69+ print_color " $GREEN " " ✓ $name tests completed"
70+ else
71+ print_color " $RED " " ✗ $name tests failed or had issues"
72+ fi
73+ fi
74+ }
75+
76+ # Main execution
77+ main () {
78+ print_header " Star Frame Tutorial SBF Builder"
79+
80+ # Parse command line arguments
81+ RUN_TESTS=false
82+ CLEAN_FIRST=false
83+
84+ while [[ $# -gt 0 ]]; do
85+ case $1 in
86+ --test)
87+ RUN_TESTS=true
88+ shift
89+ ;;
90+ --clean)
91+ CLEAN_FIRST=true
92+ shift
93+ ;;
94+ --help)
95+ echo " Usage: $0 [OPTIONS]"
96+ echo " "
97+ echo " Options:"
98+ echo " --test Run tests after building"
99+ echo " --clean Clean before building"
100+ echo " --help Show this help message"
101+ exit 0
102+ ;;
103+ * )
104+ echo " Unknown option: $1 "
105+ echo " Use --help for usage information"
106+ exit 1
107+ ;;
108+ esac
109+ done
110+
111+ # Clean if requested
112+ if [ " $CLEAN_FIRST " = true ]; then
113+ print_header " Cleaning Previous Builds"
114+ for tutorial in " ${TUTORIALS[@]} " ; do
115+ if [ -d " $tutorial /target/deploy" ]; then
116+ print_color " $YELLOW " " Cleaning $tutorial ..."
117+ rm -rf " $tutorial /target/deploy"
118+ fi
119+ done
120+
121+ for program in " ${BASIC_3_PROGRAMS[@]} " ; do
122+ if [ -d " basic-3/$program /target/deploy" ]; then
123+ print_color " $YELLOW " " Cleaning basic-3/$program ..."
124+ rm -rf " basic-3/$program /target/deploy"
125+ fi
126+ done
127+ fi
128+
129+ # Build basic tutorials
130+ print_header " Building Basic Tutorials"
131+
132+ for tutorial in " ${TUTORIALS[@]} " ; do
133+ build_program " $tutorial " " $tutorial "
134+ done
135+
136+ # Build basic-3 sub-programs
137+ print_header " Building Basic-3 Programs"
138+
139+ for program in " ${BASIC_3_PROGRAMS[@]} " ; do
140+ build_program " basic-3/$program " " $program "
141+ done
142+
143+ # Run tests if requested
144+ if [ " $RUN_TESTS " = true ]; then
145+ print_header " Running Tests with SBF Binaries"
146+
147+ for tutorial in " ${TUTORIALS[@]} " ; do
148+ test_program " $tutorial " " $tutorial "
149+ done
150+
151+ for program in " ${BASIC_3_PROGRAMS[@]} " ; do
152+ test_program " basic-3/$program " " $program "
153+ done
154+ fi
155+
156+ # Summary
157+ print_header " Build Summary"
158+
159+ local total=$(( ${# TUTORIALS[@]} + ${# BASIC_3_PROGRAMS[@]} ))
160+ local succeeded=$(( total - ${# FAILED_BUILDS[@]} ))
161+
162+ print_color " $BLUE " " Total programs: $total "
163+ print_color " $GREEN " " Succeeded: $succeeded "
164+
165+ if [ ${# FAILED_BUILDS[@]} -gt 0 ]; then
166+ print_color " $RED " " Failed: ${# FAILED_BUILDS[@]} "
167+ print_color " $RED " " Failed builds: ${FAILED_BUILDS[*]} "
168+ exit 1
169+ else
170+ print_color " $GREEN " " "
171+ print_color " $GREEN " " ✨ All tutorials built as SBF programs successfully!"
172+ fi
173+ }
174+
175+ # Run main function
176+ main " $@ "
0 commit comments