# "stateless_validation" compilation to riscv This document describes how to compile simple program using [`stateless_validation`](https://github.com/paradigmxyz/reth/blob/main/crates/stateless/src/validation.rs#L132-L148) to different riscv targets supported by rust compiler. [Source code](https://github.com/rodiazet/simple-guest-program-rust/tree/stateless-function-build) ## riscv32im-unknown-none-elf ### Build command: Switch default rust toolchain to nightly: `rustup default nightly-aarch64-apple-darwin` (for macos host) `cargo build` ### Summary Because of the library `thiserror v2.0.12` does not support this target for stable rust we have to use nightly: ``` error[E0554]: `#![feature]` may not be used on the stable release channel --> .../.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/thiserror-2.0.12/src/lib.rs:268:42 | 268 | #![cfg_attr(error_generic_member_access, feature(error_generic_member_access))] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ``` Unfortunately imports `alloc::async` which is undefined for this target: ``` error[E0432]: unresolved import `alloc::sync` --> .../.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tracing-core-0.1.34/src/stdlib.rs:53:31 | 53 | pub(crate) use alloc::sync::*; | ^^^^ could not find `sync` in `alloc` ``` The `tracing-core` library imports `alloc::sync` package which is not supported for this target. If we want to build to this target we have to eliminate usage of libraries which depends on `alloc::sync`. It's mostly related to `Arc` usage. Single-threaded counterpart `Rc` can be used. `sedre` builds properly to this target but w/o `rc` feature. These `sedre` dependencies enables the `rc` feature. ``` ├── serde feature "rc" │ ├── alloy-trie v0.9.0 (*) │ ├── revm-bytecode v6.2.0 (*) │ ├── revm-primitives v20.2.0 (*) │ └── revm-state v7.0.3 (*) ``` ## riscv32ima-unknown-none-elf This target is in Tier 3 and it means that it doesn't have `core` and `alloc` libraries being distributed with the target. We have to build them. ### Build command: Switch default rust toolchain to nightly: `rustup default nightly-aarch64-apple-darwin` (for macos host) `cargo build -Zbuild-std=core,alloc` ### Summary Unfortunately building to this target fails because of `radium v0.7.0` library which is an indirect dependency of `reth-stateless` i.e. This `radium` version wrongly considered `riscv32ima` target as a target supporting 64 bits atomics. ``` radium v0.7.0 └── radium feature "default" └── bitvec v1.0.1 ├── bitvec feature "alloc" │ └── revm-bytecode v6.2.0 │ ├── reth-primitives-traits v1.6.0 ``` ``` error[E0432]: unresolved imports `core::sync::atomic::AtomicI64`, `core::sync::atomic::AtomicU64` --> .../.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/radium-0.7.0/src/lib.rs:53:34 | 53 | use core::sync::atomic::{AtomicI64, AtomicU64}; | ^^^^^^^^^ ^^^^^^^^^ no `AtomicU64` in `sync::atomic` | | | no `AtomicI64` in `sync::atomic` ``` The reason is in their custom way to determine target features correctly. [This fragment](https://github.com/ferrilab/radium/blob/main/build.rs#L83-L94) of code does not cover `ima` target features and by default leaves `atomics.has_64` set to `true`. If we want to use this target we need to eliminate usage of `radium` library. ## riscv32/64imac-unknown-none-elf ### Build command: Switch default rust toolchain to nightly: `rustup default stable-aarch64-apple-darwin` (for macos host) `cargo build` ### Comment - It compiles properly to this target. - We cannot use `portable_atomics` as alternative `Arc` implementation as `stateless_validation` gets `alloc::sync::Arc`.