Skip to content

Commit 4d7c059

Browse files
Erik Kanedaflaub
Erik Kaneda
andcommitted
rustc: implement support for riscv32im_risc0_zkvm_elf
This also adds changes in the rust test suite in order to get a few of them to pass. Co-authored-by: Frank Laub <flaub@risc0.com>
1 parent e88e1b8 commit 4d7c059

File tree

6 files changed

+16
-2
lines changed

6 files changed

+16
-2
lines changed

compiler/rustc_target/src/spec/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1636,6 +1636,7 @@ supported_targets! {
16361636
("x86_64-unikraft-linux-musl", x86_64_unikraft_linux_musl),
16371637

16381638
("riscv32i-unknown-none-elf", riscv32i_unknown_none_elf),
1639+
("riscv32im-risc0-zkvm-elf", riscv32im_risc0_zkvm_elf),
16391640
("riscv32im-unknown-none-elf", riscv32im_unknown_none_elf),
16401641
("riscv32imc-unknown-none-elf", riscv32imc_unknown_none_elf),
16411642
("riscv32imc-esp-espidf", riscv32imc_esp_espidf),

library/panic_abort/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
#[cfg(target_os = "android")]
2020
mod android;
2121

22+
#[cfg(target_os = "zkvm")]
23+
mod zkvm;
24+
2225
use core::any::Any;
2326
use core::panic::PanicPayload;
2427

@@ -34,6 +37,8 @@ pub unsafe fn __rust_start_panic(_payload: &mut dyn PanicPayload) -> u32 {
3437
// Android has the ability to attach a message as part of the abort.
3538
#[cfg(target_os = "android")]
3639
android::android_set_abort_message(_payload);
40+
#[cfg(target_os = "zkvm")]
41+
zkvm::zkvm_set_abort_message(_payload);
3742

3843
abort();
3944

library/test/src/console.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ pub fn run_tests_console(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> io::Resu
323323
// Prevent the usage of `Instant` in some cases:
324324
// - It's currently not supported for wasm targets.
325325
// - We disable it for miri because it's not available when isolation is enabled.
326-
let is_instant_supported = !cfg!(target_family = "wasm") && !cfg!(miri);
326+
let is_instant_supported = !cfg!(target_family = "wasm") && !cfg!(target_os = "zkvm") && !cfg!(miri);
327327

328328
let start_time = is_instant_supported.then(Instant::now);
329329
run_tests(opts, tests, |x| on_test_event(&x, &mut st, &mut *out))?;

library/test/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ pub fn run_test(
546546

547547
// Emscripten can catch panics but other wasm targets cannot
548548
let ignore_because_no_process_support = desc.should_panic != ShouldPanic::No
549-
&& cfg!(target_family = "wasm")
549+
&& (cfg!(target_family = "wasm") || cfg!(target_os = "zkvm"))
550550
&& !cfg!(target_os = "emscripten");
551551

552552
if force_ignore || desc.ignore || ignore_because_no_process_support {

src/bootstrap/src/lib.rs

+7
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ const EXTRA_CHECK_CFGS: &[(Option<Mode>, &str, Option<&[&'static str]>)] = &[
9898
/* Extra values not defined in the built-in targets yet, but used in std */
9999
(Some(Mode::Std), "target_env", Some(&["libnx"])),
100100
// (Some(Mode::Std), "target_os", Some(&[])),
101+
(Some(Mode::Std), "target_os", Some(&["zkvm"])),
102+
(Some(Mode::Std), "target_vendor", Some(&["risc0"])),
101103
(Some(Mode::Std), "target_arch", Some(&["asmjs", "spirv", "nvptx", "xtensa"])),
102104
/* Extra names used by dependencies */
103105
// FIXME: Used by serde_json, but we should not be triggering on external dependencies.
@@ -729,6 +731,11 @@ impl Build {
729731
if self.config.profiler_enabled(target) {
730732
features.push_str(" profiler");
731733
}
734+
// Generate memcpy, etc. FIXME: Remove this once compiler-builtins
735+
// automatically detects this target.
736+
if target.contains("zkvm") {
737+
features.push_str(" compiler-builtins-mem");
738+
}
732739
features
733740
}
734741

src/tools/build-manifest/src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ static TARGETS: &[&str] = &[
120120
"powerpc64-unknown-linux-gnu",
121121
"powerpc64le-unknown-linux-gnu",
122122
"riscv32i-unknown-none-elf",
123+
"riscv32im-risc0-zkvm-elf",
123124
"riscv32im-unknown-none-elf",
124125
"riscv32imc-unknown-none-elf",
125126
"riscv32imac-unknown-none-elf",

0 commit comments

Comments
 (0)