Skip to content

Commit 68c8a33

Browse files
committed
feat: support JOLT
1 parent 2948388 commit 68c8a33

File tree

15 files changed

+177
-113
lines changed

15 files changed

+177
-113
lines changed

.github/workflows/release.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: release
2+
3+
on:
4+
workflow_call:
5+
workflow_dispatch:
6+
7+
jobs:
8+
build:
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
config:
13+
- { os: macos-14, triple: aarch64-apple-darwin }
14+
- { os: macos-13, triple: x86_64-apple-darwin }
15+
- { os: ubuntu-latest, triple: x86_64-unknown-linux-gnu }
16+
- { os: ubuntu-22.04-arm, triple: aarch64-unknown-linux-gnu }
17+
channel: [stable, nightly]
18+
runs-on: ${{ matrix.config.os }}
19+
steps:
20+
- name: Install nightly toolchain
21+
id: rustc-toolchain
22+
uses: actions-rs/toolchain@v1
23+
with:
24+
toolchain: nightly-2025-08-04
25+
default: true
26+
27+
- uses: lukka/get-cmake@v3.27.4
28+
29+
- name: Show rust version
30+
run: |
31+
cargo version
32+
rustup toolchain list
33+
34+
- name: Check out a16z/rust
35+
uses: actions/checkout@v4
36+
with:
37+
submodules: "recursive"
38+
path: rust
39+
40+
- name: Configure Rust build
41+
run: |
42+
./configure \
43+
--set change-id="ignore" \
44+
--target "${{ matrix.config.triple }},riscv32im-jolt-zkvm-elf,riscv64imac-jolt-zkvm-elf" \
45+
--tools "cargo,cargo-clippy,clippy,rustfmt" \
46+
--release-channel="${{ matrix.channel }}" \
47+
--set rust.lld \
48+
--set rust.llvm-tools \
49+
--set build.extended \
50+
--set llvm.download-ci-llvm=false \
51+
--set build.optimized-compiler-builtins=false
52+
working-directory: rust
53+
54+
- name: Build
55+
run: |
56+
export GITHUB_ACTIONS=false
57+
export CARGO_TARGET_RISCV32IM_JOLT_ZKVM_ELF_RUSTFLAGS="-Cpasses=lower-atomic"
58+
./x.py build --stage 2
59+
working-directory: rust
60+
61+
- name: Archive
62+
run: tar -czvf rust-toolchain-${{ matrix.channel }}-${{ matrix.config.triple }}.tar.gz rust/build/host/stage2
63+
64+
- name: Upload Release Assets
65+
uses: softprops/action-gh-release@v1
66+
with:
67+
tag_name: ${{ matrix.channel }}-${{ github.sha }}
68+
name: "Rust Toolchain - ${{ matrix.channel }} - ${{ github.sha }}"
69+
prerelease: true
70+
files: |
71+
rust-toolchain-${{ matrix.channel }}-${{ matrix.config.triple }}.tar.gz
72+
env:
73+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

