-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.sh
71 lines (59 loc) · 1.84 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
#!/bin/bash
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
YELLOW='\033[1;33m'
# Check for input argument
if [ -z "$1" ]; then
echo -e "${RED}Error: No contract name provided!${NC}"
echo "Usage: sh build.sh <contract_name>"
exit 1
fi
# Contract name
CONTRACT="$1"
# Directories
CONTRACTS_DIR="$PWD"
BUILD_DIR="$CONTRACTS_DIR/build"
CPP_FILE="$CONTRACTS_DIR/src/$CONTRACT.cpp"
HPP_FILE="$CONTRACTS_DIR/include/$CONTRACT.hpp"
echo -e "${YELLOW}Building $CONTRACT contract...${NC}"
# Check if files exist
if [ ! -f "$CPP_FILE" ] || [ ! -f "$HPP_FILE" ]; then
echo -e "${RED}Error: Contract source files not found!${NC}"
echo "Expected files:"
echo "- $CPP_FILE"
echo "- $HPP_FILE"
exit 1
fi
# Create build directory if it doesn't exist
mkdir -p $BUILD_DIR
# Build the contract
echo -e "${YELLOW}Compiling...${NC}"
# Clean any previous build
rm -f $BUILD_DIR/$CONTRACT.wasm
rm -f $BUILD_DIR/$CONTRACT.abi
# Compile the contract and filter out ricardian warnings and their associated lines
cdt-cpp \
-abigen \
--no-missing-ricardian-clause \
-I "$CONTRACTS_DIR/include" \
-contract=$CONTRACT \
-o "$BUILD_DIR/$CONTRACT.wasm" \
"$CPP_FILE" 2>&1 | grep -v -E "warning: abigen warning \(Action .* does not have a ricardian contract\)|ACTION.*::|^\s*\^$"
# Check the exit status of cdt-cpp
if [ ${PIPESTATUS[0]} -eq 0 ]; then
echo -e "${GREEN}Build successful!${NC}"
echo -e "Output files:"
echo -e "- $BUILD_DIR/$CONTRACT.wasm"
echo -e "- $BUILD_DIR/$CONTRACT.abi"
# Display file sizes
WASM_SIZE=$(ls -lh "$BUILD_DIR/$CONTRACT.wasm" | awk '{print $5}')
ABI_SIZE=$(ls -lh "$BUILD_DIR/$CONTRACT.abi" | awk '{print $5}')
echo -e "\nFile sizes:"
echo -e "WASM: $WASM_SIZE"
echo -e "ABI: $ABI_SIZE"
else
echo -e "${RED}Build failed!${NC}"
exit 1
fi