|
| 1 | +#!/usr/bin/env bash |
| 2 | +# rust/build-toolchain.sh |
| 3 | +# Builds the SP1 custom toolchain and packs stage2 into rust-toolchain-<host>.tar.gz |
| 4 | + |
| 5 | +set -euo pipefail |
| 6 | + |
| 7 | +TARGET_RISCV="riscv64im-succinct-zkvm-elf" |
| 8 | +HOST_TRIPLE="$(rustc -vV | awk '/^host:/ {print $2}')" |
| 9 | + |
| 10 | +echo "==> host triple: $HOST_TRIPLE" |
| 11 | +echo "==> building rust stage2 for targets: $TARGET_RISCV, $HOST_TRIPLE" |
| 12 | + |
| 13 | +############################## |
| 14 | +# 1. one-line sanity work-arounds |
| 15 | +############################## |
| 16 | +TMP_TARGET_DIR="$(mktemp -d)" |
| 17 | +touch "$TMP_TARGET_DIR/${TARGET_RISCV}.json" # bypass target-sanity check |
| 18 | +export RUST_TARGET_PATH="$TMP_TARGET_DIR" |
| 19 | +export CARGO_TARGET_RISCV64IM_SUCCINCT_ZKVM_ELF_RUSTFLAGS="-Cpasses=lower-atomic" |
| 20 | + |
| 21 | +############################## |
| 22 | +# 2. compile |
| 23 | +############################## |
| 24 | + cat > bootstrap.toml <<TOML |
| 25 | +[build] |
| 26 | +extended = true |
| 27 | +tools = ["cargo", "cargo-clippy", "clippy", "rustfmt"] |
| 28 | +configure-args = [] |
| 29 | +cargo-native-static = true |
| 30 | +
|
| 31 | +[rust] |
| 32 | +lld = true |
| 33 | +llvm-tools = true |
| 34 | +
|
| 35 | +[llvm] |
| 36 | +download-ci-llvm = false |
| 37 | +TOML |
| 38 | + |
| 39 | +python3 x.py build --stage 2 library \ |
| 40 | + --target "${TARGET_RISCV},${HOST_TRIPLE}" |
| 41 | + |
| 42 | +############################## |
| 43 | +# 3. pack artifact |
| 44 | +############################## |
| 45 | +STAGE2_DIR="$(find build -maxdepth 2 -type d -name stage2 | head -n1)" |
| 46 | +[[ -d "$STAGE2_DIR" ]] || { echo "error: stage2 not found"; exit 1; } |
| 47 | + |
| 48 | +OUT_TAR="rust-toolchain-${HOST_TRIPLE}.tar.gz" |
| 49 | +tar --exclude 'lib/rustlib/src' \ |
| 50 | + --exclude 'lib/rustlib/rustc-src' \ |
| 51 | + -hczvf "$OUT_TAR" -C "$STAGE2_DIR" . |
| 52 | + |
| 53 | +echo "==> done – artifact: $OUT_TAR" |
0 commit comments