compiler/rustc_target/src/spec/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,6 +1967,7 @@ supported_targets! {
19671967

19681968
("riscv32i-unknown-none-elf", riscv32i_unknown_none_elf),
19691969
("riscv32im-risc0-zkvm-elf", riscv32im_risc0_zkvm_elf),
1970+
("riscv32im-jolt-zkvm-elf", riscv32im_jolt_zkvm_elf),
19701971
("riscv32im-unknown-none-elf", riscv32im_unknown_none_elf),
19711972
("riscv32ima-unknown-none-elf", riscv32ima_unknown_none_elf),
19721973
("riscv32imc-unknown-none-elf", riscv32imc_unknown_none_elf),
@@ -1983,6 +1984,7 @@ supported_targets! {
19831984
("riscv32imac-unknown-xous-elf", riscv32imac_unknown_xous_elf),
19841985
("riscv32gc-unknown-linux-gnu", riscv32gc_unknown_linux_gnu),
19851986
("riscv32gc-unknown-linux-musl", riscv32gc_unknown_linux_musl),
1987+
("riscv64imac-jolt-zkvm-elf", riscv64imac_jolt_zkvm_elf),
19861988
("riscv64imac-unknown-none-elf", riscv64imac_unknown_none_elf),
19871989
("riscv64gc-unknown-none-elf", riscv64gc_unknown_none_elf),
19881990
("riscv64gc-unknown-linux-gnu", riscv64gc_unknown_linux_gnu),
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use crate::spec::{Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel};
2+
use crate::spec::{Target, TargetOptions};
3+
4+
pub(crate) fn target() -> Target {
5+
Target {
6+
data_layout: "e-m:e-p:32:32-i64:64-n32-S128".into(),
7+
llvm_target: "riscv32".into(),
8+
pointer_width: 32,
9+
arch: "riscv32".into(),
10+
11+
metadata: crate::spec::TargetMetadata {
12+
description: Some("Jolt's Zero's zero-knowledge Virtual Machine (RV32IM ISA)".into()),
13+
tier: Some(3),
14+
host_tools: Some(false),
15+
std: None,
16+
},
17+
18+
options: TargetOptions {
19+
os: "zkvm".into(),
20+
vendor: "jolt".into(),
21+
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes),
22+
linker: Some("rust-lld".into()),
23+
cpu: "generic-rv32".into(),
24+
features: "+m".into(),
25+
max_atomic_width: Some(64),
26+
atomic_cas: true,
27+
executables: true,
28+
llvm_abiname: "ilp32".into(),
29+
panic_strategy: PanicStrategy::Abort,
30+
relocation_model: RelocModel::Static,
31+
emit_debug_gdb_scripts: false,
32+
eh_frame_header: false,
33+
singlethread: true,
34+
supports_stack_protector: false,
35+
..Default::default()
36+
},
37+
}
38+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use crate::spec::{
2+
Cc, CodeModel, LinkerFlavor, Lld, PanicStrategy, RelocModel, SanitizerSet, Target,
3+
TargetOptions,
4+
};
5+
6+
pub(crate) fn target() -> Target {
7+
Target {
8+
data_layout: "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128".into(),
9+
llvm_target: "riscv64".into(),
10+
metadata: crate::spec::TargetMetadata {
11+
description: Some("Jolt's Zero's zero-knowledge Virtual Machine (RV64IMAC ISA)".into()),
12+
tier: Some(3),
13+
host_tools: Some(false),
14+
std: None,
15+
},
16+
pointer_width: 64,
17+
arch: "riscv64".into(),
18+
19+
options: TargetOptions {
20+
os: "zkvm".into(),
21+
vendor: "jolt".into(),
22+
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes),
23+
linker: Some("rust-lld".into()),
24+
cpu: "generic-rv64".into(),
25+
max_atomic_width: Some(64),
26+
atomic_cas: true,
27+
executables: true,
28+
features: "+m,+a,+c".into(),
29+
llvm_abiname: "lp64".into(),
30+
panic_strategy: PanicStrategy::Abort,
31+
relocation_model: RelocModel::Static,
32+
code_model: Some(CodeModel::Medium),
33+
emit_debug_gdb_scripts: false,
34+
eh_frame_header: false,
35+
supported_sanitizers: SanitizerSet::KERNELADDRESS | SanitizerSet::SHADOWCALLSTACK,
36+
singlethread: true,
37+
supports_stack_protector: false,
38+
..Default::default()
39+
},
40+
}
41+
}

library/panic_abort/src/zkvm.rs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,11 @@
1-
use alloc::string::String;
21
use core::panic::PanicPayload;
32

4-
// Forward the abort message to zkVM's sys_panic. This is implemented by RISC Zero's
5-
// platform crate which exposes system calls specifically for the zkVM.
6-
pub(crate) unsafe fn zkvm_set_abort_message(payload: &mut dyn PanicPayload) {
7-
let payload = payload.get();
8-
let msg = match payload.downcast_ref::<&'static str>() {
9-
Some(msg) => msg.as_bytes(),
10-
None => match payload.downcast_ref::<String>() {
11-
Some(msg) => msg.as_bytes(),
12-
None => &[],
13-
},
14-
};
15-
if msg.is_empty() {
16-
return;
17-
}
18-
3+
pub(crate) unsafe fn zkvm_set_abort_message(_payload: &mut dyn PanicPayload) {
194
unsafe extern "C" {
20-
fn sys_panic(msg_ptr: *const u8, len: usize) -> !;
5+
fn jolt_panic() -> !;
216
}
227

238
unsafe {
24-
sys_panic(msg.as_ptr(), msg.len());
9+
jolt_panic();
2510
}
26-
}
11+
}

library/std/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@
248248
#![allow(explicit_outlives_requirements)]
249249
#![allow(unused_lifetimes)]
250250
#![allow(internal_features)]
251-
#![deny(fuzzy_provenance_casts)]
251+
// #![deny(fuzzy_provenance_casts)]
252252
#![deny(unsafe_op_in_unsafe_fn)]
253253
#![allow(rustdoc::redundant_explicit_links)]
254254
#![warn(rustdoc::unescaped_backticks)]

