-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
99 lines (83 loc) · 2.5 KB
/
build.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
#!/bin/bash
# EXAMPLE USAGE:
# build.sh andromeda-contract some-category
# Builds "andromeda-contract" contract and "some-category" category
# LOG all the contracts compiled with there compressed file size
FILE_LOG=""
get_version_filename (){
local CONTRACT=$1
# Get the version of the contract processed
local BUILD_VERSION=$(cargo pkgid $CONTRACT | cut -d# -f2 | cut -d: -f2)
local BUILD_TARGET=${CONTRACT//-/_}
echo "$BUILD_TARGET@$BUILD_VERSION";
}
build_contract () {
local CONTRACT_PATH=$1;
local CONTRACT=`basename $CONTRACT_PATH`;
echo "Building contract $CONTRACT..."
cargo wasm -p $CONTRACT -q
local BUILD_TARGET=${CONTRACT//-/_}
local VERSION_FILENAME=$(get_version_filename $CONTRACT);
local IN_FILE="./target/wasm32-unknown-unknown/release/$BUILD_TARGET.wasm"
local OUT_FILE="./artifacts/$VERSION_FILENAME.wasm"
wasm-opt -Os $IN_FILE -o $OUT_FILE
# NOT SO IMPORTANT STEPS
# Log wasm file sizes at the end of build process
local IN_FILESIZE=$(($(wc -c <"$IN_FILE") +0))
local OUT_FILESIZE=$(($(wc -c <"$OUT_FILE") +0))
local LOG="$BUILD_TARGET \t\t: $IN_FILESIZE \t- $OUT_FILESIZE bytes"
FILE_LOG="$FILE_LOG\n$LOG"
}
build_category () {
for directory in contracts/*/; do
if [[ "$(basename $directory)" = "$1" ]]; then
echo "Building all contracts in category $(basename $directory)..."
for contract in $directory/*/; do
build_contract $contract;
done
break
fi
done
}
# Helper function to build all contracts with build all command
build_all() {
for directory in contracts/*/; do
build_category $(basename $directory)
done
}
is_contract() {
for directory in contracts/*/; do
for contract in $directory/*/; do
if [[ "$(basename $contract)" = "$1" ]]; then
return 0
fi
done
done
return 1
}
is_category() {
for directory in contracts/*/; do
if [[ "$(basename $directory)" = "$1" ]]; then
return 0
fi
done
return 1
}
export RUSTFLAGS="-C link-arg=-s"
#Clear current builds
rm -rf ./target
rm -rf ./artifacts
mkdir artifacts
for target in "$@"; do
if [[ "$target" = "all" ]]; then
build_all
elif is_contract $target; then
build_contract $target
elif is_category $target; then
build_category $target
else
echo "$target is not a valid target"
exit 1
fi
echo -e "$FILE_LOG"
done