This repository has been archived by the owner on Jan 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
Copy pathdo.sh
executable file
·147 lines (135 loc) · 3.14 KB
/
do.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env bash
cd "$(dirname "$0")"
usage() {
cat <<EOF
Usage: do.sh <action> <project>
Supported actions:
build
clean
clippy
doc
dump
fmt
test
update
EOF
}
sdkParentDir=bin
sdkDir="$sdkParentDir"/bpf-sdk
targetDir="$PWD"/"$2"/target
profile=bpfel-unknown-unknown/release
perform_action() {
set -e
case "$1" in
build)
"$sdkDir"/rust/build.sh "$2"
so_path="$targetDir/$profile"
so_name="spl_${3%/}"
if [ -f "$so_path/${so_name}.so" ]; then
cp "$so_path/${so_name}.so" "$so_path/${so_name}_debug.so"
"$sdkDir"/dependencies/llvm-native/bin/llvm-objcopy --strip-all "$so_path/${so_name}.so" "$so_path/$so_name.so"
fi
;;
clean)
"$sdkDir"/rust/clean.sh "$2"
;;
test)
(
cd "$2"
echo "test $2"
cargo +nightly test
)
;;
clippy)
(
cd "$2"
echo "clippy $2"
cargo +nightly clippy
)
;;
fmt)
(
cd "$2"
echo "formatting $2"
cargo fmt
)
;;
doc)
(
cd "$2"
echo "generating docs $2"
cargo doc
)
;;
update)
mkdir -p $sdkParentDir
./bpf-sdk-install.sh $sdkParentDir
./do.sh clean
;;
dump)
# Dump depends on tools that are not installed by default and must be installed manually
# - greadelf
# - rustfilt
(
download_bpf_sdk
pwd
"$0" build "$3"
cd "$3"
so_path="$targetDir/$profile"
so_name="solana_bpf_${3%/}"
so="$so_path/${so_name}_debug.so"
dump="$so_path/${so_name}-dump"
if [ -f "$so" ]; then
ls \
-la \
"$so" \
>"${dump}-mangled.txt"
greadelf \
-aW \
"$so" \
>>"${dump}-mangled.txt"
"$sdkDir/dependencies/llvm-native/bin/llvm-objdump" \
-print-imm-hex \
--source \
--disassemble \
"$so" \
>>"${dump}-mangled.txt"
sed \
s/://g \
< "${dump}-mangled.txt" \
| rustfilt \
> "${dump}.txt"
else
echo "Warning: No dump created, cannot find: $so"
fi
)
;;
help)
usage
exit
;;
*)
echo "Error: Unknown command"
usage
exit
;;
esac
}
set -e
if [[ "$#" -ne 2 ]]; then
if [[ $1 == "update" ]]; then
perform_action "$1"
else
# Build all projects
for project in */; do
if [[ -f "$project"Cargo.toml ]]; then
perform_action "$1" "$PWD/$project" "$project"
else
continue;
fi
done
fi
else
# Build requested project
perform_action "$1" "$PWD/$2" "$2"
fi