diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 736f8d1d..ce8138c5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,3 +57,11 @@ jobs: - run: rustup target add riscv32i-unknown-none-elf - run: assets/scripts/smoke.sh examples/src/bin/fib3.rs - run: assets/scripts/smoke.sh examples/src/bin/hello.rs + + test-sdk: + needs: check-build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: rustup target add riscv32i-unknown-none-elf + - run: assets/scripts/test_sdk.sh examples/src/bin/hello.rs diff --git a/assets/scripts/test_sdk.sh b/assets/scripts/test_sdk.sh new file mode 100755 index 00000000..4e93c15a --- /dev/null +++ b/assets/scripts/test_sdk.sh @@ -0,0 +1,59 @@ +#!/bin/bash +# This script follows steps written in README.md +# Using the rust file specified as the unique argument. +# Call at the top directory of the nexus-zkvm project +# For example: +# ./assets/scripts/test_sdk.sh examples/src/bin/fib3.rs +# Every command needs to succeed +set -e + +ORIGINAL_DIR=$(pwd) +PROJECT_NAME="/tmp/nexus-host-ci" + +if [ "$#" -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +if [ ! -f "$1" ]; then + echo "Usage: $0 " + echo "where is a path to a file." + exit 1 +fi + +if [ -e "$PROJECT_NAME" ]; then + echo "Error: Directory '$PROJECT_NAME' already exists." + exit 1 +fi + +set -x + +cleanup() { + cd "$ORIGINAL_DIR" + rm -rf "$PROJECT_NAME" +} + +trap cleanup SIGINT + +error_handler() { + echo "Error occurred in test_sdk.sh on line ${1}. Exiting." + cleanup + exit 1 +} + +trap 'error_handler $LINENO' ERR + +# Builds current cargo-nexus tool from current commit +cargo build --release --package cargo-nexus --bin cargo-nexus +./target/release/cargo-nexus nexus host "$PROJECT_NAME" +# Copy the test source file to guest program +cp "$1" "$PROJECT_NAME/src/guest/src/main.rs" +cd "$PROJECT_NAME" + +# Link the test program to the current sdk commit +sed -e "s#nexus-sdk = { git = \"https://github.com/nexus-xyz/nexus-zkvm.git\", version = \"0.2.0\" }#nexus-sdk = { path = \"$ORIGINAL_DIR/sdk\"}#" Cargo.toml > Cargo.tmp && mv Cargo.tmp Cargo.toml + +cargo update +cargo run --release + +cleanup