-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathbuild.sh
executable file
·166 lines (152 loc) · 4.27 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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/env bash
# Any error will result in failure
set -e
TOOLCHAIN_RISC0=+nightly-2024-04-18
TOOLCHAIN_SP1=+nightly-2024-04-18
TOOLCHAIN_SGX=+nightly-2024-04-18
check_toolchain() {
local TOOLCHAIN=$1
# Remove the plus sign from the toolchain name
TOOLCHAIN=${TOOLCHAIN#+}
# Function to check if the toolchain is installed
exist() {
rustup toolchain list | grep "$TOOLCHAIN" >/dev/null
}
# Main script logic
if exist; then
echo "Toolchain $TOOLCHAIN exists"
else
echo "Installing Rust toolchain: $TOOLCHAIN"
rustup install "$TOOLCHAIN"
fi
}
if [ -z "${DEBUG}" ]; then
FLAGS=--release
else
echo "Warning: in debug mode"
fi
if [ -z "${RUN}" ]; then
COMMAND=build
else
COMMAND=run
fi
if [ "$CPU_OPT" = "1" ]; then
export RUSTFLAGS='-C target-cpu=native'
echo "Enable cpu optimization with host RUSTFLAGS"
fi
# NATIVE
if [ -z "$1" ] || [ "$1" == "native" ]; then
if [ -n "${CLIPPY}" ]; then
cargo clippy -- -D warnings
elif [ -z "${RUN}" ]; then
if [ -z "${TEST}" ]; then
echo "Building native prover"
cargo build ${FLAGS}
else
echo "Building native tests"
cargo test ${FLAGS} --no-run
fi
else
if [ -z "${TEST}" ]; then
echo "Running native prover"
cargo run ${FLAGS}
else
echo "Running native tests"
cargo test ${FLAGS}
fi
fi
fi
# SGX
if [ -z "$1" ] || [ "$1" == "sgx" ]; then
check_toolchain $TOOLCHAIN_SGX
if [ "$MOCK" = "1" ]; then
export SGX_DIRECT=1
echo "SGX_DIRECT is set to $SGX_DIRECT"
fi
if [ -n "${CLIPPY}" ]; then
cargo ${TOOLCHAIN_SGX} clippy -p raiko-host -p sgx-prover -F "sgx enable" -- -D warnings
elif [ -z "${RUN}" ]; then
if [ -z "${TEST}" ]; then
echo "Building SGX prover"
cargo ${TOOLCHAIN_SGX} build ${FLAGS} --features sgx
else
echo "Building SGX tests"
cargo ${TOOLCHAIN_SGX} test ${FLAGS} -p raiko-host -p sgx-prover --features "sgx enable" --no-run
fi
else
if [ -z "${TEST}" ]; then
echo "Running SGX prover"
cargo ${TOOLCHAIN_SGX} run ${FLAGS} --features sgx
else
echo "Running SGX tests"
cargo ${TOOLCHAIN_SGX} test ${FLAGS} -p raiko-host -p sgx-prover --features "sgx enable"
fi
fi
fi
# RISC0
if [ -z "$1" ] || [ "$1" == "risc0" ]; then
check_toolchain $TOOLCHAIN_RISC0
./script/setup-bonsai.sh
if [ "$MOCK" = "1" ]; then
export RISC0_DEV_MODE=1
echo "RISC0_DEV_MODE is set to $RISC0_DEV_MODE"
fi
if [ -n "${CLIPPY}" ]; then
MOCK=1
RISC0_DEV_MODE=1
CI=1
cargo ${TOOLCHAIN_RISC0} run --bin risc0-builder
cargo ${TOOLCHAIN_RISC0} clippy -F risc0
elif [ -z "${RUN}" ]; then
if [ -z "${TEST}" ]; then
echo "Building Risc0 prover"
cargo ${TOOLCHAIN_RISC0} run --bin risc0-builder
else
echo "Building test elfs for Risc0 prover"
cargo ${TOOLCHAIN_RISC0} run --bin risc0-builder --features test,bench
fi
cargo ${TOOLCHAIN_RISC0} build ${FLAGS} --features risc0
else
if [ -z "${TEST}" ]; then
echo "Running Risc0 prover"
cargo ${TOOLCHAIN_RISC0} run ${FLAGS} --features risc0
else
echo "Running Risc0 tests"
cargo ${TOOLCHAIN_RISC0} test ${FLAGS} --lib risc0-driver --features risc0 -- run_unittest_elf
cargo ${TOOLCHAIN_RISC0} test ${FLAGS} -p raiko-host -p risc0-driver --features "risc0 enable"
fi
fi
fi
# SP1
if [ -z "$1" ] || [ "$1" == "sp1" ]; then
check_toolchain $TOOLCHAIN_SP1
if [ "$MOCK" = "1" ]; then
export SP1_PROVER=mock
echo "SP1_PROVER is set to $SP1_PROVER"
fi
if [ -n "${CLIPPY}" ]; then
cargo ${TOOLCHAIN_SP1} clippy -p raiko-host -p sp1-builder -p sp1-driver -F "sp1 enable"
elif [ -z "${RUN}" ]; then
if [ -z "${TEST}" ]; then
echo "Building Sp1 prover"
cargo ${TOOLCHAIN_SP1} run --bin sp1-builder
else
echo "Building test elfs for Sp1 prover"
cargo ${TOOLCHAIN_SP1} run --bin sp1-builder --features test,bench
fi
cargo ${TOOLCHAIN_SP1} build ${FLAGS} --features sp1
else
if [ -z "${TEST}" ]; then
if [ -n "$ORCHESTRATOR" ]; then
export ARGS="--sp1-orchestrator-address $ORCHESTRATOR"
echo "Running in worker mode with orchestrator address $ORCHESTRATOR"
fi
echo "Running Sp1 prover"
cargo ${TOOLCHAIN_SP1} run ${FLAGS} --features sp1 -- ${ARGS}
else
echo "Running Sp1 tests"
cargo ${TOOLCHAIN_SP1} test ${FLAGS} --lib sp1-driver --features sp1 -- run_unittest_elf
cargo ${TOOLCHAIN_SP1} test ${FLAGS} -p raiko-host -p sp1-driver --features "sp1 enable"
fi
fi
fi