-
Notifications
You must be signed in to change notification settings - Fork 593
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·398 lines (348 loc) · 15.5 KB
/
bootstrap.sh
File metadata and controls
executable file
·398 lines (348 loc) · 15.5 KB
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
#!/usr/bin/env bash
source $(git rev-parse --show-toplevel)/ci3/source_bootstrap
if [ "${AVM:-1}" -eq "1" ]; then
export native_preset=${NATIVE_PRESET:-clang20}
else
export native_preset=${NATIVE_PRESET:-clang20-no-avm}
fi
export hash=$(hash_str $(../../avm-transpiler/bootstrap.sh hash) $(cache_content_hash .rebuild_patterns))
export native_build_dir=$(scripts/preset-build-dir $native_preset)
# Injects version number into a given bb binary.
# Means we don't actually need to rebuild bb to release a new version if code hasn't changed.
# Uses a sentinel prefix to reliably find the version location, enabling re-injection on cached binaries.
function inject_version {
local binary=$1
if semver check "$REF_NAME"; then
local version=${REF_NAME#v}
else
# Otherwise, use the commit hash as the version.
local version=$(git rev-parse --short HEAD)
fi
local sentinel='BARRETENBERG_VERSION_SENTINEL'
local version_space='00000000.00000000.00000000'
if [ ${#version} -gt ${#version_space} ]; then
echo "Error: version ($version) is longer than available space. Cannot update bb binaries." >&2
exit 1
fi
# Find the sentinel and write version at the offset after it
local sentinel_offset=$(grep -aobF "$sentinel" "$binary" 2>/dev/null | head -n 1 | cut -d: -f1)
if [ -z "$sentinel_offset" ]; then
echo "Warning: sentinel not found in $binary - skipping version injection (binary may be from old build)" >&2
return 0
fi
# Version starts immediately after the sentinel
local version_offset=$((sentinel_offset + ${#sentinel}))
printf "$version\0" | dd of="$binary" bs=1 seek=$version_offset conv=notrunc 2>/dev/null
# Re-sign after modifying the binary.
# On macOS, use codesign. On Linux amd64, use ldid for Mach-O cross-compiled binaries.
# ARM64 Linux instances don't need ldid — all macOS release artifacts are published from amd64.
if [[ "$(os)" == "macos" ]]; then
codesign -s - -f "$binary" 2>/dev/null || true
elif [[ "$(arch)" == "amd64" ]] && llvm-objdump-20 --macho --private-header "$binary" 2>/dev/null | grep -q "Mach header"; then
ldid -S "$binary"
fi
}
# Inject version into all bb binaries in a directory (no-op if none exist).
function inject_bb_versions {
local bin_dir=$1
for f in "$bin_dir"/bb "$bin_dir"/bb.exe "$bin_dir"/bb-avm; do
if [ -f "$f" ]; then
inject_version "$f"
fi
done
}
# Raw cmake configure + build. Internal helper.
function cmake_build {
local preset=$1
shift
local cmake_args=()
if [ "${AVM_TRANSPILER:-1}" -eq 0 ]; then
cmake_args+=(-DAVM_TRANSPILER_LIB=)
fi
cmake --preset "$preset" "${cmake_args[@]}"
cmake --build --preset "$preset" "$@"
}
# Returns cache paths for a preset's build outputs.
# If preset has explicit targets: finds those specific files in bin/ and lib/.
# Otherwise: returns existing {bin,lib} dirs (catch-all).
function preset_cache_paths {
local preset=$1
local build_dir=$2
local targets=$(jq -r --arg p "$preset" '
.buildPresets[] | select(.name==$p) | .targets // [] | .[]
' CMakePresets.json)
if [ -z "$targets" ]; then
for d in $build_dir/bin $build_dir/lib; do
[ -d "$d" ] && echo "$d"
done
else
for t in $targets; do
find $build_dir/bin $build_dir/lib \
-maxdepth 1 \( -name "$t" -o -name "$t.exe" -o -name "$t.node" -o -name "lib${t}.a" \) \
2>/dev/null
done
fi
}
# Cache-aware build: download from cache or build + upload, then inject versions.
# Usage: build_preset <preset>
function build_preset {
set -eu
local preset=$1
local build_dir=$(scripts/preset-build-dir $preset)
if ! cache_download barretenberg-$preset-$hash.zst; then
cmake_build $preset
cache_upload barretenberg-$preset-$hash.zst $(preset_cache_paths $preset $build_dir)
fi
inject_bb_versions $build_dir/bin
}
# Only check formatting if we're actually going to build (not cached).
function build_format_check {
if ! cache_exists barretenberg-$native_preset-$hash.zst; then
./format.sh check
fi
}
# Builds as many targets as possible that don't have any external dependencies, e.g. on avm_transpiler.
# Allow the build system to get a head start on compilation while building dependencies.
# This is a noop if the final artifacts exist in the cache.
function build_native_objects {
set -eu
if ! cache_exists barretenberg-$native_preset-$hash.zst; then
cmake --preset "$native_preset"
targets=$(cmake --build --preset "$native_preset" --target help | awk -F: '$1 ~ /(_objects|_tests|_bench|_gen|.a)$/ && $1 !~ /^cmake_/{print $1}' | tr '\n' ' ')
cmake --build --preset "$native_preset" --target $targets nodejs_module
fi
}
function build_native { build_preset $native_preset; }
# Builds object files early for cross compilation (parallel with avm-transpiler).
function build_cross_objects {
set -eu
target=$1
if ! cache_exists barretenberg-$target-$hash.zst; then
cmake_build $target --target barretenberg vm2_stub vm2_sim circuit_checker honk
fi
}
# Build GCC - but only syntax check.
# Note we do miss some deeper GCC checks this way, but they were as noisy
# as they were useful historically, and we have sanitizers.
function build_gcc_syntax_check_only {
set -eu
if cache_download barretenberg-gcc-$hash.zst; then
return
fi
cmake --preset gcc -DSYNTAX_ONLY=1
cmake --build --preset gcc --target bb
# Note: There's no real artifact here, we fake one for consistency.
echo success > build-gcc/syntax-check-success.flag
cache_upload barretenberg-gcc-$hash.zst build-gcc/syntax-check-success.flag
}
# Do basic tests that the fuzzing and fuzzing-avm presets still compile (does not do optimization or create object files).
function build_fuzzing_syntax_check_only {
set -eu
if cache_download barretenberg-fuzzing-$hash.zst; then
return
fi
cmake --preset fuzzing -DSYNTAX_ONLY=1
cmake --build --preset fuzzing
cmake --preset fuzzing-avm -DSYNTAX_ONLY=1
cmake --build --preset fuzzing-avm
# Note: There's no real artifact here, we fake one for consistency.
echo success > build-fuzzing/syntax-check-success.flag
cache_upload barretenberg-fuzzing-$hash.zst build-fuzzing/syntax-check-success.flag
}
# Do basic tests that the smt preset still compiles and runs
function build_smt_verification {
set -eu
if cache_download barretenberg-smt-$hash.zst; then
return
fi
if ! dpkg -l python3-pip python3-venv m4 bison >/dev/null 2>&1; then
sudo apt update && sudo apt install -y python3-pip python3-venv m4 bison
fi
cmake --preset smt-verification
cvc5_cmake_hash=$(cache_content_hash ^barretenberg/cpp/src/barretenberg/smt_verification/CMakeLists.txt)
if cache_download barretenberg-cvc5-$cvc5_cmake_hash.zst; then
# Restore machine-dependent paths after downloading cache
find build-smt/_deps/cvc5 -type f -name "*.cmake" -exec sed -i "s|/workspace|$(pwd)|g" {} \;
else
cmake --build build-smt --target cvc5
cache_upload barretenberg-cvc5-$cvc5_cmake_hash.zst build-smt/_deps/cvc5
fi
cmake --build build-smt --target smt_verification_tests
cache_upload barretenberg-smt-$hash.zst build-smt
}
function build_release_dir {
local arch=$(arch)
rm -rf build-release
mkdir build-release
# Native (should be amd64-linux) builds.
tar -czf build-release/barretenberg-$arch-linux.tar.gz -C $native_build_dir/bin bb
tar -czf build-release/barretenberg-avm-$arch-linux.tar.gz -C $native_build_dir/bin bb-avm
# Wasm.
tar -czf build-release/barretenberg-wasm.tar.gz -C build-wasm/bin barretenberg.wasm
tar -czf build-release/barretenberg-threads-wasm.tar.gz -C build-wasm-threads/bin barretenberg.wasm
# bb cross-compiles.
tar -czf build-release/barretenberg-arm64-linux.tar.gz -C build-arm64-linux/bin bb
tar -czf build-release/barretenberg-arm64-darwin.tar.gz -C build-arm64-macos/bin bb
tar -czf build-release/barretenberg-amd64-darwin.tar.gz -C build-amd64-macos/bin bb
tar -czf build-release/barretenberg-amd64-windows.tar.gz -C build-amd64-windows/bin bb.exe
# Package static libraries for FFI bindings (stripped at build time via CMake POST_BUILD).
tar -czf build-release/barretenberg-static-amd64-linux.tar.gz -C $native_build_dir/lib libbb-external.a
tar -czf build-release/barretenberg-static-arm64-linux.tar.gz -C build-arm64-linux/lib libbb-external.a
tar -czf build-release/barretenberg-static-amd64-darwin.tar.gz -C build-amd64-macos/lib libbb-external.a
tar -czf build-release/barretenberg-static-arm64-darwin.tar.gz -C build-arm64-macos/lib libbb-external.a
tar -czf build-release/barretenberg-static-amd64-windows.tar.gz -C build-amd64-windows/lib libbb-external.a
tar -czf build-release/barretenberg-static-arm64-ios.tar.gz -C build-arm64-ios/lib libbb-external.a
tar -czf build-release/barretenberg-static-arm64-ios-sim.tar.gz -C build-arm64-ios-sim/lib libbb-external.a
tar -czf build-release/barretenberg-static-arm64-android.tar.gz -C build-arm64-android/lib libbb-external.a
tar -czf build-release/barretenberg-static-x86_64-android.tar.gz -C build-x86_64-android/lib libbb-external.a
}
export -f cmake_build preset_cache_paths build_preset build_format_check build_native_objects build_cross_objects build_native build_gcc_syntax_check_only build_fuzzing_syntax_check_only build_smt_verification inject_version inject_bb_versions
function build {
echo_header "bb cpp build"
if [ "$CI_FULL" -eq 1 ]; then
# Deletes all build dirs and build bb and wasms from scratch.
rm -rf build*
(cd $root && make bb-cpp-full)
else
(cd $root && make bb-cpp)
fi
}
function test_cmds_native {
# E.g. build, build-debug or build-coverage
cd $native_build_dir
for bin in ./bin/*_tests; do
local bin_name=$(basename $bin)
$bin --gtest_list_tests | \
awk '/^[a-zA-Z]/ {suite=$1} /^[ ]/ {print suite$1}' | \
grep -v 'DISABLED_' | \
while read -r test; do
local prefix=$hash
# A little extra resource for these tests.
# IPARecursiveTests fails with 2 threads.
if [[ "$test" =~ ^(AcirAvmRecursionConstraint|ChonkKernelCapacity|AvmRecursiveTests|IPARecursiveTests|HonkRecursionConstraintTest|ChonkRecursionConstraintTest) ]]; then
prefix="$prefix:CPUS=4:MEM=8g"
fi
# These tests routinely take 400-600s in debug builds; bump from the 600s default.
if [[ "$test" =~ ^(HonkRecursionConstraintTest|ChonkRecursionConstraintTest) ]]; then
prefix="$prefix:TIMEOUT=900s"
fi
echo -e "$prefix barretenberg/cpp/scripts/run_test.sh $bin_name $test"
done || (echo "Failed to list tests in $bin" && exit 1)
done
echo "$hash barretenberg/cpp/scripts/test_chonk_standalone_vks_havent_changed.sh"
}
function test_cmds_wasm_threads {
# We only want to sanity check that we haven't broken wasm ecc in merge queue.
echo "$hash barretenberg/cpp/scripts/wasmtime.sh barretenberg/cpp/build-wasm-threads/bin/ecc_tests"
}
function test_cmds_asan {
local prefix="$hash:CPUS=4:MEM=8g"
# Mostly arbitrary set that touches lots of the code.
declare -A asan_tests=(
["commitment_schemes_recursion_tests"]="IPARecursiveTests.AccumulationAndFullRecursiveVerifier"
["chonk_tests"]="ChonkTests.Basic"
["ultra_honk_tests"]="MegaHonkTests/0.Basic"
["dsl_tests"]="HonkRecursionConstraintTestWithoutPredicate/2.Tampering"
)
for bin_name in "${!asan_tests[@]}"; do
local filter=${asan_tests[$bin_name]}
echo -e "$prefix barretenberg/cpp/build-asan-fast/bin/$bin_name --gtest_filter=$filter"
done
}
function test_cmds_smt {
local prefix="$hash:CPUS=4:MEM=8g"
echo -e "$prefix barretenberg/cpp/build-smt/bin/smt_verification_tests"
}
# Print every individual test command. Can be fed into gnu parallel.
# Paths are relative to repo root.
# We prefix the hash. This ensures the test harness and cache and skip future runs.
function test_cmds {
if [ -z "${1:-}" ]; then
test_cmds_native
if [ "$CI_FULL" -eq 1 ]; then
test_cmds_wasm_threads
test_cmds_asan
test_cmds_smt
fi
else
test_cmds_$1
fi
}
# This is not called in ci. It is just for a developer to run the tests.
function test {
echo_header "bb test"
test_cmds | filter_test_cmds | parallelize
}
function bench_cmds {
prefix="$hash:CPUS=8"
echo "$prefix barretenberg/cpp/scripts/run_bench.sh native bb-micro-bench/native/ultra_honk $native_build_dir/bin/ultra_honk_bench construct_proof_ultrahonk_power_of_2/20$"
echo "$prefix barretenberg/cpp/scripts/run_bench.sh native bb-micro-bench/native/ultra_honk_zk $native_build_dir/bin/ultra_honk_bench construct_proof_ultrahonk_zk_power_of_2/20$"
echo "$prefix barretenberg/cpp/scripts/run_bench.sh native bb-micro-bench/native/chonk $native_build_dir/bin/chonk_bench ChonkBench/Full/5$"
echo "$prefix barretenberg/cpp/scripts/run_bench.sh wasm bb-micro-bench/wasm/ultra_honk build-wasm-threads/bin/ultra_honk_bench construct_proof_ultrahonk_power_of_2/20$"
echo "$prefix barretenberg/cpp/scripts/run_bench.sh wasm bb-micro-bench/wasm/ultra_honk_zk build-wasm-threads/bin/ultra_honk_bench construct_proof_ultrahonk_zk_power_of_2/20$"
echo "$prefix barretenberg/cpp/scripts/run_bench.sh wasm bb-micro-bench/wasm/chonk build-wasm-threads/bin/chonk_bench ChonkBench/Full/5$"
prefix="$hash:CPUS=1"
echo "$prefix barretenberg/cpp/scripts/run_bench.sh native bb-micro-bench/native/chonk_verify $native_build_dir/bin/chonk_bench VerificationOnly$"
}
# Runs benchmarks sharded over machine cores.
function bench {
echo_header "bb bench"
rm -rf bench-out && mkdir -p bench-out
bench_cmds | STRICT_SCHEDULING=1 parallelize
}
# Upload assets to release in AztecProtocol/barretenberg.
function release {
echo_header "bb cpp release"
do_or_dryrun gh release upload $REF_NAME build-release/* --repo AztecProtocol/barretenberg --clobber
}
function bench_ivc {
# Intended only for dev usage. For CI usage, we run yarn-project/end-to-end/bootstrap.sh bench.
# Sample usage (CI=1 required for bench results to be visible; exclude NO_WASM=1 to run wasm benchmarks):
# CI=1 NO_WASM=1 ./barretenberg/cpp/bootstrap.sh bench_ivc transfer_0_recursions+sponsored_fpc
git fetch origin next
flow_filter="${1:-}" # optional string-match filter for flow names
commit_hash="${2:-origin/next~3}" # commit from which to download flow inputs
# Build both native and wasm benchmark binaries
builds=(
"cmake_build $native_preset --target bb"
)
if [[ "${NO_WASM:-}" != "1" ]]; then
builds+=("cmake_build wasm-threads --target bb")
fi
parallel --line-buffered --tag -v denoise ::: "${builds[@]}"
# Download cached flow inputs from the specified commit
export AZTEC_CACHE_COMMIT=$commit_hash
# TODO currently does nothing! to reinstate in cache_download
export FORCE_CACHE_DOWNLOAD=${FORCE_CACHE_DOWNLOAD:-1}
# make sure that disabling the aztec VM does not interfere with cache results from CI.
BOOTSTRAP_AFTER=barretenberg BOOSTRAP_TO=yarn-project ../../bootstrap.sh
rm -rf bench-out
# Recreation of logic from bench.
../../yarn-project/end-to-end/bootstrap.sh build_bench
# Extract and filter benchmark commands by flow name and wasm/no-wasm
function ivc_bench_cmds {
local flow_filter="$1" # select only flows containing this string
../../yarn-project/end-to-end/bootstrap.sh bench_cmds |
grep barretenberg/cpp/scripts/ci_benchmark_ivc_flows.sh |
{ [[ "${NO_WASM:-}" == "1" ]] && grep -v wasm || cat; } |
{ [[ -n "$flow_filter" ]] && grep -F "$flow_filter" || cat; }
}
echo "Running commands:"
ivc_bench_cmds "$flow_filter"
ivc_bench_cmds "$flow_filter" | STRICT_SCHEDULING=1 parallelize
}
case "$cmd" in
"")
build
;;
"ci")
build
test
;;
"hash")
echo $hash
;;
*)
default_cmd_handler "$@"
;;
esac