Skip to content
This repository was archived by the owner on Apr 8, 2026. It is now read-only.

Commit 317135d

Browse files
committed
add loader
1 parent a1d2845 commit 317135d

8 files changed

Lines changed: 123 additions & 0 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ members = [
44
"bindings/rust/evmc-vm",
55
"bindings/rust/evmc-declare",
66
"bindings/rust/evmc-declare-tests",
7+
"bindings/rust/evmc-loader",
78
"examples/example-rust-vm"
89
]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/target
2+
**/*.rs.bk
3+
/Cargo.lock
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# EVMC: Ethereum Client-VM Connector API.
2+
# Copyright 2019 The EVMC Authors.
3+
# Licensed under the Apache License, Version 2.0.
4+
5+
[package]
6+
name = "evmc-loader"
7+
version = "10.0.0-alpha.5"
8+
authors = ["Alex Beregszaszi <alex@rtfs.hu>"]
9+
license = "Apache-2.0"
10+
repository = "https://github.com/ethereum/evmc"
11+
description = "Bindings to EVMC (Loader bindings)"
12+
edition = "2018"
13+
14+
[build-dependencies]
15+
bindgen = "0.59"
16+
cmake = "0.1"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# evmc-vm
2+
3+
This is a Rust interface to [EVMC](https://github.com/ethereum/evmc).
4+
5+
This crate contains the implementation helpers for the VM-side.

bindings/rust/evmc-loader/build.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// EVMC: Ethereum Client-VM Connector API.
2+
// Copyright 2019 The EVMC Authors.
3+
// Licensed under the Apache License, Version 2.0.
4+
5+
extern crate bindgen;
6+
extern crate cmake;
7+
8+
use cmake::Config;
9+
use std::env;
10+
use std::path::{Path, PathBuf};
11+
12+
fn gen_bindings() {
13+
let bindings = bindgen::Builder::default()
14+
.header("loader.h")
15+
.generate_comments(false)
16+
// do not generate an empty enum for EVMC_ABI_VERSION
17+
.constified_enum("")
18+
// generate Rust enums for each evmc enum
19+
.rustified_enum("*")
20+
// force deriving the Hash trait on basic types (address, bytes32)
21+
.derive_hash(true)
22+
// force deriving the PratialEq trait on basic types (address, bytes32)
23+
.derive_partialeq(true)
24+
.allowlist_type("evmc_.*")
25+
.allowlist_function("evmc_.*")
26+
// TODO: consider removing this
27+
.size_t_is_usize(true)
28+
.generate()
29+
.expect("Unable to generate bindings");
30+
31+
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
32+
bindings
33+
.write_to_file(out_path.join("bindings.rs"))
34+
.expect("Couldn't write bindings!");
35+
}
36+
37+
fn gen_loader() {
38+
let build_dir = Config::new("../../../").build();
39+
let loader_path = Path::new(&build_dir).join("build/lib/loader");
40+
println!("cargo:rustc-link-search=native={}", loader_path.display());
41+
println!("cargo:rustc-link-lib=static=evmc-loader");
42+
}
43+
44+
fn main() {
45+
gen_loader();
46+
gen_bindings();
47+
}

bindings/rust/evmc-loader/loader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../include/evmc/loader.h
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// EVMC: Ethereum Client-VM Connector API.
2+
// Copyright 2019 The EVMC Authors.
3+
// Licensed under the Apache License, Version 2.0.
4+
5+
mod sys;
6+
7+
#[cfg(test)]
8+
mod tests {
9+
use std::ffi::CString;
10+
use std::os::raw::c_char;
11+
12+
use super::*;
13+
14+
#[test]
15+
fn load_fail() {
16+
let c_str = CString::new("test.so").unwrap();
17+
unsafe {
18+
let mut error_code = sys::evmc_loader_error_code::EVMC_LOADER_UNSPECIFIED_ERROR;
19+
let instance = sys::evmc_load_and_create(c_str.as_ptr() as *const c_char, &mut error_code);
20+
println!("{:?}", error_code);
21+
}
22+
}
23+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// EVMC: Ethereum Client-VM Connector API.
2+
// Copyright 2019 The EVMC Authors.
3+
// Licensed under the Apache License, Version 2.0.
4+
5+
#![allow(non_upper_case_globals)]
6+
#![allow(non_camel_case_types)]
7+
#![allow(non_snake_case)]
8+
9+
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
10+
11+
#[cfg(test)]
12+
mod tests {
13+
use std::ffi::CString;
14+
use std::os::raw::c_char;
15+
16+
use super::*;
17+
18+
#[test]
19+
fn load_fail() {
20+
let c_str = CString::new("test.so").unwrap();
21+
unsafe {
22+
let mut error_code = evmc_loader_error_code::EVMC_LOADER_UNSPECIFIED_ERROR;
23+
let instance = evmc_load_and_create(c_str.as_ptr() as *const c_char, &mut error_code);
24+
println!("{:?}", error_code);
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)