From b215d169c908f062933e68bd2195925d2907a56f Mon Sep 17 00:00:00 2001 From: Lane Rettig Date: Wed, 14 Aug 2024 15:18:56 -0700 Subject: [PATCH 01/24] Switch to the correct RISC-V toolchain --- build.sh | 60 ++++++++++++++++++++++++++++++++++++++++----- patches/config.toml | 6 +++-- 2 files changed, 58 insertions(+), 8 deletions(-) diff --git a/build.sh b/build.sh index 2cb9cde..baa7363 100755 --- a/build.sh +++ b/build.sh @@ -5,16 +5,64 @@ set -euo pipefail source config.sh # Fail fast if these tools aren't properly installed and in the path -need_cmd riscv64-unknown-elf-gcc -need_cmd riscv64-unknown-elf-g++ +need_cmd riscv32-unknown-elf-clang +need_cmd riscv32-unknown-elf-clang++ # Rust requires a custom target file to exist for our custom target as part of the bootstrap build, # but it doesn't actually look at the contents. -touch /tmp/riscv32em-athena-zkvm-elf.json +cat > /tmp/riscv32em-athena-zkvm-elf.json << EOF +{ + "arch": "riscv32", + "cpu": "generic-rv32", + "crt-objects-fallback": "false", + "data-layout": "e-m:e-p:32:32-i64:64-n32-S32", + "eh-frame-header": false, + "emit-debug-gdb-scripts": false, + "features": "+e,+m", + "linker": "rust-lld", + "linker-flavor": "gnu-lld", + "llvm-abiname": "ilp32e", + "llvm-target": "riscv32", + "max-atomic-width": 32, + "os": "zkvm", + "panic-strategy": "abort", + "relocation-model": "static", + "singlethread": true, + "target-pointer-width": "32", + "vendor": "athena", + "options": { + "c-flags": "-march=rv32e -mabi=ilp32e", + "pre-link-args": { + "gcc": [ + "-march=rv32e", + "-mabi=ilp32e" + ] + } + } +} +EOF + +# Set environment variables to override compiler flags +export CC_riscv32em_athena_zkvm_elf="riscv32-unknown-elf-clang" +export CXX_riscv32em_athena_zkvm_elf="riscv32-unknown-elf-clang++" +export AR_riscv32em_athena_zkvm_elf="riscv32-unknown-elf-ar" + +# Explicitly set CFLAGS without the problematic flags +export CFLAGS_riscv32em_athena_zkvm_elf="-ffunction-sections -fdata-sections -fPIC -target riscv32-unknown-elf" +export CXXFLAGS_riscv32em_athena_zkvm_elf="$CFLAGS_riscv32em_athena_zkvm_elf" + +# Set Rust flags +export CARGO_TARGET_RISCV32EM_ATHENA_ZKVM_ELF_RUSTFLAGS="-Cpasses=loweratomic -Clink-arg=-march=rv32em -Clink-arg=-mabi=ilp32e" + +# Override the default target for compiler-rt +export COMPILER_RT_DEFAULT_TARGET_TRIPLE="riscv32-unknown-elf" + +# Force the use of our custom target spec +export RUST_TARGET_PATH="/tmp" + +# Prevent the build system from adding --target flag +export RUSTC_TARGET_ARG="" # Will create component archives (dists) ./rust/build/dist cd rust -RUST_TARGET_PATH="/tmp" \ -CARGO_TARGET_RISCV32EM_ATHENA_ZKVM_ELF_RUSTFLAGS="-Cpasses=loweratomic" \ -CFLAGS_riscv32em_athena_zkvm_elf="-ffunction-sections -fdata-sections -fPIC -march=rv32em -mabi=ilp32e" \ ./x build --stage 2 diff --git a/patches/config.toml b/patches/config.toml index 1ed3fea..85d9783 100644 --- a/patches/config.toml +++ b/patches/config.toml @@ -7,8 +7,10 @@ tools = ["cargo", "cargo-clippy", "clippy", "rustfmt"] configure-args = [] [target.riscv32em-athena-zkvm-elf] -cc = "riscv64-unknown-elf-gcc" -cxx = "riscv64-unknown-elf-g++" +cc = "riscv32-unknown-elf-clang" +cxx = "riscv32-unknown-elf-clang++" +linker = "riscv32-unknown-elf-gcc" +ar = "riscv32-unknown-elf-ar" [rust] lld = true From 79a5bcece71b9dcda3043028fb34c5927a759ad5 Mon Sep 17 00:00:00 2001 From: Lane Rettig Date: Wed, 14 Aug 2024 15:22:06 -0700 Subject: [PATCH 02/24] Try vanilla clang --- build.sh | 6 +++--- patches/config.toml | 6 ++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/build.sh b/build.sh index baa7363..71e1e42 100755 --- a/build.sh +++ b/build.sh @@ -43,9 +43,9 @@ cat > /tmp/riscv32em-athena-zkvm-elf.json << EOF EOF # Set environment variables to override compiler flags -export CC_riscv32em_athena_zkvm_elf="riscv32-unknown-elf-clang" -export CXX_riscv32em_athena_zkvm_elf="riscv32-unknown-elf-clang++" -export AR_riscv32em_athena_zkvm_elf="riscv32-unknown-elf-ar" +export CC_riscv32em_athena_zkvm_elf="clang" +export CXX_riscv32em_athena_zkvm_elf="clang++" +#export AR_riscv32em_athena_zkvm_elf="ar" # Explicitly set CFLAGS without the problematic flags export CFLAGS_riscv32em_athena_zkvm_elf="-ffunction-sections -fdata-sections -fPIC -target riscv32-unknown-elf" diff --git a/patches/config.toml b/patches/config.toml index 85d9783..e2304da 100644 --- a/patches/config.toml +++ b/patches/config.toml @@ -7,10 +7,8 @@ tools = ["cargo", "cargo-clippy", "clippy", "rustfmt"] configure-args = [] [target.riscv32em-athena-zkvm-elf] -cc = "riscv32-unknown-elf-clang" -cxx = "riscv32-unknown-elf-clang++" -linker = "riscv32-unknown-elf-gcc" -ar = "riscv32-unknown-elf-ar" +cc = "clang" +cxx = "clang++" [rust] lld = true From 6c98114e883a73dc584e4314d86ba9c4afc2cb60 Mon Sep 17 00:00:00 2001 From: Lane Rettig Date: Wed, 14 Aug 2024 15:22:44 -0700 Subject: [PATCH 03/24] Remove the patch --- patch.sh | 3 --- patches/llvm.patch | 17 ----------------- 2 files changed, 20 deletions(-) delete mode 100644 patches/llvm.patch diff --git a/patch.sh b/patch.sh index 0963cab..2ec3ec9 100755 --- a/patch.sh +++ b/patch.sh @@ -5,6 +5,3 @@ set -euo pipefail cd rust patch -p1 < ../patches/rust.patch cp ../patches/config.toml ./ - -cd src/llvm-project -patch -p1 < ../../../patches/llvm.patch diff --git a/patches/llvm.patch b/patches/llvm.patch deleted file mode 100644 index 04f24fc..0000000 --- a/patches/llvm.patch +++ /dev/null @@ -1,17 +0,0 @@ -diff --git a/compiler-rt/lib/builtins/CMakeLists.txt b/compiler-rt/lib/builtins/CMakeLists.txt -index 28ded8766..b51ebe8ea 100644 ---- a/compiler-rt/lib/builtins/CMakeLists.txt -+++ b/compiler-rt/lib/builtins/CMakeLists.txt -@@ -849,9 +849,9 @@ else () - - # For RISCV32, we must force enable int128 for compiling long - # double routines. -- if(COMPILER_RT_ENABLE_SOFTWARE_INT128 OR "${arch}" STREQUAL "riscv32") -- list(APPEND BUILTIN_CFLAGS_${arch} -fforce-enable-int128) -- endif() -+ #if(COMPILER_RT_ENABLE_SOFTWARE_INT128 OR "${arch}" STREQUAL "riscv32") -+ # list(APPEND BUILTIN_CFLAGS_${arch} -fforce-enable-int128) -+ #endif() - - add_compiler_rt_runtime(clang_rt.builtins - STATIC From 2a08d9a00d890d1364ecf8bf2f70f2a09c7f54b5 Mon Sep 17 00:00:00 2001 From: Lane Rettig Date: Wed, 14 Aug 2024 15:37:13 -0700 Subject: [PATCH 04/24] Add pull request workflow Remove unused version file --- .github/workflows/ci.yml | 5 +++++ version.txt | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) delete mode 100644 version.txt diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f147607..8afc376 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,6 +2,11 @@ name: CI on: workflow_dispatch: + pull_request: + branches: + - "**" + paths-ignore: + - README.md jobs: build: diff --git a/version.txt b/version.txt deleted file mode 100644 index 0ea3a94..0000000 --- a/version.txt +++ /dev/null @@ -1 +0,0 @@ -0.2.0 From acbf1b18bee6634b3437c1f74adb3a5c52b7b66f Mon Sep 17 00:00:00 2001 From: Lane Rettig Date: Wed, 14 Aug 2024 15:51:36 -0700 Subject: [PATCH 05/24] Update CI workflow --- .github/workflows/ci.yml | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8afc376..97e5f4a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,18 +13,22 @@ jobs: strategy: fail-fast: false matrix: - runner: - - [runs-on, runner=32cpu-linux-x64, "run-id=${{ github.run_id }}"] - - [runs-on, runner=32cpu-linux-arm64, "run-id=${{ github.run_id }}"] - - self-hosted - - macos-13 + include: + - runner: [runs-on, runner=32cpu-linux-x64, "run-id=${{ github.run_id }}"] + os: ubuntu + - runner: [runs-on, runner=32cpu-linux-arm64, "run-id=${{ github.run_id }}"] + os: ubuntu + - runner: self-hosted + os: macos + - runner: macos-13 + os: macos runs-on: ${{ matrix.runner }} steps: - name: Install nightly toolchain id: rustc-toolchain uses: actions-rs/toolchain@v1 with: - toolchain: nightly-2024-01-25 + toolchain: nightly-2024-05-29 default: true - uses: lukka/get-cmake@v3.27.4 @@ -35,7 +39,7 @@ jobs: rustup toolchain list - name: Check out athenavm/rustc-rv32e-toolchain - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: submodules: recursive path: toolchain @@ -47,6 +51,19 @@ jobs: ref: main path: athena + - name: Install ninja and riscv-tools + if: matrix.os == 'ubuntu' + run: | + sudo apt update + sudo apt-get -y install ninja-build gcc-riscv64-unknown-elf + + - name: Install ninja and riscv-tools + if: matrix.os == 'macos' + run: | + brew install ninja + brew tap riscv-software-src/riscv + brew install riscv-tools + - name: Build run: GITHUB_ACTIONS=false ATHENA_BUILD_DIR=$GITHUB_WORKSPACE/toolchain cargo run --bin cargo-athena -- athena From f283abe86bd299f434708b7b132dc39f59b5e7ca Mon Sep 17 00:00:00 2001 From: Lane Rettig Date: Wed, 14 Aug 2024 16:01:22 -0700 Subject: [PATCH 06/24] Use dummy custom target file again --- build.sh | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/build.sh b/build.sh index 71e1e42..be9b36e 100755 --- a/build.sh +++ b/build.sh @@ -10,37 +10,7 @@ need_cmd riscv32-unknown-elf-clang++ # Rust requires a custom target file to exist for our custom target as part of the bootstrap build, # but it doesn't actually look at the contents. -cat > /tmp/riscv32em-athena-zkvm-elf.json << EOF -{ - "arch": "riscv32", - "cpu": "generic-rv32", - "crt-objects-fallback": "false", - "data-layout": "e-m:e-p:32:32-i64:64-n32-S32", - "eh-frame-header": false, - "emit-debug-gdb-scripts": false, - "features": "+e,+m", - "linker": "rust-lld", - "linker-flavor": "gnu-lld", - "llvm-abiname": "ilp32e", - "llvm-target": "riscv32", - "max-atomic-width": 32, - "os": "zkvm", - "panic-strategy": "abort", - "relocation-model": "static", - "singlethread": true, - "target-pointer-width": "32", - "vendor": "athena", - "options": { - "c-flags": "-march=rv32e -mabi=ilp32e", - "pre-link-args": { - "gcc": [ - "-march=rv32e", - "-mabi=ilp32e" - ] - } - } -} -EOF +touch /tmp/riscv32em-athena-zkvm-elf.json # Set environment variables to override compiler flags export CC_riscv32em_athena_zkvm_elf="clang" From 78db710edb761906b18cccbfdc3ddd9a1729b8ce Mon Sep 17 00:00:00 2001 From: Lane Rettig Date: Wed, 14 Aug 2024 16:48:47 -0700 Subject: [PATCH 07/24] Update some workflow dependencies --- .github/workflows/ci.yml | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 97e5f4a..edb19f2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,12 +26,11 @@ jobs: steps: - name: Install nightly toolchain id: rustc-toolchain - uses: actions-rs/toolchain@v1 + uses: actions-rust-lang/setup-rust-toolchain@v1 with: toolchain: nightly-2024-05-29 - default: true - - uses: lukka/get-cmake@v3.27.4 + - uses: lukka/get-cmake@v3.30.2 - name: Show rust version run: | @@ -51,16 +50,15 @@ jobs: ref: main path: athena - - name: Install ninja and riscv-tools + - name: Install riscv-tools if: matrix.os == 'ubuntu' run: | sudo apt update - sudo apt-get -y install ninja-build gcc-riscv64-unknown-elf + sudo apt-get -y install gcc-riscv64-unknown-elf - - name: Install ninja and riscv-tools + - name: Install riscv-tools if: matrix.os == 'macos' run: | - brew install ninja brew tap riscv-software-src/riscv brew install riscv-tools From b8708f08bf02caff944f45d88ceca7ec5d3211c4 Mon Sep 17 00:00:00 2001 From: Lane Rettig Date: Wed, 14 Aug 2024 16:58:21 -0700 Subject: [PATCH 08/24] Attempt to work around macos runner brew issue --- .github/workflows/ci.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index edb19f2..d7f62b6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,6 +56,11 @@ jobs: sudo apt update sudo apt-get -y install gcc-riscv64-unknown-elf + # default runner homebrew setup won't allow us to run `brew tap` + - name: Set up Homebrew + if: matrix.os == 'macos' + uses: Homebrew/actions/setup-homebrew@master + - name: Install riscv-tools if: matrix.os == 'macos' run: | From 8afd6e00b27b017f74f3c7442ac10350cb9e3878 Mon Sep 17 00:00:00 2001 From: Lane Rettig Date: Wed, 14 Aug 2024 17:06:56 -0700 Subject: [PATCH 09/24] More cleanup --- .github/workflows/ci.yml | 7 +------ build.sh | 1 - patches/config.ci.toml | 4 ++-- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d7f62b6..ee9dd2b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,13 +56,8 @@ jobs: sudo apt update sudo apt-get -y install gcc-riscv64-unknown-elf - # default runner homebrew setup won't allow us to run `brew tap` - - name: Set up Homebrew - if: matrix.os == 'macos' - uses: Homebrew/actions/setup-homebrew@master - - name: Install riscv-tools - if: matrix.os == 'macos' + if: matrix.runner == 'macos-13' run: | brew tap riscv-software-src/riscv brew install riscv-tools diff --git a/build.sh b/build.sh index be9b36e..5c2bf18 100755 --- a/build.sh +++ b/build.sh @@ -15,7 +15,6 @@ touch /tmp/riscv32em-athena-zkvm-elf.json # Set environment variables to override compiler flags export CC_riscv32em_athena_zkvm_elf="clang" export CXX_riscv32em_athena_zkvm_elf="clang++" -#export AR_riscv32em_athena_zkvm_elf="ar" # Explicitly set CFLAGS without the problematic flags export CFLAGS_riscv32em_athena_zkvm_elf="-ffunction-sections -fdata-sections -fPIC -target riscv32-unknown-elf" diff --git a/patches/config.ci.toml b/patches/config.ci.toml index 7778d89..9dcd4da 100644 --- a/patches/config.ci.toml +++ b/patches/config.ci.toml @@ -8,8 +8,8 @@ configure-args = [] cargo-native-static = true [target.riscv32em-athena-zkvm-elf] -cc = "riscv64-unknown-elf-gcc" -cxx = "riscv64-unknown-elf-g++" +cc = "clang" +cxx = "clang++" [rust] lld = true From 8952ab5244268d9e25fbf03a334c97ffb2d63e7c Mon Sep 17 00:00:00 2001 From: Lane Rettig Date: Wed, 14 Aug 2024 17:10:39 -0700 Subject: [PATCH 10/24] Try again to fix mac workflow --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ee9dd2b..ea1879c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,6 @@ on: jobs: build: strategy: - fail-fast: false matrix: include: - runner: [runs-on, runner=32cpu-linux-x64, "run-id=${{ github.run_id }}"] @@ -57,7 +56,7 @@ jobs: sudo apt-get -y install gcc-riscv64-unknown-elf - name: Install riscv-tools - if: matrix.runner == 'macos-13' + if: matrix.os == 'macos' run: | brew tap riscv-software-src/riscv brew install riscv-tools From 317fc207bfa3e4886df1151fac4ad7d9df4fc37e Mon Sep 17 00:00:00 2001 From: Lane Rettig Date: Wed, 14 Aug 2024 19:03:19 -0700 Subject: [PATCH 11/24] Cleanup and simplification Simplify workflows It looks like clang works out of the box. Try not installing risc-v toolchain after all. --- .github/workflows/build_and_release.yml | 16 +++------------- .github/workflows/ci.yml | 15 ++------------- build.sh | 8 +++----- 3 files changed, 8 insertions(+), 31 deletions(-) diff --git a/.github/workflows/build_and_release.yml b/.github/workflows/build_and_release.yml index 1350dc3..e7aa842 100644 --- a/.github/workflows/build_and_release.yml +++ b/.github/workflows/build_and_release.yml @@ -70,18 +70,8 @@ jobs: - uses: actions/checkout@v4 - - name: Install ninja and riscv-tools - if: matrix.os == 'ubuntu' - run: | - sudo apt update - sudo apt-get -y install ninja-build gcc-riscv64-unknown-elf - - - name: Install ninja and riscv-tools - if: matrix.os == 'macos' - run: | - brew install ninja - brew tap riscv-software-src/riscv - brew install riscv-tools + - name: Install ninja + uses: lukka/get-cmake@v3.30.2 - name: Download source run: ./clone.sh @@ -92,7 +82,7 @@ jobs: - name: Build toolchain run: ./build.sh - # Push in the Github environment variable the name of the artifact + # Push the name of the artifact into the Github environment variable - run: ./config.sh -artifact_name - name: Package toolchain diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ea1879c..99ea11e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,6 +22,7 @@ jobs: - runner: macos-13 os: macos runs-on: ${{ matrix.runner }} + timeout-minutes: 120 steps: - name: Install nightly toolchain id: rustc-toolchain @@ -43,24 +44,12 @@ jobs: path: toolchain - name: Check out athenavm/athena - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: athenavm/athena ref: main path: athena - - name: Install riscv-tools - if: matrix.os == 'ubuntu' - run: | - sudo apt update - sudo apt-get -y install gcc-riscv64-unknown-elf - - - name: Install riscv-tools - if: matrix.os == 'macos' - run: | - brew tap riscv-software-src/riscv - brew install riscv-tools - - name: Build run: GITHUB_ACTIONS=false ATHENA_BUILD_DIR=$GITHUB_WORKSPACE/toolchain cargo run --bin cargo-athena -- athena diff --git a/build.sh b/build.sh index 5c2bf18..9b31b07 100755 --- a/build.sh +++ b/build.sh @@ -5,12 +5,13 @@ set -euo pipefail source config.sh # Fail fast if these tools aren't properly installed and in the path -need_cmd riscv32-unknown-elf-clang -need_cmd riscv32-unknown-elf-clang++ +need_cmd clang +need_cmd clang++ # Rust requires a custom target file to exist for our custom target as part of the bootstrap build, # but it doesn't actually look at the contents. touch /tmp/riscv32em-athena-zkvm-elf.json +export RUST_TARGET_PATH="/tmp" # Set environment variables to override compiler flags export CC_riscv32em_athena_zkvm_elf="clang" @@ -26,9 +27,6 @@ export CARGO_TARGET_RISCV32EM_ATHENA_ZKVM_ELF_RUSTFLAGS="-Cpasses=loweratomic -C # Override the default target for compiler-rt export COMPILER_RT_DEFAULT_TARGET_TRIPLE="riscv32-unknown-elf" -# Force the use of our custom target spec -export RUST_TARGET_PATH="/tmp" - # Prevent the build system from adding --target flag export RUSTC_TARGET_ARG="" From 06a000f406ef2c86b599a92c7f4aa59cf7f6d271 Mon Sep 17 00:00:00 2001 From: Lane Rettig Date: Thu, 15 Aug 2024 10:30:15 -0700 Subject: [PATCH 12/24] Simplify build further, enable GHA caching --- .github/workflows/ci.yml | 24 ++++++++++++++++++++++++ build.sh | 11 ++++++----- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 99ea11e..4465795 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,6 +50,30 @@ jobs: ref: main path: athena + - name: Source config.sh and export RUST_COMMIT + run: | + source toolchain/config.sh + echo "Using Rust commit: $RUST_COMMIT" + echo "RUST_COMMIT=$RUST_COMMIT" >> $GITHUB_ENV + + - uses: actions/cache@v4 + name: Cache Athena build + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + athena/target/ + key: ${{ matrix.os }}-athenabuild-${{ hashFiles('athena/**/Cargo.lock') }} + + - uses: actions/cache@v4 + name: Cache Rust toolchain + with: + path: | + toolchain/rust/ + key: ${{ matrix.os }}-rusttoolchain-${{ env.RUST_COMMIT }} + - name: Build run: GITHUB_ACTIONS=false ATHENA_BUILD_DIR=$GITHUB_WORKSPACE/toolchain cargo run --bin cargo-athena -- athena diff --git a/build.sh b/build.sh index 9b31b07..54ffd42 100755 --- a/build.sh +++ b/build.sh @@ -14,18 +14,19 @@ touch /tmp/riscv32em-athena-zkvm-elf.json export RUST_TARGET_PATH="/tmp" # Set environment variables to override compiler flags -export CC_riscv32em_athena_zkvm_elf="clang" -export CXX_riscv32em_athena_zkvm_elf="clang++" +#export CC_riscv32em_athena_zkvm_elf="clang" +#export CXX_riscv32em_athena_zkvm_elf="clang++" # Explicitly set CFLAGS without the problematic flags export CFLAGS_riscv32em_athena_zkvm_elf="-ffunction-sections -fdata-sections -fPIC -target riscv32-unknown-elf" -export CXXFLAGS_riscv32em_athena_zkvm_elf="$CFLAGS_riscv32em_athena_zkvm_elf" +#export CXXFLAGS_riscv32em_athena_zkvm_elf="$CFLAGS_riscv32em_athena_zkvm_elf" # Set Rust flags -export CARGO_TARGET_RISCV32EM_ATHENA_ZKVM_ELF_RUSTFLAGS="-Cpasses=loweratomic -Clink-arg=-march=rv32em -Clink-arg=-mabi=ilp32e" +export CARGO_TARGET_RISCV32EM_ATHENA_ZKVM_ELF_RUSTFLAGS="-Cpasses=loweratomic" +# export CARGO_TARGET_RISCV32EM_ATHENA_ZKVM_ELF_RUSTFLAGS="-Cpasses=loweratomic -Clink-arg=-march=rv32em -Clink-arg=-mabi=ilp32e" # Override the default target for compiler-rt -export COMPILER_RT_DEFAULT_TARGET_TRIPLE="riscv32-unknown-elf" +# export COMPILER_RT_DEFAULT_TARGET_TRIPLE="riscv32-unknown-elf" # Prevent the build system from adding --target flag export RUSTC_TARGET_ARG="" From f6511689ebb9d8438f78421195c4c264b1491769 Mon Sep 17 00:00:00 2001 From: Lane Rettig Date: Thu, 15 Aug 2024 10:50:46 -0700 Subject: [PATCH 13/24] Update cache strategy, simplify further --- .github/workflows/ci.yml | 8 ++++++-- build.sh | 11 +---------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4465795..3473a46 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -65,13 +65,17 @@ jobs: ~/.cargo/registry/cache/ ~/.cargo/git/db/ athena/target/ - key: ${{ matrix.os }}-athenabuild-${{ hashFiles('athena/**/Cargo.lock') }} + key: ${{ matrix.os }}-athenabuild-${{ hashFiles('athena/**/Cargo.toml') }} - uses: actions/cache@v4 name: Cache Rust toolchain with: path: | - toolchain/rust/ + toolchain/rust/build + toolchain/rust/library + toolchain/rust/src/doc + toolchain/rust/src/llvm-project + toolchain/rust/src/tools key: ${{ matrix.os }}-rusttoolchain-${{ env.RUST_COMMIT }} - name: Build diff --git a/build.sh b/build.sh index 54ffd42..17caafb 100755 --- a/build.sh +++ b/build.sh @@ -13,23 +13,14 @@ need_cmd clang++ touch /tmp/riscv32em-athena-zkvm-elf.json export RUST_TARGET_PATH="/tmp" -# Set environment variables to override compiler flags -#export CC_riscv32em_athena_zkvm_elf="clang" -#export CXX_riscv32em_athena_zkvm_elf="clang++" - # Explicitly set CFLAGS without the problematic flags export CFLAGS_riscv32em_athena_zkvm_elf="-ffunction-sections -fdata-sections -fPIC -target riscv32-unknown-elf" -#export CXXFLAGS_riscv32em_athena_zkvm_elf="$CFLAGS_riscv32em_athena_zkvm_elf" # Set Rust flags export CARGO_TARGET_RISCV32EM_ATHENA_ZKVM_ELF_RUSTFLAGS="-Cpasses=loweratomic" -# export CARGO_TARGET_RISCV32EM_ATHENA_ZKVM_ELF_RUSTFLAGS="-Cpasses=loweratomic -Clink-arg=-march=rv32em -Clink-arg=-mabi=ilp32e" - -# Override the default target for compiler-rt -# export COMPILER_RT_DEFAULT_TARGET_TRIPLE="riscv32-unknown-elf" # Prevent the build system from adding --target flag -export RUSTC_TARGET_ARG="" +#export RUSTC_TARGET_ARG="" # Will create component archives (dists) ./rust/build/dist cd rust From 3cceeb7b53d88c9e990be7f1190330cf3a35b610 Mon Sep 17 00:00:00 2001 From: Lane Rettig Date: Thu, 15 Aug 2024 10:54:50 -0700 Subject: [PATCH 14/24] Fix cache key to prevent conflicts --- .github/workflows/ci.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3473a46..7a97e0c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,12 +15,16 @@ jobs: include: - runner: [runs-on, runner=32cpu-linux-x64, "run-id=${{ github.run_id }}"] os: ubuntu + cachekey: ubuntu-x86 - runner: [runs-on, runner=32cpu-linux-arm64, "run-id=${{ github.run_id }}"] os: ubuntu + cachekey: ubuntu-arm64 - runner: self-hosted os: macos + cachekey: macos-arm64 - runner: macos-13 os: macos + cachekey: macos-x86 runs-on: ${{ matrix.runner }} timeout-minutes: 120 steps: @@ -65,7 +69,7 @@ jobs: ~/.cargo/registry/cache/ ~/.cargo/git/db/ athena/target/ - key: ${{ matrix.os }}-athenabuild-${{ hashFiles('athena/**/Cargo.toml') }} + key: ${{ matrix.cachekey }}-athenabuild-${{ hashFiles('athena/**/Cargo.toml') }} - uses: actions/cache@v4 name: Cache Rust toolchain @@ -76,7 +80,7 @@ jobs: toolchain/rust/src/doc toolchain/rust/src/llvm-project toolchain/rust/src/tools - key: ${{ matrix.os }}-rusttoolchain-${{ env.RUST_COMMIT }} + key: ${{ matrix.cachekey }}-rusttoolchain-${{ env.RUST_COMMIT }} - name: Build run: From 6026b84277b31868e057f1c71fb2613ab031d836 Mon Sep 17 00:00:00 2001 From: Lane Rettig Date: Thu, 15 Aug 2024 11:32:14 -0700 Subject: [PATCH 15/24] More caching, more cleanup --- .github/workflows/build_and_release.yml | 15 +++++++++++++++ build.sh | 7 ++----- patches/config.ci.toml | 6 +++--- patches/config.toml | 6 +++--- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build_and_release.yml b/.github/workflows/build_and_release.yml index e7aa842..a915ddc 100644 --- a/.github/workflows/build_and_release.yml +++ b/.github/workflows/build_and_release.yml @@ -48,12 +48,16 @@ jobs: include: - runner: [runs-on, runner=32cpu-linux-x64, "run-id=${{ github.run_id }}"] os: ubuntu + cachekey: ubuntu-x86 - runner: [runs-on, runner=32cpu-linux-arm64, "run-id=${{ github.run_id }}"] os: ubuntu + cachekey: ubuntu-arm64 - runner: self-hosted os: macos + cachekey: macos-arm64 - runner: macos-13 os: macos + cachekey: macos-x86 steps: - name: Free Disk Space (Ubuntu) @@ -70,6 +74,17 @@ jobs: - uses: actions/checkout@v4 + - uses: actions/cache@v4 + name: Cache Rust toolchain + with: + path: | + rust/build + rust/library + rust/src/doc + rust/src/llvm-project + rust/src/tools + key: ${{ matrix.cachekey }}-buildtoolchain-${{ env.RUST_COMMIT }} + - name: Install ninja uses: lukka/get-cmake@v3.30.2 diff --git a/build.sh b/build.sh index 17caafb..dd7066d 100755 --- a/build.sh +++ b/build.sh @@ -5,8 +5,8 @@ set -euo pipefail source config.sh # Fail fast if these tools aren't properly installed and in the path -need_cmd clang -need_cmd clang++ +# need_cmd clang +# need_cmd clang++ # Rust requires a custom target file to exist for our custom target as part of the bootstrap build, # but it doesn't actually look at the contents. @@ -19,9 +19,6 @@ export CFLAGS_riscv32em_athena_zkvm_elf="-ffunction-sections -fdata-sections -fP # Set Rust flags export CARGO_TARGET_RISCV32EM_ATHENA_ZKVM_ELF_RUSTFLAGS="-Cpasses=loweratomic" -# Prevent the build system from adding --target flag -#export RUSTC_TARGET_ARG="" - # Will create component archives (dists) ./rust/build/dist cd rust ./x build --stage 2 diff --git a/patches/config.ci.toml b/patches/config.ci.toml index 9dcd4da..61ded27 100644 --- a/patches/config.ci.toml +++ b/patches/config.ci.toml @@ -7,9 +7,9 @@ tools = ["cargo", "cargo-clippy", "clippy", "rustfmt"] configure-args = [] cargo-native-static = true -[target.riscv32em-athena-zkvm-elf] -cc = "clang" -cxx = "clang++" +# [target.riscv32em-athena-zkvm-elf] +# cc = "clang" +# cxx = "clang++" [rust] lld = true diff --git a/patches/config.toml b/patches/config.toml index e2304da..e84ee2f 100644 --- a/patches/config.toml +++ b/patches/config.toml @@ -6,9 +6,9 @@ extended = true tools = ["cargo", "cargo-clippy", "clippy", "rustfmt"] configure-args = [] -[target.riscv32em-athena-zkvm-elf] -cc = "clang" -cxx = "clang++" +# [target.riscv32em-athena-zkvm-elf] +# cc = "clang" +# cxx = "clang++" [rust] lld = true From ac4a82ed9fb786cf31589796e3d50701e4b23a0a Mon Sep 17 00:00:00 2001 From: Lane Rettig Date: Thu, 15 Aug 2024 11:49:00 -0700 Subject: [PATCH 16/24] Move rust commit to a standalone file Makes it easier for athena and other things to depend on it --- .github/workflows/ci.yml | 4 ++-- config.sh | 2 +- rust_commit.txt | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 rust_commit.txt diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7a97e0c..8dd2b8b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -54,9 +54,9 @@ jobs: ref: main path: athena - - name: Source config.sh and export RUST_COMMIT + - name: Get Rust commit run: | - source toolchain/config.sh + RUST_COMMIT=$(cat toolchain/rust_commit.txt) echo "Using Rust commit: $RUST_COMMIT" echo "RUST_COMMIT=$RUST_COMMIT" >> $GITHUB_ENV diff --git a/config.sh b/config.sh index bee293c..9090896 100755 --- a/config.sh +++ b/config.sh @@ -2,7 +2,7 @@ param1=${1:-} -export RUST_COMMIT=051478957371ee0084a7c0913941d2a8c4757bb9 +export RUST_COMMIT=$(cat rust_commit.txt) # If -rust_commit specified then only export the rust commit variable if [ "$param1" == "-rust_commit" ]; then diff --git a/rust_commit.txt b/rust_commit.txt new file mode 100644 index 0000000..5afe247 --- /dev/null +++ b/rust_commit.txt @@ -0,0 +1 @@ +051478957371ee0084a7c0913941d2a8c4757bb9 From 3f25209adda680faf9cf9a244fbae3332642c3c3 Mon Sep 17 00:00:00 2001 From: Lane Rettig Date: Thu, 15 Aug 2024 12:05:36 -0700 Subject: [PATCH 17/24] Temporarily use updated athena ref --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8dd2b8b..a40abf4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,7 +51,7 @@ jobs: uses: actions/checkout@v4 with: repository: athenavm/athena - ref: main + ref: rust-commit-hash path: athena - name: Get Rust commit From 401de7830432574904d5c1a07cfe88c9dafa1728 Mon Sep 17 00:00:00 2001 From: Lane Rettig Date: Thu, 15 Aug 2024 12:17:45 -0700 Subject: [PATCH 18/24] Manually check out Rust toolchain in workflow --- .github/workflows/ci.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a40abf4..c85b265 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,7 +51,6 @@ jobs: uses: actions/checkout@v4 with: repository: athenavm/athena - ref: rust-commit-hash path: athena - name: Get Rust commit @@ -60,6 +59,18 @@ jobs: echo "Using Rust commit: $RUST_COMMIT" echo "RUST_COMMIT=$RUST_COMMIT" >> $GITHUB_ENV + # This is a shortcut to allow caching. If we don't manually check out Rust here, + # the Athena CLI tool will refuse to check it out since the cache will have + # already restored files into the same directory. + # This command won't check out submodules recursively. The cache restore will do + # this for us, saving time. + - name: Check out Rust toolchain + uses: actions/checkout@v4 + with: + repository: rust-lang/rust + ref: ${{ env.RUST_COMMIT }} + path: toolchain/rust + - uses: actions/cache@v4 name: Cache Athena build with: From 14badd56cded2bb76d32d18eb9057408dff9b70b Mon Sep 17 00:00:00 2001 From: Lane Rettig Date: Thu, 15 Aug 2024 12:46:34 -0700 Subject: [PATCH 19/24] Try caching entire Rust toolchain --- .github/workflows/ci.yml | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c85b265..ef4f0d9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,18 +59,6 @@ jobs: echo "Using Rust commit: $RUST_COMMIT" echo "RUST_COMMIT=$RUST_COMMIT" >> $GITHUB_ENV - # This is a shortcut to allow caching. If we don't manually check out Rust here, - # the Athena CLI tool will refuse to check it out since the cache will have - # already restored files into the same directory. - # This command won't check out submodules recursively. The cache restore will do - # this for us, saving time. - - name: Check out Rust toolchain - uses: actions/checkout@v4 - with: - repository: rust-lang/rust - ref: ${{ env.RUST_COMMIT }} - path: toolchain/rust - - uses: actions/cache@v4 name: Cache Athena build with: @@ -86,11 +74,11 @@ jobs: name: Cache Rust toolchain with: path: | - toolchain/rust/build - toolchain/rust/library - toolchain/rust/src/doc - toolchain/rust/src/llvm-project - toolchain/rust/src/tools + toolchain/rust/** + # toolchain/rust/library + # toolchain/rust/src/doc + # toolchain/rust/src/llvm-project + # toolchain/rust/src/tools key: ${{ matrix.cachekey }}-rusttoolchain-${{ env.RUST_COMMIT }} - name: Build From 24e515d28d7ff61dc045ab704a2e6253a5472a11 Mon Sep 17 00:00:00 2001 From: Lane Rettig Date: Thu, 15 Aug 2024 12:55:14 -0700 Subject: [PATCH 20/24] We need clang after all --- build.sh | 4 ++-- patches/config.toml | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build.sh b/build.sh index dd7066d..5393b87 100755 --- a/build.sh +++ b/build.sh @@ -5,8 +5,8 @@ set -euo pipefail source config.sh # Fail fast if these tools aren't properly installed and in the path -# need_cmd clang -# need_cmd clang++ +need_cmd clang +need_cmd clang++ # Rust requires a custom target file to exist for our custom target as part of the bootstrap build, # but it doesn't actually look at the contents. diff --git a/patches/config.toml b/patches/config.toml index e84ee2f..e2304da 100644 --- a/patches/config.toml +++ b/patches/config.toml @@ -6,9 +6,9 @@ extended = true tools = ["cargo", "cargo-clippy", "clippy", "rustfmt"] configure-args = [] -# [target.riscv32em-athena-zkvm-elf] -# cc = "clang" -# cxx = "clang++" +[target.riscv32em-athena-zkvm-elf] +cc = "clang" +cxx = "clang++" [rust] lld = true From 636c637885dc811eab9e25553e0a65a9f2fd2731 Mon Sep 17 00:00:00 2001 From: Lane Rettig Date: Thu, 15 Aug 2024 13:43:14 -0700 Subject: [PATCH 21/24] Update athena pathspec --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ef4f0d9..49400dd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,6 +51,7 @@ jobs: uses: actions/checkout@v4 with: repository: athenavm/athena + ref: fix-toolchain-build path: athena - name: Get Rust commit From 0822b409e1ae9fdfcd9d7909dbc7403fe53c8f69 Mon Sep 17 00:00:00 2001 From: Lane Rettig Date: Thu, 15 Aug 2024 16:21:16 -0700 Subject: [PATCH 22/24] Update to match Athena changes See https://github.com/athenavm/athena/pull/91 --- build.sh | 8 +++++++- patch.sh | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/build.sh b/build.sh index 5393b87..fba7ed0 100755 --- a/build.sh +++ b/build.sh @@ -17,7 +17,13 @@ export RUST_TARGET_PATH="/tmp" export CFLAGS_riscv32em_athena_zkvm_elf="-ffunction-sections -fdata-sections -fPIC -target riscv32-unknown-elf" # Set Rust flags -export CARGO_TARGET_RISCV32EM_ATHENA_ZKVM_ELF_RUSTFLAGS="-Cpasses=loweratomic" +export CARGO_TARGET_RISCV32EM_ATHENA_ZKVM_ELF_RUSTFLAGS="-Cpasses=loweratomic -Clink-arg=-march=rv32em -Clink-arg=-mabi=ilp32e" +export COMPILER_RT_DEFAULT_TARGET_TRIPLE="riscv32-unknown-elf" +export CC_riscv32em_athena_zkvm_elf="clang" +export CXX_riscv32em_athena_zkvm_elf="clang++" + +# Prevent the build system from adding --target flag +export RUSTC_TARGET_ARG="" # Will create component archives (dists) ./rust/build/dist cd rust diff --git a/patch.sh b/patch.sh index 2ec3ec9..4838b12 100755 --- a/patch.sh +++ b/patch.sh @@ -3,5 +3,5 @@ set -euo pipefail cd rust -patch -p1 < ../patches/rust.patch +patch -N -p1 < ../patches/rust.patch cp ../patches/config.toml ./ From a5c5e50ea2180f8f37b61b5adfa4cbfe5e62eb0b Mon Sep 17 00:00:00 2001 From: Lane Rettig Date: Thu, 15 Aug 2024 17:31:06 -0700 Subject: [PATCH 23/24] Cleanup --- build.sh | 6 +++--- patches/config.ci.toml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build.sh b/build.sh index fba7ed0..1d1d469 100755 --- a/build.sh +++ b/build.sh @@ -18,9 +18,9 @@ export CFLAGS_riscv32em_athena_zkvm_elf="-ffunction-sections -fdata-sections -fP # Set Rust flags export CARGO_TARGET_RISCV32EM_ATHENA_ZKVM_ELF_RUSTFLAGS="-Cpasses=loweratomic -Clink-arg=-march=rv32em -Clink-arg=-mabi=ilp32e" -export COMPILER_RT_DEFAULT_TARGET_TRIPLE="riscv32-unknown-elf" -export CC_riscv32em_athena_zkvm_elf="clang" -export CXX_riscv32em_athena_zkvm_elf="clang++" +# export COMPILER_RT_DEFAULT_TARGET_TRIPLE="riscv32-unknown-elf" +# export CC_riscv32em_athena_zkvm_elf="clang" +# export CXX_riscv32em_athena_zkvm_elf="clang++" # Prevent the build system from adding --target flag export RUSTC_TARGET_ARG="" diff --git a/patches/config.ci.toml b/patches/config.ci.toml index 61ded27..9dcd4da 100644 --- a/patches/config.ci.toml +++ b/patches/config.ci.toml @@ -7,9 +7,9 @@ tools = ["cargo", "cargo-clippy", "clippy", "rustfmt"] configure-args = [] cargo-native-static = true -# [target.riscv32em-athena-zkvm-elf] -# cc = "clang" -# cxx = "clang++" +[target.riscv32em-athena-zkvm-elf] +cc = "clang" +cxx = "clang++" [rust] lld = true From 6355dd1cfce19982609214491b38ab9d3c19f642 Mon Sep 17 00:00:00 2001 From: Lane Rettig Date: Thu, 15 Aug 2024 17:36:31 -0700 Subject: [PATCH 24/24] Add back riscv toolchain clang --- build.sh | 4 ++-- patches/config.toml | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/build.sh b/build.sh index 1d1d469..230ef37 100755 --- a/build.sh +++ b/build.sh @@ -5,8 +5,8 @@ set -euo pipefail source config.sh # Fail fast if these tools aren't properly installed and in the path -need_cmd clang -need_cmd clang++ +need_cmd riscv32-unknown-elf-clang +need_cmd riscv32-unknown-elf-clang++ # Rust requires a custom target file to exist for our custom target as part of the bootstrap build, # but it doesn't actually look at the contents. diff --git a/patches/config.toml b/patches/config.toml index e2304da..f29c4a7 100644 --- a/patches/config.toml +++ b/patches/config.toml @@ -7,8 +7,10 @@ tools = ["cargo", "cargo-clippy", "clippy", "rustfmt"] configure-args = [] [target.riscv32em-athena-zkvm-elf] -cc = "clang" -cxx = "clang++" +cc = "riscv32-unknown-elf-clang" +cxx = "riscv32-unknown-elf-clang++" +# linker = "riscv32-unknown-elf-gcc" +# ar = "riscv32-unknown-elf-ar" [rust] lld = true