library/std/src/sys/alloc/zkvm.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1+
use crate::sys::abi::sys_alloc;
12
use crate::alloc::{GlobalAlloc, Layout, System};
2-
use crate::sys::pal::abi;
33

44
#[stable(feature = "alloc_system_type", since = "1.28.0")]
55
unsafe impl GlobalAlloc for System {
6-
#[inline]
76
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
8-
unsafe { abi::sys_alloc_aligned(layout.size(), layout.align()) }
7+
unsafe { sys_alloc(layout.size(), layout.align()) }
98
}
109

11-
#[inline]
12-
unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {
13-
// this allocator never deallocates memory
14-
}
15-
}
10+
unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {}
11+
}

library/std/src/sys/args/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ cfg_if::cfg_if! {
3333
pub use wasi::*;
3434
} else if #[cfg(target_os = "xous")] {
3535
mod xous;
36-
pub use xous::*;
37-
} else if #[cfg(target_os = "zkvm")] {
38-
mod zkvm;
39-
pub use zkvm::*;
36+
pub use xous::*;
4037
} else {
4138
mod unsupported;
4239
pub use unsupported::*;

library/std/src/sys/env/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ cfg_if::cfg_if! {
3838
} else if #[cfg(target_os = "xous")] {
3939
mod xous;
4040
pub use xous::*;
41-
} else if #[cfg(target_os = "zkvm")] {
42-
mod zkvm;
43-
pub use zkvm::*;
4441
} else {
4542
mod unsupported;
4643
pub use unsupported::*;
Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,4 @@
1-
//! ABI definitions for symbols exported by risc0-zkvm-platform.
2-
3-
// Included here so we don't have to depend on risc0-zkvm-platform.
4-
//
5-
// FIXME: Should we move this to the "libc" crate? It seems like other
6-
// architectures put a lot of this kind of stuff there. But there's
7-
// currently no risc0 fork of the libc crate, so we'd either have to
8-
// fork it or upstream it.
9-
10-
#![allow(dead_code)]
11-
pub const DIGEST_WORDS: usize = 8;
12-
13-
/// Standard IO file descriptors for use with sys_read and sys_write.
14-
pub mod fileno {
15-
pub const STDIN: u32 = 0;
16-
pub const STDOUT: u32 = 1;
17-
pub const STDERR: u32 = 2;
18-
pub const JOURNAL: u32 = 3;
19-
}
20-
211
unsafe extern "C" {
22-
// Wrappers around syscalls provided by risc0-zkvm-platform:
23-
pub fn sys_halt();
24-
pub fn sys_output(output_id: u32, output_value: u32);
25-
pub fn sys_sha_compress(
26-
out_state: *mut [u32; DIGEST_WORDS],
27-
in_state: *const [u32; DIGEST_WORDS],
28-
block1_ptr: *const [u32; DIGEST_WORDS],
29-
block2_ptr: *const [u32; DIGEST_WORDS],
30-
);
31-
pub fn sys_sha_buffer(
32-
out_state: *mut [u32; DIGEST_WORDS],
33-
in_state: *const [u32; DIGEST_WORDS],
34-
buf: *const u8,
35-
count: u32,
36-
);
37-
pub fn sys_rand(recv_buf: *mut u32, words: usize);
38-
pub fn sys_panic(msg_ptr: *const u8, len: usize) -> !;
39-
pub fn sys_log(msg_ptr: *const u8, len: usize);
40-
pub fn sys_cycle_count() -> usize;
41-
pub fn sys_read(fd: u32, recv_buf: *mut u8, nrequested: usize) -> usize;
42-
pub fn sys_write(fd: u32, write_buf: *const u8, nbytes: usize);
43-
pub fn sys_getenv(
44-
recv_buf: *mut u32,
45-
words: usize,
46-
varname: *const u8,
47-
varname_len: usize,
48-
) -> usize;
49-
pub fn sys_argc() -> usize;
50-
pub fn sys_argv(out_words: *mut u32, out_nwords: usize, arg_index: usize) -> usize;
51-
52-
// Allocate memory from global HEAP.
53-
pub fn sys_alloc_words(nwords: usize) -> *mut u32;
54-
pub fn sys_alloc_aligned(nwords: usize, align: usize) -> *mut u8;
55-
}
2+
pub fn sys_rand(dest: *mut u8, words: usize);
3+
pub fn sys_alloc(size: usize, align: usize) -> *mut u8;
4+
}

0 commit comments

Comments
 (0)