Skip to content

add riscv64im-unknown-openvm-elf tier 3 target#3

Merged
shuklaayush merged 1 commit into
riscv64im-unknown-openvm-elffrom
feat/riscv64im-unknown-openvm-elf
May 21, 2026
Merged

add riscv64im-unknown-openvm-elf tier 3 target#3
shuklaayush merged 1 commit into
riscv64im-unknown-openvm-elffrom
feat/riscv64im-unknown-openvm-elf

Conversation

@Tuanlinh12312
Copy link
Copy Markdown

Add riscv64im-unknown-openvm-elf as a tier 3 Rust target for the OpenVM zero-knowledge virtual machine (RV64IM ISA). The target includes std support via the OpenVM platform abstraction layer.

@shuklaayush shuklaayush force-pushed the feat/riscv64im-unknown-openvm-elf branch 3 times, most recently from 0edc748 to f1281db Compare May 13, 2026 18:45
@shuklaayush shuklaayush reopened this May 13, 2026
@shuklaayush shuklaayush requested a review from jonathanpwang May 13, 2026 19:08
@shuklaayush shuklaayush force-pushed the feat/riscv64im-unknown-openvm-elf branch 6 times, most recently from 22b86aa to 8f068e6 Compare May 13, 2026 22:21
@jonathanpwang
Copy link
Copy Markdown

Should we change the target to some openvm branch so we can merge it?
also any way to get CI to not break, or it has too many rust org stuff?

@shuklaayush shuklaayush force-pushed the feat/riscv64im-unknown-openvm-elf branch 3 times, most recently from ada9892 to a5da1ed Compare May 14, 2026 09:14
@shuklaayush
Copy link
Copy Markdown

Should we change the target to some openvm branch so we can merge it?

can't we just close the pr after review and maintain the changes in the branch?

also any way to get CI to not break, or it has too many rust org stuff?

probably not, but the release workflow did work and we have a tarball
https://github.com/openvm-org/rust/releases/tag/openvm-nightly-2026-01-18

@jonathanpwang
Copy link
Copy Markdown

Should we change the target to some openvm branch so we can merge it?

can't we just close the pr after review and maintain the changes in the branch?

also any way to get CI to not break, or it has too many rust org stuff?

probably not, but the release workflow did work and we have a tarball https://github.com/openvm-org/rust/releases/tag/openvm-nightly-2026-01-18

We can, but given that this is a target we want to maintain, I'd just say we rename the branch to something more official

@shuklaayush shuklaayush requested a review from GunaDD May 19, 2026 16:21
Comment thread library/std/src/sys/alloc/mod.rs
Comment thread library/test/src/lib.rs
Comment thread src/doc/rustc/src/platform-support.md Outdated
Comment thread compiler/rustc_target/src/spec/targets/riscv64im_unknown_openvm_elf.rs Outdated
Comment thread library/std/src/sys/args/openvm.rs Outdated
Comment thread library/std/src/sys/env/openvm.rs
Copy link
Copy Markdown

@jonathanpwang jonathanpwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change in platform-support.md is the main fix. Otherwise please address the other more minor comments and it will be good for me

@shuklaayush shuklaayush force-pushed the feat/riscv64im-unknown-openvm-elf branch from df4da48 to 0b54c11 Compare May 21, 2026 14:20
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added stubs for now. we can consider adding a HINT_TIME later

@shuklaayush
Copy link
Copy Markdown

i addressed all comments. can you take a look again? i had to squash the commits so it's easier to trigger a release

Add the OpenVM RV64IM tier-3 Rust target, std/PAL support, panic_abort integration, release workflows for prebuilt toolchains, and target documentation.

The prebuilt guest std is built with lower-atomic and the release workflow verifies shipped guest rlibs do not contain unsupported RISC-V A-extension atomics before packaging.
@shuklaayush shuklaayush force-pushed the feat/riscv64im-unknown-openvm-elf branch from 0b54c11 to f967520 Compare May 21, 2026 17:10
Copy link
Copy Markdown

@jonathanpwang jonathanpwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did targeted re-review, LGTM. I made follow-up ticket around hint time.

