tezos_smart_rollup_entrypoint/
lib.rs

1// SPDX-FileCopyrightText: 2022-2023 TriliTech <contact@trili.tech>
2// SPDX-FileCopyrightText: 2023 Nomadic Labs <contact@nomadic-labs.com>
3//
4// SPDX-License-Identifier: MIT
5
6#![doc = include_str!("../README.md")]
7#![deny(missing_docs)]
8#![deny(rustdoc::broken_intra_doc_links)]
9#![cfg_attr(not(feature = "std"), no_std)]
10
11#[cfg(feature = "dlmalloc")]
12mod allocator {
13    use dlmalloc::GlobalDlmalloc;
14
15    #[global_allocator]
16    static ALLOCATOR: GlobalDlmalloc = GlobalDlmalloc;
17}
18
19/// Set panic hook
20#[cfg(feature = "panic-hook")]
21pub fn set_panic_hook() {
22    std::panic::set_hook(Box::new(tezos_smart_rollup_panic_hook::panic_handler));
23}
24
25/// Dummy panic hook that does nothing.
26#[cfg(not(feature = "panic-hook"))]
27pub fn set_panic_hook() {}
28
29#[cfg(feature = "alloc")]
30extern crate alloc;
31
32/// Derive `kernel_run` & `mock_kernel_run` entrypoints.
33///
34/// ```no_run
35/// # extern crate alloc;
36/// #[macro_use] extern crate tezos_smart_rollup_entrypoint;
37/// #[macro_use] extern crate tezos_smart_rollup_debug;
38///
39/// use tezos_smart_rollup_host::runtime::Runtime;
40///
41/// fn run<Host: Runtime>(host: &mut Host) {
42///   debug_msg!(host, "Hello: {}", "Kernel!");
43/// }
44///
45/// # #[cfg(doc)]
46/// kernel_entry!(run);
47/// ```
48#[macro_export]
49macro_rules! kernel_entry {
50    ($kernel_run: expr) => {
51        /// The `kernel_run` function is called by the wasm host at regular intervals.
52        #[cfg(target_arch = "wasm32")]
53        #[no_mangle]
54        pub extern "C" fn kernel_run() {
55            $crate::set_panic_hook();
56            use $crate::RollupHost;
57            let mut host = unsafe { RollupHost::new() };
58            $kernel_run(&mut host)
59        }
60    };
61}
62
63#[doc(hidden)]
64pub use tezos_smart_rollup_core::rollup_host::RollupHost;