athenavm / athena

Athena monorepo
https://www.athenavm.org/
Apache License 2.0
17 stars 1 forks source link

Rust toolchain #3

Closed lrettig closed 3 months ago

lrettig commented 4 months ago

Right now we're using the SP1 toolchain: https://github.com/succinctlabs/rust. It should be possible to switch to riscv32im-risc0-zkvm-elf which has at least partial mainline Rust support, see https://github.com/rust-lang/rust/commit/75d7d7091a6c891bb98ff4158a09f4e1f2fb2be1. But I don't see this target listed for rustc 1.78.0 and I'm getting errors when trying to build using mainline rust rather than the custom toolchain (about missing std support).

This works:

> RUSTC=/home/lane/.rustup/toolchains/risc0/bin/rustc CFLAGS_riscv32im_risc0_zkvm_elf="-march=rv32im -nostdlib" CC=/home/lane/.local/share/cargo-risczero/cpp/bin/riscv32-unknown-elf-gcc RUSTFLAGS="-Cpasses=loweratomic -Clink-arg=-Ttext=0x00200800 -Clink-arg=--fatal-warnings -Cpanic=abort" cargo build --target riscv32im-risc0-zkvm-elf

This also works:

> LD_LIBRARY_PATH=$HOME/opt/lib:$LD_LIBRARY_PATH RUSTUP_TOOLCHAIN=risc0 cargo build

This does not work:

> RUSTFLAGS="-Cpasses=loweratomic -Clink-arg=-Ttext=0x00200800 -Clink-arg=--fatal-warnings -Cpanic=abort" cargo build --target riscv32im-risc0-zkvm-elf
   Compiling zeroize v1.8.1
   Compiling typenum v1.17.0
   Compiling cfg-if v1.0.0
   Compiling subtle v2.5.0
   Compiling const-oid v0.9.6
   Compiling tap v1.0.1
   Compiling funty v2.0.0
   Compiling base16ct v0.2.0
   Compiling ppv-lite86 v0.2.17
   Compiling generic-array v0.14.7
   Compiling num-traits v0.2.19
   Compiling radium v0.7.0
   Compiling proc-macro2 v1.0.84
   Compiling serde v1.0.203
   Compiling hex v0.4.3
   Compiling anyhow v1.0.86
error[E0463]: can't find crate for `core`
  |
  = note: the `riscv32im-risc0-zkvm-elf` target may not be installed
  = help: consider downloading the target with `rustup target add riscv32im-risc0-zkvm-elf`
  = help: consider building the standard library from source with `cargo build -Zbuild-std`

For more information about this error, try `rustc --explain E0463`.
   Compiling once_cell v1.19.0
error: could not compile `tap` (lib) due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `const-oid` (lib) due to 1 previous error
error: could not compile `cfg-if` (lib) due to 1 previous error
error: could not compile `zeroize` (lib) due to 1 previous error
error: could not compile `base16ct` (lib) due to 1 previous error
error: could not compile `funty` (lib) due to 1 previous error
error: could not compile `subtle` (lib) due to 1 previous error
error: could not compile `ppv-lite86` (lib) due to 1 previous error
error: could not compile `radium` (lib) due to 1 previous error
error[E0463]: can't find crate for `std`
  |
  = note: the `riscv32im-risc0-zkvm-elf` target may not be installed
  = help: consider downloading the target with `rustup target add riscv32im-risc0-zkvm-elf`
  = help: consider building the standard library from source with `cargo build -Zbuild-std`

error: could not compile `once_cell` (lib) due to 1 previous error
error: could not compile `hex` (lib) due to 1 previous error
lrettig commented 3 months ago

Ended up moving to a custom RV32E toolchain: https://github.com/athenavm/rustc-rv32e-toolchain/. Codegen support for RV32E was added recently to LLVM: https://github.com/llvm/llvm-project/commit/3ac9fe69f70a2b3541266daedbaaa7dc9c007a2a. We're still using patches but we should try switching to a newer Rust that depends on this version of LLVM, without the LLVM patches.

lrettig commented 3 months ago

Done in linked issue