Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples: Test Rust VM #233

Merged
merged 3 commits into from
Apr 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
members = [
"bindings/rust/evmc-sys",
"bindings/rust/evmc-vm",
"examples/example-rust-vm"
]
16 changes: 15 additions & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ jobs:
- store_artifacts:
path: ~/package
destination: package
- persist_to_workspace:
root: ~/build
paths:
- test/evmc-vmtester

build-cxx17:
<<: *build
Expand Down Expand Up @@ -159,6 +163,14 @@ jobs:
- run:
name: Test
command: cargo test
- attach_workspace:
at: ~/build
- run:
name: Test with evmc-vmtester
command: |
# FIXME: there is a linking issue with Cargo workspaces, this is to workaround it
export LD_LIBRARY_PATH="$(rustc --print sysroot)/lib:$LD_LIBRARY_PATH"
~/build/test/evmc-vmtester target/debug/libexamplerustvm.so

workflows:
version: 2
Expand All @@ -171,7 +183,9 @@ workflows:
- build-clang3.8
- bindings-go-latest
- bindings-go-min
- bindings-rust
- bindings-rust:
requires:
- build-cxx17
- test-docs
- upload-docs:
requires:
Expand Down
12 changes: 12 additions & 0 deletions examples/example-rust-vm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "example-rust-vm"
version = "0.1.0"
authors = ["Alex Beregszaszi <[email protected]>"]
edition = "2018"

[lib]
name = "examplerustvm"
crate-type = ["staticlib", "dylib"]

[dependencies]
evmc-vm = { path = "../../bindings/rust/evmc-vm" }
52 changes: 52 additions & 0 deletions examples/example-rust-vm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
extern crate evmc_vm;

use evmc_vm::evmc_sys as ffi;

extern "C" fn execute(
instance: *mut ffi::evmc_instance,
context: *mut ffi::evmc_context,
rev: ffi::evmc_revision,
msg: *const ffi::evmc_message,
code: *const u8,
code_size: usize,
) -> ffi::evmc_result {
let result = evmc_vm::ExecutionResult::new(
ffi::evmc_status_code::EVMC_SUCCESS,
66,
None,
ffi::evmc_address { bytes: [0u8; 20] },
);
result.into()
}

extern "C" fn get_capabilities(
instance: *mut ffi::evmc_instance,
) -> ffi::evmc_capabilities_flagset {
ffi::evmc_capabilities::EVMC_CAPABILITY_EVM1 as u32
}

extern "C" fn destroy(instance: *mut ffi::evmc_instance) {
drop(unsafe { Box::from_raw(instance) })
}

#[no_mangle]
pub extern "C" fn evmc_create_examplerustvm() -> *const ffi::evmc_instance {
let ret = ffi::evmc_instance {
abi_version: ffi::EVMC_ABI_VERSION as i32,
destroy: Some(destroy),
execute: Some(execute),
get_capabilities: Some(get_capabilities),
set_option: None,
set_tracer: None,
name: {
let c_str =
std::ffi::CString::new("ExampleRustVM").expect("Failed to build EVMC name string");
c_str.into_raw() as *const i8
},
version: {
let c_str = std::ffi::CString::new("1.0").expect("Failed to build EVMC version string");
c_str.into_raw() as *const i8
},
};
Box::into_raw(Box::new(ret))
}