@shuklaayush shuklaayush changed the base branch from master to riscv64im-unknown-openvm-elf May 21, 2026 20:57
@shuklaayush shuklaayush marked this pull request as ready for review May 21, 2026 20:57
@shuklaayush shuklaayush merged commit 49930ba into riscv64im-unknown-openvm-elf May 21, 2026
4 of 13 checks passed
shuklaayush added a commit to openvm-org/openvm that referenced this pull request May 21, 2026
… build system (#2765)

## Summary

Integrate the built-in Rust target `riscv64im-unknown-openvm-elf`
(`target_os = "openvm"`) into the OpenVM build system and guest crates,
enabling `std` support for guest programs.

The target itself was added to the OpenVM Rust fork in
[openvm-org/rust#3](openvm-org/rust#3). Prebuilt
toolchain tarballs are published on the fork's
[Releases](https://github.com/openvm-org/rust/releases) page — install
via `cargo openvm toolchain install` (this PR) or the CI helper script.

### Changes

- **Build system** (`crates/toolchain/build/src/lib.rs`):
- Set `DEFAULT_RUSTC_TARGET = "riscv64im-unknown-openvm-elf"`
(overridable via `OPENVM_TARGET`).
- Set `DEFAULT_RUSTUP_TOOLCHAIN_NAME = "openvm-nightly-2026-01-18"`
(overridable via `OPENVM_RUST_TOOLCHAIN`); guest builds invoke `cargo
+<toolchain> build --target <target>` directly, using the prebuilt
`std`/`core`/`alloc`/`panic_abort` rlibs that ship in the toolchain.
- Add `ensure_openvm_toolchain_linked()` — verifies the linked toolchain
has the guest target's prebuilt rlibs in its sysroot before invoking
cargo.

- **Guest runtime** (`crates/toolchain/openvm/`):
- New `pal_abi.rs`: provides `sys_write`, `sys_panic`, `sys_rand`,
`sys_halt`, `sys_argc`/`sys_argv`, `sys_getenv`, `sys_read`, and
`sys_alloc_aligned` symbols that the upstream `std` PAL declares.
Bridges to OpenVM's custom RISC-V instructions via `openvm_riscv_guest`.
`sys_rand` uses a byte-level ABI (`*mut u8, nbytes: usize`) with a
`hint_buffer_bytes` helper that handles non-dword-aligned tails via a
stack scratch buffer; `sys_getenv` returns `usize::MAX` per the upstream
"unset" contract.
- Simplify the `entry!` macro: a single `cfg(openvm_intrinsics)` branch
emits `#[no_mangle] fn main()` for both `std` and `no_std` guests. The
custom `_start` defined via `global_asm!` (now using `asm_const` for
`STACK_TOP`) replaces std's default entry.

- **Platform** (`crates/toolchain/platform/`):
- Update `target_os = "none"` cfg gates to `any(target_os = "none",
target_os = "openvm")` so target-gated deps (e.g. `libm`) resolve under
either form.
- Change `fileno` constants from `u32` to `i32` to match POSIX `RawFd` /
the PAL's `sys_write(fd: i32, …)` signature. Drop unused `JOURNAL` fd.

- **CLI** (`crates/cli/src/commands/toolchain.rs`):
- New `cargo openvm toolchain {install, uninstall, list}` subcommand.
`install` downloads the prebuilt tarball from openvm-org/rust Releases
for the host triple, extracts it under `~/.openvm/toolchains/`, and runs
`rustup toolchain link`. Supports `--version <tag>` and `--force`;
idempotent re-installs skip the relink via an `is_link_to` check.

- **CI helper** (`ci/install-openvm-toolchain.sh`):
- Bash equivalent of `cargo openvm toolchain install` for repo
workflows. Linux/macOS host detection, idempotent installs (skips the
download when the target's rlib dir already exists). Wired into the
`extension-tests`, `continuations`, `sdk.cuda`, `guest-lib-tests`,
`riscv`, and `cli` workflows.

- **Guest programs (~100 files)**:
- Update `no_main` cfg gate to `cfg_attr(any(target_os = "none",
target_os = "openvm"), no_main)`.
- Update 45 guest `Cargo.toml`s' `unexpected_cfgs` check-cfg to include
`cfg(openvm_intrinsics)` and `cfg(target_os, values("openvm"))` so
stable-rustc host checks recognise the new `target_os` value.

- **`riscv-guest`** (`extensions/riscv/guest/src/io.rs`):
- New `hint_buffer_bytes(*mut u8, nbytes)` — byte-granular wrapper over
the dword-granular `hint_buffer_chunked`, with a stack scratch dword for
the trailing `0..8` bytes.
- Mark `hint_buffer_chunked` `unsafe fn` (raw pointer write) and add
SAFETY blocks at the three callers in
`crates/toolchain/openvm/src/io/{mod,read}.rs`; existing callers in
`moduli-macros` codegen and the pairing libs were already inside
`unsafe` blocks.

## Test plan

### Install the toolchain

```bash
cargo openvm toolchain install         # or `bash ci/install-openvm-toolchain.sh`
```

This downloads `rust-toolchain-<host>.tar.gz` from the [openvm-org/rust
release](https://github.com/openvm-org/rust/releases/tag/openvm-nightly-2026-01-18)
and links it as `openvm-nightly-2026-01-18`.

### Test results

- `cargo nextest run -p openvm-riscv-integration-tests --run-ignored
all` — local pass.
- Guest builds: `cargo openvm build` on `examples/algebra`
(moduli-macros path) and `examples/pairing` (direct
`hint_buffer_chunked` callers) compile clean against the linked
toolchain.
- CI: all guest-touching workflows (`extension-tests`, `continuations`,
`sdk.cuda`, `guest-lib-tests`, `riscv`, `cli`) install the toolchain via
the script and pass on this branch.
- Benchmarks show no regression.

- [x] Toolchain install path works end-to-end via both the CLI and the
bash helper
- [x] Guest builds succeed with `cargo openvm build`
- [x] CI passes (all non-CUDA-gated checks)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Resolves INT-7635, INT-7654

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Ayush Shukla <ayush@axiom.xyz>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants