diff --git a/.github/workflows/build_and_release.yml b/.github/workflows/build_and_release.yml index 1350dc3..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,18 +74,19 @@ 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 + - 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 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 +97,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 f147607..49400dd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,27 +2,39 @@ name: CI on: workflow_dispatch: + pull_request: + branches: + - "**" + paths-ignore: + - README.md jobs: build: 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 + 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: - name: Install nightly toolchain id: rustc-toolchain - uses: actions-rs/toolchain@v1 + uses: actions-rust-lang/setup-rust-toolchain@v1 with: - toolchain: nightly-2024-01-25 - default: true + toolchain: nightly-2024-05-29 - - uses: lukka/get-cmake@v3.27.4 + - uses: lukka/get-cmake@v3.30.2 - name: Show rust version run: | @@ -30,18 +42,46 @@ jobs: rustup toolchain list - name: Check out athenavm/rustc-rv32e-toolchain - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: submodules: recursive path: toolchain - name: Check out athenavm/athena - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: athenavm/athena - ref: main + ref: fix-toolchain-build path: athena + - name: Get Rust commit + run: | + RUST_COMMIT=$(cat toolchain/rust_commit.txt) + 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.cachekey }}-athenabuild-${{ hashFiles('athena/**/Cargo.toml') }} + + - uses: actions/cache@v4 + name: Cache Rust toolchain + with: + path: | + 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 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 2cb9cde..230ef37 100755 --- a/build.sh +++ b/build.sh @@ -5,16 +5,26 @@ 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 +export RUST_TARGET_PATH="/tmp" + +# Explicitly set CFLAGS without the problematic flags +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 -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 -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/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/patch.sh b/patch.sh index 0963cab..4838b12 100755 --- a/patch.sh +++ b/patch.sh @@ -3,8 +3,5 @@ set -euo pipefail cd rust -patch -p1 < ../patches/rust.patch +patch -N -p1 < ../patches/rust.patch cp ../patches/config.toml ./ - -cd src/llvm-project -patch -p1 < ../../../patches/llvm.patch 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 diff --git a/patches/config.toml b/patches/config.toml index 1ed3fea..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 = "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 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 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 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