lib.rs 1.82 KB
Newer Older
nhynes committed
1 2 3 4 5 6 7 8 9 10 11 12
//! This crate is an implementation of the TVM runtime for modules compiled with `--system-lib`.
//! It's mainly useful for compiling to WebAssembly and SGX,
//! but also native if you prefer Rust to C++.
//!
//! For TVM graphs, the entrypoint to this crate is `runtime::GraphExecutor`.
//! Single-function modules are used via the `packed_func!` macro after obtaining
//! the function from `runtime::SystemLibModule`
//!
//! The main entrypoints to this crate are `GraphExecutor`
//! For examples of use, please refer to the multi-file tests in the `tests` directory.

#![feature(
13 14 15 16 17 18 19
    alloc,
    allocator_api,
    box_syntax,
    fn_traits,
    try_from,
    unboxed_closures,
    vec_remove_item
nhynes committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
)]

#[cfg(target_env = "sgx")]
extern crate alloc;
extern crate bounded_spsc_queue;
#[cfg(target_env = "sgx")]
extern crate core;
#[macro_use]
extern crate error_chain;
#[macro_use]
extern crate itertools;
#[macro_use]
extern crate lazy_static;
extern crate ndarray;
#[macro_use]
extern crate nom;
#[cfg(not(target_env = "sgx"))]
extern crate num_cpus;
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
42
extern crate tvm_common as common;
nhynes committed
43

44 45 46 47 48 49 50 51 52 53 54 55
mod allocator;
mod array;
pub mod errors;
mod module;
#[macro_use]
mod packed_func;
mod graph;
#[cfg(target_env = "sgx")]
#[macro_use]
pub mod sgx;
mod threading;
mod workspace;
nhynes committed
56

57
pub use crate::common::{errors::*, ffi, TVMArgValue, TVMRetValue};
nhynes committed
58

59 60 61
pub use self::{
    array::*, errors::*, graph::*, module::*, packed_func::*, threading::*, workspace::*,
};
nhynes committed
62

63 64
#[cfg(target_env = "sgx")]
use self::sgx::ocall_packed_func;
nhynes committed
65

66 67 68 69 70 71 72 73 74
#[no_mangle]
pub extern "C" fn TVMAPISetLastError(cmsg: *const i8) {
    #[cfg(not(target_env = "sgx"))]
    unsafe {
        panic!(std::ffi::CStr::from_ptr(cmsg).to_str().unwrap());
    }
    #[cfg(target_env = "sgx")]
    ocall_packed!("__sgx_set_last_error__", cmsg);
}