feat(v2.1-rv64): integrate riscv64im-unknown-openvm-elf target into build system#2765
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
aafca0a to
e8e2e8f
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
d6e8a8d to
9a37c32
Compare
e8e2e8f to
0958ffc
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
a8a77ba to
3ae8395
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
3ae8395 to
d9d95dc
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
d9d95dc to
235f041
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
235f041 to
de4ffe3
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
de4ffe3 to
397f469
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
397f469 to
19d5a2c
Compare
This comment has been minimized.
This comment has been minimized.
jonathanpwang
left a comment
There was a problem hiding this comment.
I commented on some guest UX issue.
Other than that, the main changes LGTM. However, I think we should add a separate parallel CI to test the full CLI against the riscv64im-unknown-none-elf target to make sure things still work smoothly there. It doesn't need to be the main recommended path, but I'd still like to make sure using this non-custom target has good support.
Make `cargo openvm build` smoothly switch between the openvm-fork's custom
`riscv64im-unknown-openvm-elf` target and the upstream tier-3
`riscv64im-unknown-none-elf` target via env var overrides.
- `target_has_prebuilt_std()`: new helper that checks
`<rustc parent>/../lib/rustlib/<target>/lib/` to decide whether the
toolchain ships prebuilt rlibs for the configured target. The openvm-fork
ships them; the upstream tier-3 none target does not (per rust-lang.org
platform-support docs).
- `cargo_command()`: when prebuilts are missing, automatically pass
`-Z build-std=core,alloc,panic_abort` plus
`-Z build-std-features=compiler-builtins-mem` so cargo builds std from
source via `rust-src`. This is the existing flow restored, but now
scoped only to targets that need it.
- `ensure_openvm_toolchain_linked()`: missing prebuilts is no longer
fatal — it's now the `-Z build-std` path. The function instead checks
for the `rust-src` component (`lib/rustlib/src/rust/library`) and prints
install hints that branch on `is_openvm_toolchain(toolchain)`:
* openvm-fork toolchain missing rlibs → `cargo openvm toolchain install --force`
* upstream toolchain missing rust-src → `rustup component add rust-src --toolchain <X>`
- `is_openvm_toolchain()`: new helper exposing the `openvm-` name-prefix
check used by the install-hint branching, also reusable from other
callers that need to distinguish the two flows.
- Renames the env var consts and reorgs the file head: all `const`s
(public then private) grouped at the top, then helpers, then the rest.
- AGENTS.md: env var rename `OPENVM_TARGET` → `OPENVM_RUSTC_TARGET`,
with new wording covering the prebuilt-rlibs-OR-rust-src requirement.
- CLI post-install hint now shows the `RUSTFLAGS="-Cpasses=lower-atomic"`
envelope for the direct `cargo +<toolchain> build` invocation.
CI:
- New `.github/workflows/cli.yml` job `app-level-cli-none-elf` runs
parallel to the main `app-level-cli`. Installs stock
`nightly-2026-01-18` + `rust-src`, sets
`OPENVM_RUST_TOOLCHAIN=nightly-2026-01-18`,
`OPENVM_RUSTC_TARGET=riscv64im-unknown-none-elf`, then runs
`cargo openvm init` + `build` + `run` to keep the upstream-target path
exercised. Doesn't run the full extension test matrix because some
deps (alloy etc.) won't compile against tier-3 / max_atomic_width=0.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This comment was marked as outdated.
This comment was marked as outdated.
Use openvm-1.94.0 as the default guest Rust toolchain in openvm-build, cargo openvm toolchain install, and the CI install helper. Update docs to describe the default as a stable OpenVM release, and clarify that users can install other published toolchain tags, including selected nightly variants, with cargo openvm toolchain install --version <tag>.
This comment was marked as outdated.
This comment was marked as outdated.
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
Previous run failed at runtime with VM error: phantom error: EndOfInputStream because the cargo-openvm-init template's `pub fn main()` calls `openvm::io::read::<u64>()` as its first instruction, and the smoke job was invoking `cargo openvm run` with no input. The hint stream was empty, so the very first read hit end-of-stream and the VM errored out. Pass `fib_10_input="0x010A00000000000000"` — the `0x01` "raw bytes" prefix followed by 8 little-endian bytes for `n = 10u64`. That's the same input I verified locally; the guest computes fibonacci(10) = 55 and reveals it. Build steps were already succeeding; this only affects runtime. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
A handful of small fixes scattered across the PR that fell out of the default-flip and the smoke-test investigation: - `crates/toolchain/build/src/lib.rs`: when the configured toolchain is an upstream (non-`openvm-`-prefixed) channel and the target has no prebuilt rlibs, explicitly check that the toolchain reports as nightly before claiming the build can proceed. `-Z build-std` is nightly-only; on stable we'd silently emit it and fail at the cargo level. The new error message points the user at `rustup toolchain install nightly --component rust-src` with a worked `OPENVM_RUST_TOOLCHAIN=nightly` invocation. Also tighten the openvm-toolchain-missing-prebuilts branch — that case is always a broken/truncated tarball so the only useful hint is `cargo openvm toolchain install --force`. - `crates/toolchain/openvm/src/pal_abi.rs`: tidy a few user-visible strings. Drop the noisy "sys_argc is todo; returning 0" println that fires on every std program startup. Reword "sys_X is todo" → "unsupported OpenVM syscall: sys_X" so the guest log makes sense when a real program hits these. Replace one `write!(... "\n")` with `writeln!(...)`. - `extensions/riscv/guest/src/io.rs`: in the `hint_buffer_chunked` / `hint_buffer_bytes` helpers (both already `unsafe fn`), use `ptr.add(...)` instead of `wrapping_add(...)` since the offsets are guaranteed in-bounds by the caller's safety contract. The non-wrapping variant gives stronger UB guarantees + slightly better optimization. - `extensions/riscv/tests/programs/examples/std_collections.rs`: align the `#![cfg_attr(... no_main)]` gate with what `cargo openvm init` now generates (`all(not(feature = "std"), any(openvm_intrinsics, target_os = "openvm"))`). - `docs/.../quickstart.mdx` + `docs/.../writing-a-program.mdx`: update the example `no_main` cfg_attr lines to the same form (matching the init template + the test programs). Tighten the prose around "openvm guest" vs "no_main openvm guest". - `AGENTS.md`: tighten the `OPENVM_RUSTC_TARGET` env var description to spell out that an upstream toolchain without prebuilts must be nightly + have `rust-src`. `cargo +nightly fmt` and `cargo check -p openvm-build -p openvm` clean. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This comment was marked as outdated.
This comment was marked as outdated.
Note: cells_used metrics omitted because CUDA tracegen does not expose unpadded trace heights. Commit: 95590ce |
…p run
Two debuggability fixes:
- `.github/workflows/cli.yml`: `cargo openvm build` invokes an inner
`cargo build` under a `tty_println`-style wrapper that writes its
output to `/dev/tty` (or the `OPENVM_GUEST_LOGFILE` env var if set).
In GHA the wrapper has no tty, so previous build failures dropped
the inner cargo output on the floor and showed nothing actionable
in the workflow log. Set `OPENVM_GUEST_LOGFILE` to a file and `cat`
it on `cargo openvm build` failure so the inner errors are visible.
- `crates/toolchain/build/src/lib.rs`: switch the nightly-check
invocation from the `rustup +<toolchain>` proxy shorthand to the
explicit `rustup run <toolchain> rustc --version` form. Output
format is identical, so the `contains("nightly")` check still
works; the explicit form is more conventional and avoids any
argument-parsing ambiguity if `<toolchain>` ever contains an
unusual character.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Claude finished @shuklaayush's task in 3m 3s —— View job Code Review: PR #2765 — Integrate
|
|
Claude finished @shuklaayush's task in 3m 3s —— View job Code Review: PR #2765 — Integrate
|
Note: cells_used metrics omitted because CUDA tracegen does not expose unpadded trace heights. Commit: 8122b5c |
jonathanpwang
left a comment
There was a problem hiding this comment.
LGTM, the is_openvm build is handled nicely
|
Claude finished @shuklaayush's task in 2m 48s —— View job Code Review: PR #2765 — Integrate
|
Note: cells_used metrics omitted because CUDA tracegen does not expose unpadded trace heights. Commit: de73e22 |
|
Claude finished @shuklaayush's task in 3m 16s —— View job Code Review: PR #2765 — Integrate
|
Note: cells_used metrics omitted because CUDA tracegen does not expose unpadded trace heights. Commit: f8732f6 |
Summary
Integrate the built-in Rust target
riscv64im-unknown-openvm-elf(target_os = "openvm") into the OpenVM build system and guest crates, enablingstdsupport for guest programs.The target itself was added to the OpenVM Rust fork in openvm-org/rust#3. Prebuilt toolchain tarballs are published on the fork's Releases page — install via
cargo openvm toolchain install(this PR) or the CI helper script.Changes
Build system (
crates/toolchain/build/src/lib.rs):DEFAULT_RUSTC_TARGET = "riscv64im-unknown-openvm-elf"(overridable viaOPENVM_TARGET).DEFAULT_RUSTUP_TOOLCHAIN_NAME = "openvm-nightly-2026-01-18"(overridable viaOPENVM_RUST_TOOLCHAIN); guest builds invokecargo +<toolchain> build --target <target>directly, using the prebuiltstd/core/alloc/panic_abortrlibs that ship in the toolchain.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/):pal_abi.rs: providessys_write,sys_panic,sys_rand,sys_halt,sys_argc/sys_argv,sys_getenv,sys_read, andsys_alloc_alignedsymbols that the upstreamstdPAL declares. Bridges to OpenVM's custom RISC-V instructions viaopenvm_riscv_guest.sys_randuses a byte-level ABI (*mut u8, nbytes: usize) with ahint_buffer_byteshelper that handles non-dword-aligned tails via a stack scratch buffer;sys_getenvreturnsusize::MAXper the upstream "unset" contract.entry!macro: a singlecfg(openvm_intrinsics)branch emits#[no_mangle] fn main()for bothstdandno_stdguests. The custom_startdefined viaglobal_asm!(now usingasm_constforSTACK_TOP) replaces std's default entry.Platform (
crates/toolchain/platform/):target_os = "none"cfg gates toany(target_os = "none", target_os = "openvm")so target-gated deps (e.g.libm) resolve under either form.filenoconstants fromu32toi32to match POSIXRawFd/ the PAL'ssys_write(fd: i32, …)signature. Drop unusedJOURNALfd.CLI (
crates/cli/src/commands/toolchain.rs):cargo openvm toolchain {install, uninstall, list}subcommand.installdownloads the prebuilt tarball from openvm-org/rust Releases for the host triple, extracts it under~/.openvm/toolchains/, and runsrustup toolchain link. Supports--version <tag>and--force; idempotent re-installs skip the relink via anis_link_tocheck.CI helper (
ci/install-openvm-toolchain.sh):cargo openvm toolchain installfor repo workflows. Linux/macOS host detection, idempotent installs (skips the download when the target's rlib dir already exists). Wired into theextension-tests,continuations,sdk.cuda,guest-lib-tests,riscv, andcliworkflows.Guest programs (~100 files):
no_maincfg gate tocfg_attr(any(target_os = "none", target_os = "openvm"), no_main).Cargo.tomls'unexpected_cfgscheck-cfg to includecfg(openvm_intrinsics)andcfg(target_os, values("openvm"))so stable-rustc host checks recognise the newtarget_osvalue.riscv-guest(extensions/riscv/guest/src/io.rs):hint_buffer_bytes(*mut u8, nbytes)— byte-granular wrapper over the dword-granularhint_buffer_chunked, with a stack scratch dword for the trailing0..8bytes.hint_buffer_chunkedunsafe fn(raw pointer write) and add SAFETY blocks at the three callers incrates/toolchain/openvm/src/io/{mod,read}.rs; existing callers inmoduli-macroscodegen and the pairing libs were already insideunsafeblocks.Test plan
Install the toolchain
cargo openvm toolchain install # or `bash ci/install-openvm-toolchain.sh`This downloads
rust-toolchain-<host>.tar.gzfrom the openvm-org/rust release and links it asopenvm-nightly-2026-01-18.Test results
cargo nextest run -p openvm-riscv-integration-tests --run-ignored all— local pass.Guest builds:
cargo openvm buildonexamples/algebra(moduli-macros path) andexamples/pairing(directhint_buffer_chunkedcallers) 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.
Toolchain install path works end-to-end via both the CLI and the bash helper
Guest builds succeed with
cargo openvm buildCI passes (all non-CUDA-gated checks)
🤖 Generated with Claude Code
Resolves INT-7635, INT-7654